如何使用CMakeLists.txt和AndroidStudio将libxml2本机lib集成到Android-NDK项目中? [英] How to Integrate libxml2 native lib in Android-NDK project using CMakeLists.txt and AndroidStudio?
问题描述
请协助我使用CMakeLists.txt
配置在 Android NDK 中使用libxml2
本机库- XML 解析库.
Please assist me for using libxml2
native-lib - XML parsing library in Android NDK using CMakeLists.txt
configuration.
我在此处找到了来源.但是不知道如何使用 AndroidStudio 中的CMakeLists.txt
进行集成.为了使用libxml2,需要从我的android-NDK项目的此存储库中包含什么?
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 克隆源.
- Clone the source from android/platform_external_libxml2 in your machine.
2.在项目的适当位置添加所需的所有源代码和头文件.
2.Add the required all source as well as header files at appropriate place in your project.
3.借助于Android.bp文件,我设法配置了我的app/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将libxml2本机lib集成到Android-NDK项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!