Realm-java: App Bundle: MissingLibraryException

Created on 28 May 2018  路  54Comments  路  Source: realm/realm-java

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

O-Community Pipeline-On-Hold T-Duplicate

Most helpful comment

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

Samsung SM-G965F
LGE Nexus 5X

relinker issue

All 54 comments

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.

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.

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

@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

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.

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

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.

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".

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.

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 when it will be released?

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

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?

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 : I believe that Realm Java 5.6.0 has been released with a fix for this ticket. Can you verify and close?

Yes, a fix has been released in 5.6.0

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

Samsung SM-G965F
LGE Nexus 5X

relinker issue

@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

@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.

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.

Note that with App Bundle, if users are sharing their APK manually there is a very real possibility that the user receiving the APK is not able to use it due to ABI incompatibility. That is probably hard to tell from Crashlytics though :/

@cmelchior we ordered one of the reported devices so we can test it locally, I will update you as soon as I receive them.
For your second question, I don't think that is the case as we are getting around 500 unique crash per week from this bug, we will know better when I test it locally.
Thanks for your help.

Yes, that probably means we can rule that out in that case.

ok, so I got my hands on 2 of the devices I mentioned, unfortunately, couldn't reproduce locally, tried both devices with the app installed from play store:/
I was checking fabrics reports, so decided to check Google Play Console for more info about the crashes (it has an option to check if the app was installed from play store), here is what I have for now.

1- I am getting 2 crash reports with the same bug "com.getkeepsafe.relinker.MissingLibraryException"
one coming from Samsung devices and one from Huawei (mostly)
screen shot 2018-11-12 at 11 20 19
screen shot 2018-11-12 at 11 20 26

2- both have the same crash report posted earlier by @MeinLieberScholli.

3- If I select the "installed from anywhere" option, the crash numbers triples ( @cmelchior you were right about this possibility)

Hope this info help fixing this bug.
The problem is we can't roll back to apk way of publishing after signing for the bundle, so we have nothing to do but to limit the bug cause with you guys.

Update from: https://issuetracker.google.com/issues/109448556

