这两天被2个System.loadLibrary异常给整懵了,后来Google了一圈,总算找到解决办法,先说下现象:java
一样的so(存放路径都同样,如jniLibs/armeabi-v7a),不一样的Project,在Android 4.4(多是由于我手上的是32位,5.0以上为64位)及如下的手机上能运行,在Android 5.0及以上的手机上,其中一个app能够用,另一个app就会crash,logcat信息是:android
java.lang.UnsatisfiedLinkError和text relocations(多个so文件,错误不是同时发生,处理掉UnsatisfiedLinkError后出现了text relocations)。git
第一个异常在https://github.com/yixia/VitamioBundle/issues/305找到了解决方法:github
If you are using Android studio, just edit the gradle.properties
in the root folder and addandroid.useDeprecatedNdk=true
. Then edit the build.gradle
file in your app's folder, set abiFilters as below:shell
android { .... defaultConfig { .... ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "mips" } } }
另外,How Android Apps are Built and Run一文介绍了Android apk如何被编译并运行的,同时也介绍了Android 5.0(也就是API 21)以后,Android会启动Zygote来优化程序的加载。app
Does Android keep the .apk files? if so where? 提到了如何查看已安装的Android apk及其路径
gradle
adb shell pm list packages adb shell pm path com.king.candycrushsaga
Android 6.0下报错: UnsatisfiedLinkError: dlopen failed ... text relocations 一文提到:优化
在Android 6.0以前, text reloactions问题, 会在编译的过程当中, 做为warning报出来,在Android 6.0中, 原来的warning被升级为error了. 所以, 一样的库文件, 在Android 6.0前的环境运行, 不报错, 6.0下就会crash掉.ui
libavcodec.so: has text relocations 中提到了一个解决方法,就是将build.gradle中targetSdkVersion由23(可能更大)改成22。spa