问题
I trying to build android application with some precompiled native libraries: liba.so and libb.so.1.2.3
Libraries are placed into jniLibs subdirectory. After building APK file, only liba.so included into it, but not libb.so.1.2.3.
Result is predictable. Application crashes at start.
What to do with build scripts to include all files from jniLibs into APK?
回答1:
Unfortunately I don't develop for Android anymore, so I can't test this, but I know Gradle and this might work for you. Looking at the Android DSL docs, you might be able to change the filtering on the jniLibs
folder:
android {
sourceSets {
main {
jniLibs.filter.include("**/*")
}
}
}
Let me know if this works!
回答2:
Due to the native library regex ^.+\\.so$
being used in the Android Gradle plugin, it is impossible to include anything other than .so
files using the jniLibs
folder. And even if you were to somehow add the library to the APK, the dynamic loader on Android is very limited and will most likely not be able to load them.
Your best bet is to remove the version altogether by renaming the library and changing its internal soname
before linking against it.
回答3:
Just add the jniLibs folder in app/src/main and it will include the .so file in the apk.
/app/src/main/armeabi/*.so files
来源:https://stackoverflow.com/questions/42813480/how-to-include-versioned-so-file-into-apk-using-gradle