React Native Version Upgrade plugin (Android only), react-native version requires 0.17.0 and above
How to install 1. Install the NPM package first
NPM Install react-native-upgrade-android--save
2.link Auto Link Method ~ NPM requires node version 4.1 or higher
NPM Link
Link Success Command line prompt
NPM info linking react-native-upgrade-android Android dependency
Manual link~ (if Auto link is not possible)
# # # #Android
// file: android/settings.gradle...include ‘:react-native-upgrade-android‘project(‘:react-native-upgrade-android‘).projectDir = new File(settingsDir, ‘../node_modules/react-native-upgrade-android/android‘)
// file: android/app/build.gradle...dependencies { ... compile project(‘:react-native-upgrade-android‘)}
android/app/src/main/java/<你的包名>/MainActivity.java
, public class MainActivity
previously added:
Com.lenny.modules.upgrade.UpgradeModule;
If react-native-is .addPackage(new MainReactPackage())
added after version <0.18.0:
. Addpackage (upgradpackage ())
If react-native-version >=0.18.0 is new MainReactPackage()
added later
,upgradepackage ()
How to use the ingest package
import Upgrade from ‘react-native-upgrade-android‘;
Apiupgrade.init ()
Must be initialized before use
Similar to the following:
Componentdidmount () { const { isSet, this . if (Platform.') iOSUpgrade. Init (); }}
Weiboapi.startdownload (DownloadURL, version, FileName)
Start download
Parameter information downloadurl: Download apk address (absolute address)string version: The version number to download (prevents duplicate downloads)string fileName
Add Listener
Similar to the following:
Componentdidmount () {const {IsSet,}=This.Propsif (Platform.OS!==' iOS‘) {Upgrade.Init ();Deviceeventemitter.AddListener (' Progress‘, (E= = {if (E.Code===' 0000‘) {Start downloadThis.SetState ({isloading:True,}); }Elseif (E.Code===' 0001') { //download, update progress bar this . SetState ({fileSize: E.fileSize, downsize: E.downsize,}); Else if (E.code = = = ' 0002') { //download complete this . SetState ({fileSize: E.fileSize, downsize: E.downsize,});}}); }}
GitHub Address: Https://github.com/lennyup/react-native-upgrade-android
React-native-upgrade-android