1

I have a react-native app with 3 android product flavours namely dev, prod and staging. The problem is that when I try to distribute the app via Crashlytics, basically when I build a release signed apk file, CodePush stops working. I am using redux-saga in my app and I am using the react-native-redux-saga package to check for CodePush updates. All works fine on iOS, but not for Android as I mentioned above.

In my Android project, I have a strings.xml file for each of the product flavours that look like this:

<resources>
    <string moduleConfig="true" name="reactNativeCodePush_androidDeploymentKey">_My_CodePush_Key</string>
    <string name="app_name">MyApp Staging</string> 
</resources>

Product flavours setup looks like this:

productFlavors {

        prod {
            versionCode 6
            versionName "1.1"
        }

        staging {
            minSdkVersion 16
            applicationId 'com.myapp.staging'
            versionCode 6
            versionName "1.1"
        }

        dev {
            minSdkVersion 16
            applicationId 'com.myapp.dev'
            versionCode 6
            versionName "1.1"
        }
    }

And my MainApplication.java file looks like this:

public class MainApplication extends Application implements ReactApplication {

  private final MyReactNativeInstanceHolder mReactNativeHost = new MyReactNativeInstanceHolder(this) {

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

    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            // ...Some packages
            new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG),
            // ...More packages
      );
    }
  };

  @Override
  public void onCreate() {
    CodePush.setReactInstanceHolder(getReactNativeHost());
    super.onCreate();
    Fabric.with(this, new Crashlytics());
  }

  @Override
  public MyReactNativeInstanceHolder getReactNativeHost() {
      return mReactNativeHost;
  }
}

I tried to remove the BuildConfig.DEBUG parameter from the CodePush package, but the problem doesn't go away.

The MyReactNativeInstanceHolder.java file looks like this:

public class MyReactNativeInstanceHolder extends ReactNativeHost implements ReactInstanceHolder {
    protected MyReactNativeInstanceHolder(Application application) {
        super(application);
    }

    @Override
    public boolean getUseDeveloperSupport() {
        return false;
    }

    @Override
    protected List<ReactPackage> getPackages() {
        return null;
    }
}

I have also checked the keys for the CodePush app and there isn't any issue there. This issue is really strange and I would really like some help. Is there anything that I am missing?

Rameez Hussain
  • 6,414
  • 10
  • 56
  • 85

0 Answers0