🆙🚀 Flutter application upgrade / download Plug-in (with notice bar progress), supports full upgrade, hot update and incremental upgrade
Android and IOS upgrade plugin.
AndroidDownload APK using download link
Androidhot upgrade
Androidincrement upgrade
IOSJump to Appstore upgrade according to appid
IOSGet the current online version of Appstore according to appid
add this code in
pubspec.yaml
dependencies: r_upgrade: last version
void upgradeFromUrl()async{ bool isSuccess =await RUpgrade.upgradeFromUrl( 'https://www.google.com', ); print(isSuccess); }
void upgradeFromAndroidStore(){ bool isSuccess = await RUpgrade.upgradeFromAndroidStore(AndroidStore.GOOGLE_PLAY); print('${isSuccess?'jump success':'jump error'}'); }
make sure your application had this permission and request dynamic permission.
RUpgrade.stream.listen((DownloadInfo info){ ///... });
info:
| param | desc |
| - | - |
| (int) id | download id |
| (int) maxlength | download max bytes length (bytes) |
| (int) currentlength | download current bytes length (bytes) |
| (double) percent | download percent 0-100 |
| (double) planTime | download plan time /s (X.toStringAsFixed(0)) |
| (String) path | download file path |
| (double) speed | download speed kb/s |
| (DownloadStatus) status | download status
STATUS_PAUSED
STATUS_PENDING
STATUS_RUNNING
STATUS_SUCCESSFUL
STATUS_FAILED
STATUS_CANCEL|
This upgrade have two part.
useDownloadManager: -
true: Use system
DownloadManagerto download - advantage:Simple, use system. - Inferiority:can not use http download , can not click the notification pause downloading, can not pause and continue download by network status etc... - support:
RUpgrade.stream、
install、
cancel-
false: Use
Servicedownload(default use) - advantage:Power, support http/https download, support auto pause and continue download by network status etc.. - Inferiority:No bugs found yet. If you find a bug, you are welcome to issue - support:
RUpgrade.stream、
install、
cancel
dart // [isAutoRequestInstall] downloaded finish will auto request install apk. // [apkName] apk name (such as `release.apk`) // [notificationVisibility] notification visibility. // [notificationStyle] download notification show style about content text, only support [useDownloadManager]==false. // [useDownloadManager] if true will use DownloadManager,false will use my service , // if true will no use [pause] , [upgradeWithId] , [getDownloadStatus] , [getLastUpgradedId] methods. // [upgradeFlavor] you can use [RUpgradeFlavor.normal] , [RUpgradeFlavor.hotUpgrade] , [RUpgradeFlavor.incrementUpgrade] flavor void upgrade() async { int id = await RUpgrade.upgrade( 'https://raw.githubusercontent.com/rhymelph/r_upgrade/master/apk/app-release.apk', apkName: 'app-release.apk',isAutoRequestInstall: true); }New upgraded flavor:(no support use DownloadManager)
dart enum RUpgradeFlavor { normal, // full upgrade hotUpgrade, // hot upgrade incrementUpgrade, // increment upgrade }
void cancel() async { bool isSuccess=await RUpgrade.cancel(id); }
void install() async { bool isSuccess=await RUpgrade.install(id); }
void pause() async { bool isSuccess=await RUpgrade.pause(id); }
void pause() async { bool isSuccess=await RUpgrade.upgradeWithId(id); /// return true. /// * if download status is [STATUS_PAUSED] or [STATUS_FAILED] or [STATUS_CANCEL], will restart running. /// * if download status is [STATUS_RUNNING] or [STATUS_PENDING], nothing happened. /// * if download status is [STATUS_SUCCESSFUL] , will install apk. /// /// return false. /// * if not found the id , will return [false]. }
void getLastUpgradeId() async { int id = await RUpgrade.getLastUpgradedId(); }
void getDownloadStatus()async{ DownloadStatus status = await RUpgrade.getDownloadStatus(id); }
./bsdiff old.apk new.apk increment.patch
increment.patchUpload to server
RUpgrade.upgrade(...,upgradeFlavor:RUpgradeFlavor.incrementUpgrade)download file
RUpgrade.install(id)install apk.
The code is as follows: ```dart int id; void incrementUpgrade(){ id = await RUpgrade.upgrade( 'https://mydata-1252536312.cos.ap-guangzhou.myqcloud.com/rupgrade.patch', fileName: 'rupgrade.patch', useDownloadManager: false, isAutoRequestInstall: false, upgradeFlavor: RUpgradeFlavor.incrementUpgrade, ); }
void install(){ try { await RUpgrade.install(id); } catch (e) { _state.currentState .showSnackBar(SnackBar(content: Text('failure!'))); } }
#### 10. Hot Upgrade - you can use this id to hot upgrade,but download file is zip. include three file [isolate_snapshot_data]、[kernel_blob.bin]、[vm_snapshot_data].Your can use `flutter build bundle` generate.
flutter build bundle ```
|- AssetManifest.json |- FontManifest.json |- fonts |- ... |- isolate_snapshot_data * |- kernel-blob.bin * |- LICENSE |- packages |- ... |- vm_snapshot_data *
RUpgrade.upgrade(...,upgradeFlavor:RUpgradeFlavor.hotUpgrade)download file.
idto hot upgrade
bool isSuccess = await RUpgrade.hotUpgrade(id); if (isSuccess) { _state.currentState .showSnackBar(SnackBar(content: Text('Hot update succeeded, exit the application after 3S, please enter again'))); Future.delayed(Duration(seconds: 3)).then((_){ SystemNavigator.pop(animated: true); }); }else{ _state.currentState .showSnackBar(SnackBar(content: Text('Hot update failed, please wait for update package download to complete'))); }
At present, the hot update is still in the testing stage, only supporting the change of the flutter code, not supporting the resource file, etc. the author of the plug-in is not responsible for all the consequences caused by the hot update, and the user is responsible for it.
If you want to customize the content displayed in the download notification bar, you can do so, modify or add files
project/android/app/main/res/values/r_upgrade_value.xml,add the following code
xml %.0f kb/s %.0fs left Download finished Download paused Download failedAnd then.When you use
upgrademethod,you should set the
notificationStyleparam.
dart /// Notification show style about content text enum NotificationStyle { speechAndPlanTime, // 100kb/s 1s left planTimeAndSpeech, // 1s left 100kb/s speech,// 100kb/s planTime, // 1s left none, // }
void upgradeFromAppStore() async { bool isSuccess =await RUpgrade.upgradeFromAppStore( 'your AppId',//such as:WeChat AppId:414478124 ); print(isSuccess); }
void getVersionFromAppStore() async { String versionName = await RUpgrade.getVersionFromAppStore( 'your AppId',//such as:WeChat AppId:414478124 ); print(versionName); }