本文共 958 字,大约阅读时间需要 3 分钟。
一般我们开发的android sdk(arr)使用了jni后,aar中只会包含动态库的(so文件),所以以前一直没有注意与处理过android平台上的静态库的打包。今天尝试了一下,有遇到了一直打不出.a文件和aar构建出来后没有.a文件的问题,后来通过搜索找到了不明原因的解决方案。后续需要弄清楚原因和撑握相关的知识点。
1、CMakeLists.txt文件,把库的打包类型改为STATIC
2、需要在build.gradle 文件的nativeBundleExport配置上加上bundleStatic 3、需要在build.gradle 文件的externalNativeBuild配置上加上targets//CMakeLists.txt文件add_library( # Sets the name of the library. 库名 # Sets the library as a shared library. STATIC # Provides a relative path to your source file(s). src/main/jni/xxx.cp)// build.gradle文件 nativeBundleExport { bundleStatic = true //加上了可以在aar才加包含打出来的.a文件 } externalNativeBuild { cmake { arguments '-DANDROID_TOOLCHAIN=clang', "-DANDROID_STL=c++_static" cppFlags "-std=c++11 -frtti -fexceptions" abiFilters 'arm64-v8a','armeabi-v7a','x86','x86_64' targets '库名' //加上了可以编译出.a文件 }
转载地址:http://pkmbi.baihongyu.com/