realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

App Bundle: MissingLibraryException

Open Jeff11 opened this issue 8 years ago • 54 comments

Goal

To find a solution for ABI related problems

Expected Results

To run all split versions of app successfully

Actual Results

Fatal Exception: java.lang.RuntimeException: Unable to create application my.app.AppMain: com.b.a.b: lib/armeabi/librealm-jni.so
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4715)
       at android.app.ActivityThread.-wrap1(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
Caused by com.b.a.b: lib/armeabi/librealm-jni.so
       at com.b.a.a.a(ApkLibraryInstaller.java:85)
       at com.b.a.d.a(ReLinkerInstance.java:180)
       at com.b.a.d.a(ReLinkerInstance.java:136)
       at com.b.a.c.a(ReLinker.java:1070)
       at io.realm.internal.m.a(RealmCore.java:60)
       at io.realm.v.a(Realm.java:258)
       at my.app.AppMain.onCreate(AppMain.java:256)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4712)
       at android.app.ActivityThread.-wrap1(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)

Version of Realm and tooling

Realm version(s): 5.1.0 Android Studio version: 3.2 canary 15

Which Android version and device: Nexus 5X tries to load x86, but most reported devices try armeabi Many different devices are affected App is not using other so files than Realm.

From the Google Play dashboard I can see that no armeabi version is generated, only the 5 that Realm uses.

Edit: removed the x86 from the stacktrace, that was confusing

Jeff11 avatar May 28 '18 10:05 Jeff11

Hi @Jeff11 Thanks for reporting this. I haven't had a chance to use App Bundles yet, and since the feature was just released I will need to play around with it to determine what might be causing this.

This message looks rather strange though: lib/armeabi or x86/librealm-jni.so, since a phone only have one architecture.

cmelchior avatar May 29 '18 14:05 cmelchior

That was confusing from my side, sorry. Of course, either x86 or armeabi was loaded per device, not both.

This crash happens on <0.2% of devices.

Jeff11 avatar May 29 '18 14:05 Jeff11

I have a similar issue using Android App Bundle.

Caused by com.getkeepsafe.relinker.MissingLibraryException
lib/x86/librealm-jni.so
arrow_right
com.getkeepsafe.relinker.ApkLibraryInstaller.a (Unknown Source)
com.getkeepsafe.relinker.ReLinkerInstance.b (Unknown Source)
com.getkeepsafe.relinker.ReLinkerInstance.a (Unknown Source)
com.getkeepsafe.relinker.ReLinker.a (Unknown Source)
io.realm.internal.RealmCore.a (Unknown Source)
io.realm.Realm.a (Unknown Source)

and

Caused by com.getkeepsafe.relinker.MissingLibraryException
lib/armeabi/librealm-jni.so
com.getkeepsafe.relinker.ApkLibraryInstaller.a (Unknown Source)
com.getkeepsafe.relinker.ReLinkerInstance.b (Unknown Source)
com.getkeepsafe.relinker.ReLinkerInstance.a (Unknown Source)
com.getkeepsafe.relinker.ReLinker.a (Unknown Source)
io.realm.internal.RealmCore.a (Unknown Source)
io.realm.Realm.a (Unknown Source)

Filed an issue on Google side to check if it's a fault on the bundle system itself: https://issuetracker.google.com/issues/109448556

chriswiesner avatar Jun 04 '18 08:06 chriswiesner

@Jeff11 Are you using another library which uses armeabi, my guess is the bundle created an APK based on this configuration (CPU = armeabi) but as you know Realm stopped supporting armeabi since 2.x (Following Google deprecation on this ABI).

You can now double check the generated APK locally using bundletool as described by the official doc & see if you can reproduce the issue before pushing to Play

nhachicha avatar Jun 09 '18 15:06 nhachicha

I have no other libraries that use armeabi. Realm is the only native library in use.

After uploading the AAB to the play store, I am able to download the APKs by device and they worked fine.

Jeff11 avatar Jun 11 '18 08:06 Jeff11

I'm experiencing the same issue with Android App Bundle:

Caused by com.getkeepsafe.relinker.MissingLibraryException: lib/armeabi/librealm-jni.so
       at com.getkeepsafe.relinker.a.a(ApkLibraryInstaller.java:85)
       at com.getkeepsafe.relinker.c.c(ReLinkerInstance.java:180)
       at com.getkeepsafe.relinker.c.a(ReLinkerInstance.java:136)
       at com.getkeepsafe.relinker.b.a(ReLinker.java:70)
       at com.getkeepsafe.relinker.b.a(ReLinker.java:57)
       at io.realm.internal.l.a(RealmCore.java:60)
       at io.realm.v.a(Realm.java:258)

Strangely only on devices which use MediaTek chipsets like:

Quantum MUV PRO - MediaTek MT6753 Lenovo PHAB 2 Plus - MediaTek MT8783 Xperia XA - MediaTek MT6755 Helio P10 Sony Xperia XA1 Ultra Dual - MediaTek MT6757 Helio P20

