App Bundle, split APKs and LinkageError

Troubleshoot or avoid crashes when using ObjectBox db and Android App Bundle or due to buggy devices. Google-certified devices prevent this crash.

Your app might observe crashes due to UnsatisfiedLinkError or (since ObjectBox 2.3.4) LinkageError on some devices. This has mainly two reasons:

  • If your app uses the App Bundlearrow-up-right format, the legacy split APK feature or Multidexarrow-up-right the native library can't be found.

  • Or if your app's minimum SDK level is below API 23 (Marshmallow), there are known bugs in Android's native library loading code.

Let us know if the below suggestions do not resolve your crashes in GitHub issue 605arrow-up-right.

App Bundle and split APKs

When using an App Bundle or split APKs Google Play only delivers the split APKs required for each user's device configuration, including its architecture (ABI). If users bypass Google Play to install your app ("sideloading") they might not install all of the required split APKs. If the split APK containing the ObjectBox native library required for the device ABI is missing, your app will crash with LinkageError when building BoxStore.

Using the Play Core library to check for missing splits

circle-info

Update August 2020: Google-certified devices (those running Google Play Services) or those running Android 10 (API level 29) or higher prevent users from sideloading split APKs, preventing this crash. Adding the below check is no longer necessary for these devices.

Add the Play Core libraryarrow-up-right to the dependencies block:

implementation 'com.google.android.play:core:1.7.3'

In the Application class add the missing split APKs check before calling super.onCreate():

public class App extends Application {

    @Override
    public void onCreate() {
        if (MissingSplitsManagerFactory.create(this).disableAppIfMissingRequiredSplits()) {
            return; // Skip app initialization.
        }
        super.onCreate();
        // ...
    }
}

If a broken installation is detected, users will see a message and Reinstall button asking them to re-install the app from Google Play.

See how we updated our example apparrow-up-right to use the Play Core library detection.

If the Play Core library should not be used, there are two alternatives:

Alternative: Catch exception and inform users

You can guard the MyObjectBox build call and for example display an activity with an info message (e.g. direct users to reinstall the app from Google Play, send you an error report, ...):

As an example see how we added this to our Android app examplearrow-up-right.

Alternative: turn off splitting by ABI

The simplest solution is to always include native libraries for all supported ABIs. However, this will increase the download size of your app for all users.

Source: Android Developersarrow-up-right

Buggy devices (API 22 or lower)

On some devices and if your minimum SDK is below API 23 (Android 6.0 Marshmallow), loading the native library may fail with LinkageError due to known bugs in Android's native library loading code. To counter this ObjectBox includes support for the ReLinkerarrow-up-right tool which will try to extract the native library manually if loading it normally fails.

To enable this, just add ReLinker to your dependencies:

circle-exclamation

For ProGuard add this line:

For Multidex add a multiDexKeepProguard file to your build file:

And in the multidex-config.pro file add the same rule as above:

circle-info

Multidex supports two file formats to keep filesarrow-up-right. We are using the ProGuard format (multiDexKeepProguard property). You can also use the multiDexKeepFile property, but make sure to adapt the rule above to that format.

Enable ReLinker debug log

To enable debug logs for ReLinker you can pass a custom ReLinkerInstance when building BoxStore:

Last updated

Was this helpful?