The source of the install can unfortunately be faked quite easily with "adb" and it looks like a bunch of users have learnt to do that (for reasons that I'm not entirely sure of yet). We haven't received any end-user report either that an install from Play was failing for them. A few other developers are facing the same issue and none of them have been able to reproduce the issue either.
All of this seems to confirm that the issue is indeed sideloading (with for some users faking the source of the install) so I will close this bug for now. If you have any end-user reporting that the install is failing when installing from Play store, feel free to re-open this bug providing the details. Note that we are also actively working on a solution to avoid the crashes on the users having installed only a subset of the required APKs. This should help remove those crashes from your reports altogether . Stay tuned.

Unfortunately, it seems at this point in time that the only way to avoid this issue is to avoid using AppBundle. Note that if users are indeed installing the wrong bundle, they will probably also experience other issues, like images having the wrong size or localization not working correctly.

Fresco had this issue before. But they fixed it 22 days ago.
When building via App Bundle, Fresco fails to find "libimagepipeline.so"
Maybe you can ask them about how to resolve this problem.

@cmelchior any update on this bug? We can use this feature for reducing the size of our build.

If that is the case, then the bug would be in Relinker

Any news? i'm thinking of using apk split for now

Note that users in India, Africa have much higher tendency to "share" apk files due to the cost and speed of bandwidth there.

We have zero reports of this issue with users that installed from offiial Play store via bundle split apks. I do not believe this can be solved by relinker or any so loader since if you manually install the wrong apk, you are missing .so files period. No ammount of wrangling will let your app open realm files.

Note that if you use realm with relinker 1.3.0+, there is absolutely no issue barring human error.

Note that users in India, Africa have much higher tendency to "share" apk files due to the cost and speed of bandwidth there.

We have zero reports of this issue with users that installed from offiial Play store via bundle split apks. I do not believe this can be solved by relinker or any so loader since if you manually install the wrong apk, you are missing .so files period. No ammount of wrangling will let your app open realm files.

Note that if you use realm with relinker 1.3.0+, there is absolutely no issue barring human error.

I've been working on an app with a 700k+ user base. We recently switched to bundle, and since then we had been receiving reports of this error during a rollout for an update. This means that the user had got the update from the play store and the APK was determined by Google.

We ignored the issue for a while until a user contacted us to complain. The user confirmed that they had installed the app through the play store and not from any other source (such as sharing APKs).

Reasons why Google would supply an incorrect APK are unconfirmed. Regardless, we resolved the issue by deploying an APK instead of a bundle

More details here: https://github.com/realm/realm-java/issues/6418

@Jonty800 You can track the google issue here https://issuetracker.google.com/issues/111233819

If the user installed custom roms that didn't support split apks, they need to wait for Google Play update which will auto detect this on their phone. You need to check to see if those users are using a) custom mods b) rooting and installed custom kernels.

Note that users in India, Africa have much higher tendency to "share" apk files due to the cost and speed of bandwidth there.
We have zero reports of this issue with users that installed from offiial Play store via bundle split apks. I do not believe this can be solved by relinker or any so loader since if you manually install the wrong apk, you are missing .so files period. No ammount of wrangling will let your app open realm files.
Note that if you use realm with relinker 1.3.0+, there is absolutely no issue barring human error.

I've been working on an app with a 700k+ user base. We recently switched to bundle, and since then we had been receiving reports of this error during a rollout for an update. This means that the user had got the update from the play store and the APK was determined by Google.

We ignored the issue for a while until a user contacted us to complain. The user confirmed that they had installed the app through the play store and not from any other source (such as sharing APKs).

Reasons why Google would supply an incorrect APK are unconfirmed. Regardless, we resolved the issue by deploying an APK instead of a bundle

More details here: #6418

have you tried deploying with apk-splits? Currently, I'm having the same choice split or bundle. 200k+ users. Considering dev's feedbacks i think that this issue still exists

It seems that Google thinks this issue is also related to https://issuetracker.google.com/issues/111233819 and they are working on a fix for that.

Unfortunately, this means that the advice in https://github.com/realm/realm-java/issues/5977#issuecomment-440257246 still stands and AppBundle should probably be avoided until Google can fix the underlying issue.

Any update or new information about this issues?
My Crashlytics received many errors:
Caused by com.getkeepsafe.relinker.MissingLibraryException lib/x86/librealm-jni.so com.getkeepsafe.relinker.ApkLibraryInstaller.installLibrary (ApkLibraryInstaller.java:85) com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal (ReLinkerInstance.java:180) com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary (ReLinkerInstance.java:136) com.getkeepsafe.relinker.ReLinker.loadLibrary (ReLinker.java:70) com.getkeepsafe.relinker.ReLinker.loadLibrary (ReLinker.java:57) io.realm.internal.RealmCore.loadLibrary (RealmCore.java:60) io.realm.Realm.init (Realm.java:200) com.demo.AppApplication.onCreate (AppApplication.java:59)

Have just update the classpath to classpath "io.realm:realm-gradle-plugin:5.11.0"

Does this issue still happen? Or can I update my app to use the app bundle?

+1

@lucasrafagnin unfortunately still does for a random small percentage of users

+1

+1

+1

You are most likely missing this check on YOUR side: https://developer.android.com/guide/app-bundle/sideload-check#application_class_check

You should make sure that the APK installed by the user has the library variant in Realm.

If you are using Android App Bundle, then you should have this check in your Application class.

This is not a problem with Realm.

@Zhuinden the MissingSplitsManager didn't work for me when I tried an APK with ndk { abiFilters "mips" } on a x86 emulator.

Instead I'm catching the RuntimeException and show a toast.

@jeff11 hmm I thought abiFilters requires you to specify what to keep (and Realm doesn't support MIPS), and not what to exclude.

Maybe try

abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'

My intention was to build an APK that is not compatible and therefore disableAppIfMissingRequiredSplits() is true and the app won't start.

But disableAppIfMissingRequiredSplits() was false.

But was it actually an Android App bundle, and not an APK?

An APK. When using the App Bundle, you would first have to extract an APK with a single ABI from it. That I didn't test.

missing required splits should only be relevant when Android App Bundle is used.

https://realm.io/docs/java/latest/#faq-librealm-jni

I tried this method and it crashed.
Is there no solution?

Device Information:
Device: Nexus 5X
Android Version: 6.0.1

Realm Version: 5.14.0

Logcat:
Caused by e.f.a.b: librealm-jni.so
       at com.getkeepsafe.relinker.ApkLibraryInstaller.installLibrary + 123(ApkLibraryInstaller.java:123)
       at com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal + 180(ReLinkerInstance.java:180)
       at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary + 136(ReLinkerInstance.java:136)
       at com.getkeepsafe.relinker.ReLinker.loadLibrary + 70(ReLinker.java:70)
       at com.getkeepsafe.relinker.ReLinker.loadLibrary + 57(ReLinker.java:57)
       at io.realm.internal.RealmCore.loadLibrary + 60(RealmCore.java:60)
       at io.realm.Realm.initializeRealm + 322(Realm.java:322)
       at io.realm.Realm.init + 265(Realm.java:265)

https://realm.io/docs/java/latest/#faq-librealm-jni

This happens every time I try to run my app on a device, without fail. I'm happy to provide more code if requested.

I've also tried this method and it made no difference, it's still crashing on Realm.init() in my Application Class.

All of this started after trying to update the application build.gradle with the latest version of Braintree 3D secure, it wouldn't build so I migrated the project to use androidx, now the project builds, and the app will install, it just falls down on Realm.init() constantly.

Device Information:
Device: Google Pixel 3 XL
Android Version: 9

Realm Version:

5.14.0

Logcat output

2019-09-10 11:47:13.735 29660-29660/com.companyname.androidapps.companyname E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.companyname.androidapps.skiddle, PID: 29660
    java.lang.RuntimeException: Unable to create application com.companyname.androidapps.companyname.ApplicationController: com.getkeepsafe.relinker.MissingLibraryException: librealm-jni.so
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5758)
        at android.app.ActivityThread.-wrap1(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6518)
        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:807)
     Caused by: com.getkeepsafe.relinker.MissingLibraryException: librealm-jni.so
        at com.getkeepsafe.relinker.ApkLibraryInstaller.installLibrary(ApkLibraryInstaller.java:123)
        at com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal(ReLinkerInstance.java:180)
        at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary(ReLinkerInstance.java:136)
        at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:70)
        at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:57)
        at io.realm.internal.RealmCore.loadLibrary(RealmCore.java:60)
        at io.realm.Realm.initializeRealm(Realm.java:322)
        at io.realm.Realm.init(Realm.java:265)
        at com.companyname.androidapps.companyname.ApplicationController.onCreate(ApplicationController.java:39)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1120)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5755)

