Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Android playstore in-app update with react-native

immediate flow of play store in-app updates

How can I implement play store in-app update with my react-native app, which is already live on play store?

I have already implemented code push and also internal version check via API calls to force the user to update the app.

With Codepush: code push only works for javascript changes. However, there are many scenarios where we will need the whole app to be updated when there is a native code change.

With API check: We need to watch when the update is getting live, and update the version number kept in the backend to force the user to update the app.

Though both these solutions are kind of patchy, I would like to implement the elegant approach of the play-store in-app update, but couldn't find a clue on how to get it done.

like image 899
Maneesh MK Avatar asked Jan 21 '20 03:01

Maneesh MK


People also ask

How do I force an Android app to update React Native?

You can use https://appupgrade.dev/ service to force update you mobile apps. You need to create new version for your app versions you want to update in the app upgrade service and select whether you want to force it or just want to let users know that new version is available. See the response has force update true.

Can we use Android SDK in React Native?

Get started with React Native by installing required tools Android Studio installs the latest Android SDK by default. React Native requires Android 6.0 (Marshmallow) SDK or higher. We recommend using the latest SDK.


Video Answer


2 Answers

There's a fairly new package that does that: sp-react-native-in-app-updates.

It also handles the iOS case by prompting the user with a native alert that redirects to the App Store.

like image 127
Edmundo Rodrigues Avatar answered Oct 26 '22 23:10

Edmundo Rodrigues


I did not find any react-native package for this, so I had to implement it for my self.

You can check the complete tutorial here and below downloadable files here.

But in short, here is what you need to do.

  1. Open android folder in your react-native project with Android Studio and add implementation 'com.google.android.play:core:1.7.3' at the end of dependencies section of the build.gradle(app) file. Like below,
dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules


    .......
    implementation 'com.google.android.play:core:1.7.3' // add it at the end
}

Cick sync after adding the dependency.

  1. Download InAppUpdateModule.java and InAppUpdatePackage.java files and place in them in the same directory of MainActivity.java(android/app/src/main/java/<package>/)
  2. Change the package names in both InAppUpdateModule.java and InAppUpdatePackage.java to your project package name.
  3. Now Open MainApplication.java and add our InAppUpdatePackage into getPackages method like below,
        @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 InAppUpdatePackage());
          return packages;
        }
  1. Download InAppUpdate.js and place it into your react-native project.
  2. Import the InAppUpdate.js in any js file, wherever you want to use. And use it like below.
  componentDidMount () {
    InAppUpdate.checkUpdate() // this is how you check for update 
  }
  1. That's it.

You can download all the files from here

like image 39
Naroju Avatar answered Oct 26 '22 21:10

Naroju