4

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.

German
  • 10,263
  • 4
  • 40
  • 56
  • 1
    "If I install the same APK in a Nexus 4 with KitKat it just works" -- did you enable ART in Developer Options on the Nexus 4? If not, try that. ART is the most likely culprit, and you'll need to get an updated library: http://developer.android.com/guide/practices/verifying-apps-art.html – CommonsWare Nov 28 '14 at 17:04
  • You mean that enabling ART on a Nexus 4 with KitKat should trigger this problem if ART is the culprit? I could test that and see what happens... – German Nov 28 '14 at 17:15
  • 1
    "You mean that enabling ART on a Nexus 4 with KitKat should trigger this problem if ART is the culprit?" -- yes. Now, ART itself has probably changed some in between 4.4 and 5.0, so it's possible that the problem is tied specifically to 5.0's ART. But, if your app works on 4.4 with Dalvik and fails on 4.4 with ART, that's a pretty positive sign that the problem is tied to ART. – CommonsWare Nov 28 '14 at 17:16
  • Hi @CommonsWare. I tried your suggestion and, when switching a KitKat device to use ART from the dev settings, the library still works. So ART doesn't seem to be the culprit, it's rather Android 5.0 in some way. Since the lib works under ART it might be related to location of the library. Any additional suggestion? – German Nov 29 '14 at 22:18
  • "Any additional suggestion?" -- talk to the AllJoyn folks, I guess. There's only 44 questions tagged `alljoyn` here on SO, so hopefully there's some other AllJoyn support board that might be more useful. – CommonsWare Nov 29 '14 at 22:20
  • Yes, done! Thanks https://ask.allseenalliance.org/question/1619/unsatisfied-link-after-installing-android-5-update/ – German Nov 29 '14 at 22:23

1 Answers1

2

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/

German
  • 10,263
  • 4
  • 40
  • 56