javascriptandroidreact-nativecode-pushreact-native-code-push

Codepush crashes on android when updateDialog is set to true


I have used the documentation at https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-android.md#plugin-installation-and-configuration-for-react-native-060-version-and-above-android to install codepush on android.

For some reason when updateDialog: true in the codepush config the android app crashed with the following error.

should be called from the main thread, not thread[mqt_native_modules,5,main]

enter image description here

See code implementation below.

const CPOptions = { updateDialog: true, installMode: CodePush.InstallMode.ON_NEXT_RESTART,};
AppRegistry.registerComponent('celo', () => CodePush(CPOptions)(App));

"react-native": "0.66.4"
"react-native-code-push": "^7.0.4",


Solution

  • I was able to solve the answer myself. It became clear the error wasn't actually coming from codepush but rather the leakcanary debug implementation that was installed.

    It was version 2.7 which had this known issue:

    Stop throwing when not on main thread. While Curtains APIs should be used from the main thread, there are a number edge cases as well as bugs in consuming SDKs / apps and the Android Framework SDKs that can trigger calls from the wrong thread, and in many cases there isn't much developers can do, so Curtains is relaxing the constraint and doing a best effort approach.

    The issue was solved by changing the leakcanary version to 2.8.1.

    dependencies {
      // debugImplementation because LeakCanary should only run in debug builds.
      debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
    }