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.
Last updated
Was this helpful?
Troubleshoot or avoid crashes when using ObjectBox db and Android App Bundle or due to buggy devices. Google-certified devices prevent this crash.
Last updated
Was this helpful?
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 format, the legacy split APK feature or 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 .
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.
Add the to the dependencies block:
In the Application
class add the missing split APKs check before calling 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.
If the Play Core library should not be used, there are two alternatives:
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, ...):
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.
To enable this, just add ReLinker to your dependencies:
ObjectBox is calling ReLinker via reflection. If you are using ProGuard or Multidex, make sure to add keep rules so that ReLinker code is not stripped from the final app or is not in the primary dex file.
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:
To enable debug logs for ReLinker you can pass a custom ReLinkerInstance
when building BoxStore
:
See to use the Play Core library detection.
As an example see .
Source:
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 tool which will try to extract the native library manually if loading it normally fails.
. 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.