如何使用 CMakeLists.txt 和 AndroidStudio 在 Android-NDK 项目中集成 libxml2 本机库? [英] How to Integrate libxml2 native lib in Android-NDK project using CMakeLists.txt and AndroidStudio?
问题描述
请帮助我使用 libxml2
native-lib - XML 解析库在 Android NDK 中使用 CMakeLists.txt
配置.
Please assist me for using libxml2
native-lib - XML parsing library in Android NDK using CMakeLists.txt
configuration.
我在这里找到了一个来源.但是不知道如何在 AndroidStudio 中使用 CMakeLists.txt
来集成它.在我的 android-NDK 项目中需要从这个存储库中包含什么才能使用 libxml2?
I found a source here. But do not know how to integrate this using CMakeLists.txt
in AndroidStudio. And what need to include from this repository in my android-NDK project to use libxml2?
推荐答案
经过一番搜索和努力,我找到了一些解决方案.所以我想按照以下步骤回答我自己的问题:
After some search and effort i found some solution. So i would like to answer my own question in following steps :
- 从您的机器中的 android/platform_external_libxml2 克隆源.
2.在项目中的适当位置添加所需的所有源文件和头文件.
2.Add the required all source as well as header files at appropriate place in your project.
3.借助 Android.bp 文件,我设法配置了我的应用程序/CMakeList.txt
3.With the help of Android.bp file, i managed to configure my app/CMakeList.txt
4.配置您的应用或库级别的 build.gradle 文件.
4.Configure your app or library level build.gradle file.
这是我的 CMakeLists.txt :
Here is My CMakeLists.txt :
cmake_minimum_required(VERSION 3.4.1)
set(LIBXML2_SOURCES
src/main/cpp/libxml2/src/SAX.c
src/main/cpp/libxml2/src/entities.c
src/main/cpp/libxml2/src/encoding.c
src/main/cpp/libxml2/src/error.c
src/main/cpp/libxml2/src/parserInternals.c
src/main/cpp/libxml2/src/parser.c
src/main/cpp/libxml2/src/tree.c
src/main/cpp/libxml2/src/hash.c
src/main/cpp/libxml2/src/list.c
src/main/cpp/libxml2/src/xmlIO.c
src/main/cpp/libxml2/src/xmlmemory.c
src/main/cpp/libxml2/src/uri.c
src/main/cpp/libxml2/src/valid.c
src/main/cpp/libxml2/src/xlink.c
src/main/cpp/libxml2/src/debugXML.c
src/main/cpp/libxml2/src/xpath.c
src/main/cpp/libxml2/src/xpointer.c
src/main/cpp/libxml2/src/xinclude.c
src/main/cpp/libxml2/src/DOCBparser.c
src/main/cpp/libxml2/src/catalog.c
src/main/cpp/libxml2/src/globals.c
src/main/cpp/libxml2/src/threads.c
src/main/cpp/libxml2/src/c14n.c
src/main/cpp/libxml2/src/xmlstring.c
src/main/cpp/libxml2/src/buf.c
src/main/cpp/libxml2/src/xmlregexp.c
src/main/cpp/libxml2/src/xmlschemas.c
src/main/cpp/libxml2/src/xmlschemastypes.c
src/main/cpp/libxml2/src/xmlunicode.c
src/main/cpp/libxml2/src/xmlreader.c
src/main/cpp/libxml2/src/relaxng.c
src/main/cpp/libxml2/src/dict.c
src/main/cpp/libxml2/src/SAX2.c
src/main/cpp/libxml2/src/xmlwriter.c
src/main/cpp/libxml2/src/legacy.c
src/main/cpp/libxml2/src/chvalid.c
src/main/cpp/libxml2/src/pattern.c
src/main/cpp/libxml2/src/xmlsave.c
src/main/cpp/libxml2/src/xmlmodule.c
src/main/cpp/libxml2/src/schematron.c
)
include_directories(src/main/cpp/libxml2/include)
include_directories(src/main/cpp/libxml2/src)
add_library( # Sets the name of the library.
myexampe-native
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/my-native.cpp )
add_library( # Sets the name of the library.
mylibxml2
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
${LIBXML2_SOURCES} )
target_link_libraries( # Specifies the target library.
myexampe-native
mylibxml2
)
这是我的 app/build.gradle 配置
And Here is my app/build.gradle configuration
android { .....
defaultConfig { .....
externalNativeBuild {
cmake {
cppFlags "-std=gnu++11"
arguments '-DANDROID_PLATFORM=android-21',
'-DANDROID_STL=c++_shared','-DANDROID_ARM_MODE=arm'
}
}
欢迎提出任何澄清意见.谢谢:-)
Comments are welcomed for any clarification. Thanks :-)
这篇关于如何使用 CMakeLists.txt 和 AndroidStudio 在 Android-NDK 项目中集成 libxml2 本机库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!