解决方案1
在“src/main/”内创建文件夹“jniLibs”
将所有 .so 库放入“src/main/jniLibs”文件夹中
文件夹结构如下:
|--app:
|--|--src:
|--|--|--main
|--|--|--|--jniLibs
|--|--|--|--|--armeabi
|--|--|--|--|--|--.so Files
您能确认一下您有这个层次结构吗?
不需要额外的代码,只需同步您的项目并运行您的应用程序。
参考https://github.com/commonsguy/sqlcipher-gradle/tree/master/src/main https://github.com/commonsguy/sqlcipher-gradle/tree/master/src/main
解决方案2
将两个代码片段添加到模块 gradle.build 文件中作为依赖项:
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
如何创建这个自定义 jar:
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
tasks.withType(Compile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
source https://stackoverflow.com/questions/16683775/include-so-library-in-apk-in-android-studio?rq=1