Android and IOS upgrade plugin.
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'}');
}
RUpgrade.stream.listen((DownloadInfo info){
///...
});
info:
param | desc |
---|---|
(int) id | download id |
(int) max_length ( total Deprecated ) |
download max bytes length (bytes) |
(int) current_length ( progress Deprecated ) |
download current bytes length (bytes) |
(double) percent | download percent 0-100 |
(double) planTime | download plan time /s (X.toStringAsFixed(0)) |
(String) path ( address Deprecated ) |
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 systemDownloadManager
to 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...
false
: UseService
download(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
// [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] look up at
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);
}
useDownloadManager
:
false
: useupgrade
orgetLastUpgradedId
method will return .true
: useupgrade
method will return .
void cancel() async {
bool isSuccess=await RUpgrade.cancel(id);
}
useDownloadManager
:
false
: useupgrade
orgetLastUpgradedId
method will return .true
: useupgrade
method will return .
void install() async {
bool isSuccess=await RUpgrade.install(id);
}
useDownloadManager
:
false
: useupgrade
orgetLastUpgradedId
method will return .
void pause() async {
bool isSuccess=await RUpgrade.pause(id);
}
useDownloadManager
:
false
: useupgrade
orgetLastUpgradedId
method will return .
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].
}
this method will find id by your application version name and version code.
void getLastUpgradeId() async {
int id = await RUpgrade.getLastUpgradedId();
}
useDownloadManager
:
false
: useupgrade
orgetLastUpgradedId
method will return .
void getDownloadStatus()async{
DownloadStatus status = await RUpgrade.getDownloadStatus(id);
}
- 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
generate file path form ./build/flutter_assets and packaged into zip.
|- AssetManifest.json
|- FontManifest.json
|- fonts
|- ...
|- isolate_snapshot_data *
|- kernel-blob.bin *
|- LICENSE
|- packages
|- ...
|- vm_snapshot_data *
download complete you can use download id
to hot upgrade
bool isSuccess = await RUpgrade.hotUpgrade(id);
if (isSuccess) {
_state.currentState
.showSnackBar(SnackBar(content: Text('热更新成功,3s后退出应用,请重新进入')));
Future.delayed(Duration(seconds: 3)).then((_){
SystemNavigator.pop(animated: true);
});
}else{
_state.currentState
.showSnackBar(SnackBar(content: Text('热更新失败,请等待更新包下载完成')));
}
if your application is Android,make sure your application had this permission and request dynamic permission.
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
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/r_upgrade_value.xml
,add the following code
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="r_upgrade_download_speech">%.0f kb/s</string>
<string name="r_upgrade_download_planTime">%.0fs left</string>
<string name="r_upgrade_download_finish">Download finished</string>
<string name="r_upgrade_download_paused">Download paused</string>
<string name="r_upgrade_download_failed">Download failed</string>
</resources>
And then.When you use upgrade
method,you should set the notificationStyle
param.
/// 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);
}