3

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));
halfer
  • 19,824
  • 17
  • 99
  • 186
bryan
  • 8,879
  • 18
  • 83
  • 166
  • Can you see the update in the dashboard? – Ashwin Mothilal Nov 26 '18 at 05:41
  • Can you please share your index.js – Anurag Chutani Nov 26 '18 at 12:10
  • @AshwinMothilal the update is on the dashboard with only the iOS devices listed as downloaded – bryan Nov 26 '18 at 16:32
  • @AnuragChutani I've updated my question to post the index.js at the bottom. I would like to reiterate that iOS Codepush's work. Just not android. – bryan Nov 26 '18 at 16:33
  • Try using install mode immediate like this on click a button codePush.sync({ updateDialog: true, installMode: codePush.InstallMode.IMMEDIATE }); – Ashwin Mothilal Nov 26 '18 at 17:10
  • @AshwinMothilal I can do this to test but I don't really want update dialogue's. Will report back if it pops up but I don't think this is the issue. – bryan Nov 26 '18 at 17:31
  • Everything seems fine, just check your deployment key once and logcat with Codepush as filter to see logs, also check if you are running application in debug mode. – Anurag Chutani Nov 27 '18 at 12:24
  • Anything worked? – Ashwin Mothilal Dec 02 '18 at 11:14
  • So I actually found out I was using an iOS project trying to CodePush to Android. What confused me is I saw an android device popup in the project so didn't know they were different. But after creating an Android specific Project to do CodePush, I didn't have any issues and it works fine. I appreciate your help. @AshwinMothilal – bryan Dec 03 '18 at 23:17

1 Answers1

4

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())

Patrick Muhire
  • 384
  • 3
  • 6