Android 加载jni报错java.lang.UnsatisfiedLinkError: dlopen failed: library "libandroid_runtime.so" not

在Android 7.0以后,系统加了限制,访问私有so库有了限制,报错为下面的:

 PID: 3918
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libandroid_runtime.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
        at java.lang.System.loadLibrary(System.java:1657)
        at java.lang.Class.newInstance(Native Method)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:3348)
        at android.app.ActivityThread.-wrap4(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1701)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)

解决方案如下(目前只在MTK):

找到当前文件,\frameworks\base\core\java\android\app\LoadedApk.java

添加以下判断

private void createOrUpdateClassLoaderLocked(List addedPaths){
    ..............\\省略部分代码
    if (mApplicationInfo.getCodePath() != null
                && mApplicationInfo.getCodePath().startsWith("/vendor/")
                && !mApplicationInfo.getCodePath().startsWith("/vendor/operator/app/")
                && treatVendorApkAsUnbundled) {
            isBundledApp = false;
        }
    //需要添加的部分代码
    if("包名".equals(mApplicationInfo.packageName)){
            isBundledApp = true;
}

        makePaths(mActivityThread, isBundledApp, mApplicationInfo, zipPaths, libPaths);



}

看着是这一个判断就解决了问题,但是花了很长时间。。。。。。。。。

记录一下;

 

 

 

今夕是何夕,晚风过花庭~~~~~~~~~

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Android开发)