更新到Android 5.0后的java.lang.UnsatisfiedLinkError [英] java.lang.UnsatisfiedLinkError after updating to Android 5.0

查看:104
本文介绍了更新到Android 5.0后的java.lang.UnsatisfiedLinkError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用,该应用使用名为liballjoyn_java.so的本机库(在此处中提供) Android Core SDK).我使用Android Studio作为IDE,使用Maven作为构建/依赖系统(不是Gradle).借助Android KitKat,一切都像个魅力,这就是我将库添加到项目中的方式:

1)将库添加到我的本地Maven存储库

mvn install:install-file -Dfile=./alljoyn/liballjoyn_java.so -DgroupId=org.alljoyn -DartifactId=liballjoyn_java -Dversion=14.06.00 -Dscope=runtime -Dpackaging=so

2)在POM文件中定义了一个依赖项:

        <dependency>
            <groupId>org.alljoyn</groupId>
            <artifactId>liballjoyn_java</artifactId>
            <scope>runtime</scope>
            <type>so</type>
            <version>14.06.00</version>
        </dependency>

3)从我的代码中静态调用它:

static {
    try {
        System.loadLibrary("alljoyn_java");
        Log.d("AllJoynManager", "static - Loaded AllJoyn native library");
    } catch (Exception exception) {
        Log.d("AllJoynManager", "static - Error loading AllJoyn native library");
        exception.printStackTrace();
    }
}

这在我的Nexus 4手机中的KitKat上运行良好,但是现在我安装了官方的Android 5.0 OTA更新,并且在运行时出现以下错误:

11-28 17:57:39.988  30068-30068/com.avispalabs.kiihome E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.avispalabs.kiihome, PID: 30068
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.avispalabs.kiihome-2/base.apk"],nativeLibraryDirectories=[/data/app/com.avispalabs.kiihome-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "liballjoyn_java.so"
            at java.lang.Runtime.loadLibrary(Runtime.java:366)
            at java.lang.System.loadLibrary(System.java:989)
            at com.avispalabs.kiihome.helpers.network.alljoyn.AlljoynManager.<clinit>(AlljoynManager.java:38)
            at com.avispalabs.kiihome.ui.activities.MainActivity.<init>(MainActivity.java:38)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.Class.newInstance(Class.java:1572)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
11-28 17:57:55.432  30068-30068/com.avispalabs.kiihome I/Process﹕ Sending signal. PID: 30068 SIG: 9

我怀疑.so库的编译方式可能与新的Android 5.0 ART(?)不兼容.表示找不到该库的消息可能会引起误解(当库加载失败时也会看到该异常),但我不确定(另一种可能性是.so未被正确提取或放置).

该库已预编译,并被宣传为与JellyBean兼容.我认为以前的动态库将与新版本的Android兼容,否则很多应用程序将崩溃.如果我在使用KitKat的Nexus 4中安装了相同的APK,它就可以正常工作.

任何建议都将受到高度赞赏.

更新:我已经在基于KitKat的设备中测试了我的项目,并将运行时切换为ART而不是Dalvik,并且该项目运行正常.这个问题似乎与Android 5有关,而不是与ART本身有关.

解决方案

在这里回答我自己的问题.您可以按照以下说明通过将liballjoyn_java编译为PIE来解决此问题:

https://jira.allseenalliance.org/browse/ASACORE-1208

这是一个变通方法,直到AllJoyn伙计们发布新的Android版本为止.请随时注意获取更新的版本:

https://build .allseenalliance.org/ci/view/Core%20RB14.12%20SDK/job/branch-android-sdk/

I'm developing an Android app which uses a native library called liballjoyn_java.so (available here in the Android Core SDK). I'm using Android Studio as IDE and Maven as build/dependency system (not Gradle). With Android KitKat everything worked like a charm and this is how I added the library to my project:

1) Added the library to my local Maven repo

mvn install:install-file -Dfile=./alljoyn/liballjoyn_java.so -DgroupId=org.alljoyn -DartifactId=liballjoyn_java -Dversion=14.06.00 -Dscope=runtime -Dpackaging=so

2) Defined a dependency in the POM file:

        <dependency>
            <groupId>org.alljoyn</groupId>
            <artifactId>liballjoyn_java</artifactId>
            <scope>runtime</scope>
            <type>so</type>
            <version>14.06.00</version>
        </dependency>

3) Called it statically from my code:

static {
    try {
        System.loadLibrary("alljoyn_java");
        Log.d("AllJoynManager", "static - Loaded AllJoyn native library");
    } catch (Exception exception) {
        Log.d("AllJoynManager", "static - Error loading AllJoyn native library");
        exception.printStackTrace();
    }
}

This was working perfectly under KitKat in my Nexus 4 phone but now I installed the official Android 5.0 OTA update and I get the following error on runtime:

11-28 17:57:39.988  30068-30068/com.avispalabs.kiihome E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.avispalabs.kiihome, PID: 30068
    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.avispalabs.kiihome-2/base.apk"],nativeLibraryDirectories=[/data/app/com.avispalabs.kiihome-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "liballjoyn_java.so"
            at java.lang.Runtime.loadLibrary(Runtime.java:366)
            at java.lang.System.loadLibrary(System.java:989)
            at com.avispalabs.kiihome.helpers.network.alljoyn.AlljoynManager.<clinit>(AlljoynManager.java:38)
            at com.avispalabs.kiihome.ui.activities.MainActivity.<init>(MainActivity.java:38)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.Class.newInstance(Class.java:1572)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1065)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2199)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
11-28 17:57:55.432  30068-30068/com.avispalabs.kiihome I/Process﹕ Sending signal. PID: 30068 SIG: 9

I suspect the .so library might have been compiled in way which is somehow incompatible with the new Android 5.0 ART (?). The message that says it can't find the library is probably misleading (the exception is also seen when a library fails to load) but I'm not sure (another possibility is the .so is not correctly extracted or placed).

The library comes precompiled and is advertised to be compatible with JellyBean. I thought previous dynamic libraries would be compatible with new versions of Android, otherwise a lot of apps would break. If I install the same APK in a Nexus 4 with KitKat it just works.

Any advice is highly appreciated.

UPDATE: I have tested my project in a KitKat based device and switched the runtime to ART rather than Dalvik, and the project works fine. This problem seems to be tied to Android 5 rather than ART itself.

解决方案

Answering my own question here. You can solve it by compiling liballjoyn_java as PIE as explained here:

https://jira.allseenalliance.org/browse/ASACORE-1208

This is a workaround until the AllJoyn guys publish a new Android build. Keep an eye here to get the updated release:

https://build.allseenalliance.org/ci/view/Core%20RB14.12%20SDK/job/branch-android-sdk/

这篇关于更新到Android 5.0后的java.lang.UnsatisfiedLinkError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