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.
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.
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.
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.
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.
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.
InAppUpdateModule.java
and InAppUpdatePackage.java
files and place in them in the same directory of MainActivity.java
(android/app/src/main/java/<package>/
)InAppUpdateModule.java
and InAppUpdatePackage.java
to your project package name.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;
}
InAppUpdate.js
and place it into your react-native
project.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
}
You can download all the files from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With