React-Native Android CodePush setup not downloading updates

3.2k Views Asked by At

I'm having trouble setting up CodePush into my React-Native Android application. On my dashboard, it's not showing that any apps have downloaded the update or installed it.

NOTE: iOS Codepushing works for this mobile app, just not Android.

I currently have my codePush options set up like this:

let codePushOptions = { 
   checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
   installMode: codePush.InstallMode.ON_NEXT_RESUME
};

Things I have done:

  1. In your android/settings.gradle file, make the following additions:

    include ':app', ':react-native-code-push' project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

  2. In your android/app/build.gradle file, add the :react-native-code-push project as a compile-time dependency:

    ... dependencies { ... compile project(':react-native-code-push') }

  3. In your android/app/build.gradle file, add the codepush.gradle file as an additional build task definition underneath react.gradle:

    ... apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/react-native-code-push/android/codepush.gradle" ...

  4. If you are integrating Code Push into React Native application please do the following steps:

Update the MainApplication.java file to use CodePush via the following changes:

...
// 1. Import the plugin class.
import com.microsoft.codepush.react.CodePush;

public class MainApplication extends Application implements ReactApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        ...
        // 2. Override the getJSBundleFile method in order to let
        // the CodePush runtime determine where to get the JS
        // bundle location from on each app start
        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }

        @Override
        protected List<ReactPackage> getPackages() {
            // 3. Instantiate an instance of the CodePush runtime and add it to the list of
            // existing packages, specifying the right deployment key. If you don't already
            // have it, you can run "code-push deployment ls <appName> -k" to retrieve your key.
            return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new CodePush("deployment-key-here", MainApplication.this, BuildConfig.DEBUG)
            );
        }
    };
}

Here is a picture of my MainApplication.java file

enter image description here


I know there is also this portion of the setup instructions that I don't know if I need to do or not. I tried to implement it but I get an error because this code is not like the sample documents at all that I have in my files.

I'm not quite sure what this is either:

public class MyReactNativeHost extends ReactNativeHost implements ReactInstanceHolder {
  // ... usual overrides
}

Edit 2 - index.js file

import { AppRegistry } from 'react-native';
import codePush from "react-native-code-push";

import App from './app/config/app';

let codePushOptions = { 
    checkFrequency: codePush.CheckFrequency.ON_APP_RESUME,
    installMode: codePush.InstallMode.ON_NEXT_RESUME
};

AppRegistry.registerComponent('AppName', () => codePush(codePushOptions)(App));
1

There are 1 best solutions below

0
On

I added the following to my android/app/build.gradle and it work as a workaround. I'm guessing this is likely an android gradle plugin issue. There seem to be a bunch of undocumented breaking changes in AGP 4.1+ that affect React Native.

under android { defaultConfig { I added

resValue 'string', "CODE_PUSH_APK_BUILD_TIME", String.format("\"%d\"", System.currentTimeMillis())