java.lang.UnsatisfiedLinkError和text relocations錯誤

這兩天被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

UnsatisfiedLinkError

第一個異常在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

text relocations

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

相關文章
相關標籤/搜索