bugsnag / bugsnag-react-native

Error monitoring and reporting tool for native exceptions and JS errors in React Native apps
https://docs.bugsnag.com/platforms/react-native
MIT License
369 stars 121 forks source link

App crash during launch java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader #471

Closed SudoPlz closed 4 years ago

SudoPlz commented 4 years ago

Description

Our app crashes during app launch

Issue

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.example.app.android-3vNKvOYNFBjegL3oUY_FYw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.app.android-3vNKvOYNFBjegL3oUY_FYw==/lib/arm64, /system/lib64, /vendor/lib64]]] couldn't find "libbugsnag-ndk.so"
     FATAL EXCEPTION: main
Process: com.example.app.android, PID: 10716
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.example.app.android-3vNKvOYNFBjegL3oUY_FYw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.app.android-3vNKvOYNFBjegL3oUY_FYw==/lib/arm64, /system/lib64, /vendor/lib64]]] couldn't find "libbugsnag-ndk.so"
  at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
  at java.lang.System.loadLibrary(System.java:1657)
  at com.bugsnag.android.NdkPlugin.<clinit>(NdkPlugin.kt:9)
  at java.lang.Class.classForName(Native Method)
  at java.lang.Class.forName(Class.java:453)
  at java.lang.Class.forName(Class.java:378)
  at com.bugsnag.android.Client.<init>(Client.java:240)
  at com.bugsnag.android.Bugsnag.init(Bugsnag.java:77)
  at com.bugsnag.android.Bugsnag.init(Bugsnag.java:64)
  at com.bugsnag.android.Bugsnag.init(Bugsnag.java:37)
  at com.bugsnag.BugsnagReactNative.start(BugsnagReactNative.java:46)
  at com.example.app.android.MainApplication.onCreate(MainApplication.java:125)
  at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1118)
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5791)
  at android.app.ActivityThread.-wrap1(Unknown Source:0)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
  at android.os.Handler.dispatchMessage(Handler.java:105)
  at android.os.Looper.loop(Looper.java:164)
  at android.app.ActivityThread.main(ActivityThread.java:6541)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Environment

Library versions:

acuitymobileapp@4.9.6 /Users/SudoPlz/Development/Example/mobile
├── bugsnag-react-native@2.23.10
└── react-native-code-push@6.3.0

How we set up Bugsnag

MainApplication.java

@Override
    public void onCreate() {
        super.onCreate();
        BugsnagReactNative.start(this);

CrashReporter.js

import { Client, Configuration } from 'bugsnag-react-native';

initCrashReporter(key, codeBundleId) {
    if (this.instance === null) {
      if (key == null) {
        throw new Error(`Crash Reporter should be created with a
         key as the first param. i.e .create(key, reduxStore)`);
      }
      const bugsnagConfig = new Configuration(key);

      // enable session-tracking to provide crash rates between releases
      // https://docs.bugsnag.com/platforms/react-native/#session-tracking
      bugsnagConfig.autoCaptureSessions = true;

      bugsnagConfig.shouldNotify = () => !__DEV__;
      if (codeBundleId) {
        bugsnagConfig.appVersion = codeBundleId;
        bugsnagConfig.codeBundleId = codeBundleId;
      }
      bugsnagConfig.notifyReleaseStages = ['production', 'staging', 'testflight'];

      // create a breadcrumb for all console.logs
      bugsnagConfig.consoleBreadcrumbsEnabled = true;

      const that = this;
      bugsnagConfig.registerBeforeSendCallback(async (report) => {
        const metadata = report.metadata || {};

        if (that && that.mStore) {
          const state = JSON.parse(JSON.stringify(that.mStore.getState()));
          metadata.device = state.device;
          metadata.global = state.global;
          metadata.router = state.router;
          metadata.auth = state.auth;
        }

        if (report.errorClass === 'AcuityError') {
          // if an acuity error, change the severity
          report.severity = 'error';
        }

        const {
          curAppVersion,
          // baseV,
          // codepushV,
          pendingFailed,
          pendingVersion,
          isFirstRunOfRunningCodepushVersion,
        } = await OTAUpdateManager.getAppVersion(CONFIG.VERSION);

        if (metadata.app == null) {
          metadata.app = {};
        }
        // overwrite codeBundleId (version) make sure we use the current version
        if (curAppVersion && metadata.app.codeBundleId !== curAppVersion) {
          metadata.app.tmpVersion = metadata.app.codeBundleId;
          metadata.app.codeBundleId = curAppVersion;
        }

        if (metadata.device == null) {
          metadata.device = {};
        }
        metadata.device.pendingFailed = pendingFailed;
        metadata.device.pendingVersion = pendingVersion;
        metadata.device.isFirstRunOfRunningCodepushVersion = isFirstRunOfRunningCodepushVersion;

        report.metadata = metadata;

        return true; // return false to send no error
      });
      this.instance = new Client(bugsnagConfig);
    }
    return this.instance;
  }

</details>
steve-nester-uk commented 4 years ago

Hi @SudoPlz this seems like a possible duplicate of: https://github.com/bugsnag/bugsnag-react-native/issues/369#issuecomment-541596996 - can you try the solution mentioned in that thread?

e.g. These intermittent linkage errors can occur particularly on older versions of Android. Our suggested approach to avoid them would be to preload the SO file with ReLinker:

ReLinker.loadLibrary(this, "bugsnag-ndk");
Bugsnag.init(this);
SudoPlz commented 4 years ago

This happens on Android 10, is that considered an old version of Android?

steve-nester-uk commented 4 years ago

If you have a minimum SDK level of 23, we didn't think the ReLinker was going to do much to help in that case. However, there is anecdotal evidence that there are still issues with Android loading libraries even on SDK level 23 and above, where ReLinker has fixed this for them. I think it's worth giving ReLinker a go to see if it fixes the issue for you. Could you try this and let us know if it helps?

SudoPlz commented 4 years ago

Our APK was probably not the right one, we'll investigate and I'll re-open this if needed. Thanks