Have just update the classpath to classpath "io.realm:realm-gradle-plugin:5.11.0"

the same me, i upgraded to 6.0.0. It works.

Gradle plugin: "io.realm:realm-gradle-plugin:6.0.0"
Android App Bundle
Android: 6.0.1
Device: Nexus 4

Fatal Exception: java.lang.RuntimeException: Unable to create application Application: com.getkeepsafe.relinker.MissingLibraryException: librealm-jni.so
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4714)
       at android.app.ActivityThread.-wrap1(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1408)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5421)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by com.getkeepsafe.relinker.MissingLibraryException: librealm-jni.so
       at com.getkeepsafe.relinker.ApkLibraryInstaller.installLibrary(ApkLibraryInstaller.java:123)
       at com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal(ReLinkerInstance.java:180)
       at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary(ReLinkerInstance.java:136)
       at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:70)
       at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:57)
       at io.realm.internal.RealmCore.loadLibrary(RealmCore.java:60)
       at io.realm.Realm.initializeRealm(Realm.java:322)
       at io.realm.Realm.init(Realm.java:265)
       at epayservice.kotlin.controller.RealmController.create(RealmController.java:23)
       at epayservice.kotlin.controller.App.onCreate(App.java:63)
       at epayservice.kotlin.controller.Application.onCreate(Application.java:21)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1022)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4711)
       at android.app.ActivityThread.-wrap1(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1408)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5421)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Was this page helpful?
0 / 5 - 0 ratings