bildschirmfoto 2018-06-14 um 22 50 51

sdeff avatar Jun 14 '18 20:06 sdeff

From the comments in https://issuetracker.google.com/issues/109448556 It seems that this is related to side-loaded APK's. Before, if you didn't manually use ABI split, the APK would contain all the code needed for all CPU architectures. With App Bundle a split is happening automatically and if people are distributing the APK to devices with a different architecture, the app will crash with the above message.

I have been told this is behaviour is quite common in areas where data traffic might be expensive.

Unfortunately, there isn't much we can do about this as it is a "user error". The best we can do is probably having a better check if we cannot match the CPU architecture with the native code found. If that happens we can throw a better exception. App developers can then use this exception to show a dialogue to the user saying the app doesn't work on their device.

I'll keep this issue open as it hasn't been closed on Googles side yet, so we cannot yet rule out a bug on their end.

cmelchior avatar Jun 28 '18 13:06 cmelchior

It looks like the our ReLinker has problems loading native libs from AppBundles as we only look in the base APK for the native library. https://github.com/KeepSafe/ReLinker/issues/44 Sums this up.

We would be very happy about a PR on this, as we don't use AppBundles our selfs. The following comment from a google issue sums it up quite well:

ReLinker loads the native library directly from the APK file, without using the OS' System.load() or System.loadLibrary() methods. The issue is that it searches for the native libraries in the base APK, whereas with the App Bundle, the native libraries are in config splits (i.e. ReLinker searches in base.apk whereas the native libraries are actually in base-x86.apk, base-armeabi.apk, etc.).

Source: https://github.com/KeepSafe/ReLinker/blob/master/relinker/src/main/java/com/getkeepsafe/relinker/ApkLibraryInstaller.java#L55 Instead of searching in "sourceDir", ReLinker should be searching over the different directories under "splitSourceDirs".

philippb avatar Jul 09 '18 18:07 philippb

A PR is currently in review that should fix this: https://github.com/KeepSafe/ReLinker/pull/46 Once this PR has been approved and merged we will upgrade the Relinker version used.

cmelchior avatar Jul 16 '18 07:07 cmelchior

Support for App Bundles has been merged to Relinker master branch. It seems that only https://github.com/KeepSafe/ReLinker/pull/51 needs to be merged before a release is made.

cmelchior avatar Aug 31 '18 13:08 cmelchior

@cmelchior when it will be released?

tamtom avatar Sep 03 '18 07:09 tamtom

@cmelchior It looks like ReLinker released 1.3.0 with the fix, we should test it & release a minor

nhachicha avatar Sep 12 '18 11:09 nhachicha

Waiting for a 5.5.1 version really much, it's the only obstacle for us to make an APK almost three times smaller. Are there any estimates for this release?

amatsegor avatar Sep 20 '18 14:09 amatsegor

Yes, the plan is to release it next week. Our SNAPSHOT uploads have been broken, but should work again, so you can also test it by using our 5.6.0-SNAPSHOT release: https://github.com/realm/realm-java#using-snapshots

cmelchior avatar Sep 21 '18 10:09 cmelchior

@cmelchior : I believe that Realm Java 5.6.0 has been released with a fix for this ticket. Can you verify and close?

roberhofer avatar Sep 26 '18 23:09 roberhofer

Yes, a fix has been released in 5.6.0

cmelchior avatar Sep 27 '18 04:09 cmelchior

Unfortunately, I still get the same issue with Realm version 5.7.0.

Samsung SM-G965F LGE Nexus 5X

relinker issue

MeinLieberScholli avatar Oct 19 '18 14:10 MeinLieberScholli

@MeinLieberScholli , Do you have any idea if Is this problem has been solved in 5.8.0? We are getting such crashes from those models on 5.7.1: ANE-LX1,CLT-L09,CLT-L29,SM-N910C,SM-N920C,SM-N960F

engi2nee avatar Nov 07 '18 14:11 engi2nee

@MeinLieberScholli , Do you have any idea if Is this problem has been solved in 5.8.0? We are getting such crashes from those models on 5.7.1: ANE-LX1,CLT-L09,CLT-L29,SM-N910C,SM-N920C,SM-N960F

i will update in a few days and report if it occurs again.

MeinLieberScholli avatar Nov 08 '18 07:11 MeinLieberScholli

I'm reopening this issue as we are seeing some reports of there perhaps still being problems with App Bundle.

Note, we are using Relinker to load our .so files so if there still are problems it is most likely in either Relinker (https://github.com/KeepSafe/ReLinker) or the App Bundle feature itself.

That said, we are still interested in finding and fixing bugs in any of these components.

@MeinLieberScholli @engi2nee Is it something you can reproduce locally?

Note that upgrading to 5.8.0 should not fix it as we haven't touched this part of the code in that release.

cmelchior avatar Nov 08 '18 08:11 cmelchior