Google released In App Update feature, but I did not find any react-native
supported library for that, so I had to implement it for myself.
- Open
android
folder in your react-native project withAndroid Studio
and addimplementation 'com.google.android.play:core:1.7.3'
at the end of dependencies section of thebuild.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.
- Download
InAppUpdateModule.java
andInAppUpdatePackage.java
files and place in them in the same directory ofMainActivity.java
(android/app/src/main/java/<package>/
) - Change the package names in both
InAppUpdateModule.java
andInAppUpdatePackage.java
to your project package name. - Now Open
MainApplication.java
and add ourInAppUpdatePackage
intogetPackages
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;
}
- Download
InAppUpdate.js
and place it into yourreact-native
project. - Import the
InAppUpdate.js
in anyjs
file, wherever you want to use. And use it like below.
componentDidMount () {
InAppUpdate.checkUpdate() // this is how you check for update
}
- That's it.
- It is
FLEXIBLE
update by dafault, if the user does not update in 5 days, it becomesIMMEDIATE
update, you can change the number by editingSTALE_DAYS
inInAppUpdateModule.java
. - It does not include prioriy update, you can implement it by editing
checkUpdate
method inInAppUpdateModule.java
. For more details check https://developer.android.com/guide/playcore/in-app-updates#check-priority