Here is the all steps to achieve in-app update in React Native
- Open
android
folder in your react-native project withAndroid Studio
and addimplementation "com.google.android.material:material:1.1.0"
andimplementation '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"])
implementation "com.facebook.react:react-native:+" // From node_modules
.......
implementation "com.google.android.material:material:1.1.0"
implementation 'com.google.android.play:core:1.7.3' // 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.
useEffect(() => {
InAppUpdate.checkUpdate() // this is how you check for update
}, []);
- That's it.
Here is the full desciption where you can go through and see how it works and how we can test this feature.
->https://developer.android.com/guide/playcore/in-app-updates#internal-app-sharing
->https://stackoverflow.com/questions/56087064/how-can-i-test-in-app-updates-in-android