React-native-code-push: Android app crash when use code push

Created on 23 Oct 2019  路  6Comments  路  Source: microsoft/react-native-code-push

Thanks so much for filing an issue or feature request! Please fill out the following (wherever relevant):

Steps to Reproduce

  1. install react-native-code-push
  2. Use autolinking
  3. Add return CodePush.getJSBundleFile(); to getJSMainModuleName()
  4. Run app

I also tried add this but still same problem

@Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
            packages.add(new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG));
          return packages;
        }

Expected Behavior

What you expected to happen?
CodePush can update my code

Actual Behavior

What actually happens?
Get Error A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sting.movie/com.safety.MainActivity}: com.microsoft.codepush.react.CodePushNotInitializedException: A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3268)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3407)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7343)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933)
     Caused by: com.microsoft.codepush.react.CodePushNotInitializedException: A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?
        at com.microsoft.codepush.react.CodePush.getJSBundleFile(CodePush.java:206)
        at com.microsoft.codepush.react.CodePush.getJSBundleFile(CodePush.java:201)
        at com.safety.MainApplication$1.getJSMainModuleName(MainApplication.java:35)
        at com.facebook.react.ReactNativeHost.createReactInstanceManager(ReactNativeHost.java:68)
        at com.facebook.react.ReactNativeHost.getReactInstanceManager(ReactNativeHost.java:38)
        at com.facebook.react.ReactDelegate.loadApp(ReactDelegate.java:103)
        at com.facebook.react.ReactActivityDelegate.loadApp(ReactActivityDelegate.java:88)
        at com.facebook.react.ReactActivityDelegate.onCreate(ReactActivityDelegate.java:83)
        at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:44)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3243)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3407)聽
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)聽
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)聽
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)聽
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)聽
        at android.os.Handler.dispatchMessage(Handler.java:107)聽
        at android.os.Looper.loop(Looper.java:214)聽
        at android.app.ActivityThread.main(ActivityThread.java:7343)聽
        at java.lang.reflect.Method.invoke(Native Method)聽
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)聽
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933)聽

Reproducible Demo

Environment

  • react-native-code-push version: 5.7.0
  • react-native version: 0.61.2
  • iOS/Android/Windows version: Android 10, API 29
  • Does this reproduce on a debug build or release build? both
  • Does this reproduce on a simulator, or only on a physical device? both

Most helpful comment

this line

packages.add(new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG));

does the trick for me

All 6 comments

this line

packages.add(new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG));

does the trick for me

@Stjng were you able to find a solution for this?

@bhavukjain1 Yes, its because i was confuse about getJSMainModuleName and getJSBundleFile in MainApplication.java ( also not read the docs carefully ). Just add both of this function and it should work.

@Override
protected String getJSMainModuleName() {
    return "index";
}

@Override
protected String getJSBundleFile() { return CodePush.getJSBundleFile();
}

@Stjng, did the same thing... guess the docs could have a small note on this

import com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
import com.microsoft.appcenter.reactnative.analytics.AppCenterReactNativeAnalyticsPackage;
import com.microsoft.appcenter.reactnative.appcenter.AppCenterReactNativePackage;
import com.microsoft.codepush.react.CodePush;
@Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          packages.add(new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)));
          packages.add(new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)));
          packages.add(new AppCenterReactNativePackage(MainApplication.this));
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }

        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
}

error:
com.microsoft.codepush.react.CodePushNotInitializedException: A CodePush instance has not been created yet. Have you added it to your app's list of ReactPackages?

EDIT:
THIS LINE SAVE MY LIFE
packages.add(new CodePush(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG));

this line

packages.add(new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG));

does the trick for me

thank you!!! you saved my day!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cgerikj picture cgerikj  路  3Comments

jaysig picture jaysig  路  3Comments

fanzhiri picture fanzhiri  路  3Comments

sergey-akhalkov picture sergey-akhalkov  路  4Comments

chrisjrex picture chrisjrex  路  4Comments