Preface
19 pandemic in 2020, I had nothing to do at home, so I wrote a flutter version update plugin: , and published it on the Dart plugin platform established by Google, and received it in the past year. The response is not bad, as shown in the figure below:
But at the same time, it has also received many questions from users.
For this reason, I briefly looked at the problem and found that the user may not have done Android native development before, and the basic knowledge of Android is very lacking, which will cause many problems.
Here, in order to allow everyone to better use flutter_xupdate achieve one-click version update, I specially counted several major problems that may arise during the use process, and cleared mines in advance. Not only that, I also specially recorded For the first video, should the friends who like to watch the video quickly support it for three consecutive times?
The video address is as follows: https://www.bilibili.com/video/BV1gy4y1g7pB/
https://www.bilibili.com/video/BV1gy4y1g7pB/?aid=803672050&cid=357307749&page=1
common problem
Ok, let's get back to business, let's take a look briefly, what are the common problems?
- 1. The version update pop-up window cannot be displayed.
- 2. The version update prompt displays abnormally.
- 3. The update cannot be installed after downloading.
- 4. Forced update does not work.
- 5. Internationalization issues.
Below I will answer for you one by one.
Unable to display the version update popup
There may be a variety of situations in which the pop-up window cannot be displayed for the version update. The main manifestations are: an update error occurs or it shows that there is no version update currently.
1. The problem with the interface
Prerequisite: The default interface provided by the framework used by
The requested url does not return json in the default format, so there will be problems with json serialization, resulting in failure to obtain version information and unable to determine the update status.
Because the underlying call of is 160d0dabdf0318 XUpdate , its default json format is as follows:
{
"Code": 0, //0代表请求成功,非0代表失败
"Msg": "", //请求出错的信息
"UpdateStatus": 1, //0代表不更新,1代表有版本更新,不需要强制升级,2代表有版本更新,需要强制升级
"VersionCode": 3, //本地也会对版本号进行校验,确保升级的时候,版本号自增
"VersionName": "1.0.2",
"ModifyContent": "1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。",
"DownloadUrl": "https://raw.githubusercontent.com/xuexiangjys/XUpdate/master/apk/xupdate_demo_1.0.2.apk",
"ApkSize": 2048
"ApkMd5": "..." //应用apk的md5值没有的话,就无法保证apk是否完整,每次都会重新下载。框架默认使用的是md5加密。
}
If any of the above fields do not meet, it may cause json parsing to fail and the version update pop-up window cannot be displayed. Unless you use a custom interface or directly pass in UpdateEntity
to update.
The problem with the version number
Prerequisite: The default interface provided by the framework used by
Similarly, using the default interface, the returned json format is also normal and can be parsed normally, except that the returned VersionCode
not self-incremented, which causes the local version number update verification to fail, and the version update pop-up window cannot be displayed.
The problem of obfuscating packaging
Prerequisite: (updated by default), and debug runs normally.
This situation occurs mainly because the code obfuscation is set in the android native project. However, if flutter build apk --release
is used for packaging, the obfuscation configuration will not take effect (because the command uses R8 compression by default, there will be problems).
There are three ways to solve it:
- 1. Use the
flutter build apk --no-shrink
instruction instead. - 2. Actively turn off R8 compression and use D8 compression instead. The method is to enter the
android
directory of thegradle.properties
as follows:
org.gradle.jvmargs=-Xmx1536M
# 开启D8压缩
android.enableD8=true
android.useAndroidX=true
android.enableJetifier=true
# 关闭R8压缩
#android.enableR8=true
- 3. Directly use android's native packaging method for packaging. The method is to enter the android directory of the current project and use the
./gradlew assembleRelease
command to package.
The version update prompt is displayed abnormally
Prerequisite: uses a custom update pop-up style, and sets the topImageRes
attribute.
The phenomenon that appears is generally displayed normally under debug, but it is displayed abnormally under release. The details are as follows:
This problem occurs, the main reason is that the top style customization of the update pop-up window uses the reflective reference method, so when you open the release package, if we do not set shrinkResources
to false, the packager will clear your customization by default At the top of the picture, the picture is not displayed under the release.
So at this time, we only need to shrinkResources
display of 060d0dabdf05e8 to false. For details, please refer to the following figure:
Unable to install the update after downloading
There may be many situations in which the update cannot be installed after the download is completed. The main manifestations are: unable to enter the application installation page or prompt installation failure (inconsistent signature/file parsing failure).
1. The problem of apk download
If the apk is not completely down, or the downloaded apk is damaged and cannot be installed, it must not be installed properly.
So here we can open the debug log first, then get the downloaded apk path, and then find the specified file and open it to see if it can be installed normally. (First of all, ensure that the downloaded file is correct).
2. The problem of setting the MD5 value
Note that the MD5 value here refers to the MD5 value of the application APK file , not the MD5 value of the application signature file! !
The reason why the MD5 value download verification is set is to prevent the file download from being tampered with or incomplete, so the framework will verify the MD5 value of the downloaded APK.
But many people don't understand the principle of this, so when using it for the first time, it is easy to set the MD5 value to the MD5 value of the application signature file.
3. The issue of signing
I believe anyone who has done Android native development knows that applications under the same package name cannot directly overwrite and install (update and upgrade) applications with different signatures. Applications with the same package name can only overwrite and install application apks with the same signature.
If you did not configure the same signature as the release when debugging, you cannot directly overwrite and upgrade to the release package.
4. The problem of the equipment terminal
Because the rom and version of the Android device terminal are different, the general apk installation method may not work on some customized rom machines. The probability of this kind of problem is relatively low, when none of the above 3 points If there is a problem, you can try to use a different model of machine to try whether it can be installed to eliminate the problem of a specific device model.
Forced update does not work
Prerequisite: use a custom interface or directly pass in UpdateEntity
to update.
This is because the isForce
and isIgnorable
UpdateEntity
object are mutually exclusive. If isIgnorable
is true
, at this time, setting isForce
to true
isForce
is impossible to ignore and can be ignored, and it will be invalid. It is also impossible for the version update to be mandatory.
Internationalization issues
Because the bottom layer of flutter_xupdate calls the XUpdate native library, the update UI is written natively, so if you want to achieve multi-language internationalization, you need to use native internationalization for configuration.
error code
Finally, common error codes are attached to facilitate the discovery of problems when debugging.
error code | Remarks |
---|---|
2000 | Query update failed |
2001 | No wifi |
2002 | No internet |
2003 | Version update in progress |
2004 | No latest version |
2005 | Version check returns empty |
2006 | Version check returns json parsing failed |
2007 | Ignored version |
2008 | The cache directory for app download is empty |
3000 | Version prompter exception error |
3001 | The Activity page where the version indicator is located is destroyed |
4000 | Failed to download the new application installation package |
4001 | Failed to apply for read and write permissions |
4002 | Cancel download |
5000 | apk installation failed |
5100 | unknown mistake |
At last
The above is all the content I have compiled. If you like, please remember to go to the homepage of the project: https://github.com/xuexiangjys/flutter_xupdate star to support it~
I am xuexiangjys, a technical up master who loves learning, programming, and is committed to Android architecture research and open source project experience sharing. For more information, welcome to search the public number on : 160d0dabdf0a5b [My Android Open Source Journey]
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。