经过一番搜索和努力,我找到了解决方案.所以我想按照以下步骤回答我自己的问题:
2.在项目中的适当位置添加所需的所有源代码和头文件.
3.借助Android.bp文件,我设法配置了我的app / CMakeList.txt
4.配置您的应用程序或库级别的build.gradle文件.
这是我的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配置
android { .....
defaultConfig { .....
externalNativeBuild {
cmake {
cppFlags "-std=gnu++11"
arguments '-DANDROID_PLATFORM=android-21',
'-DANDROID_STL=c++_shared','-DANDROID_ARM_MODE=arm'
}
}
欢迎对任何澄清发表评论.
谢谢 :-)