android 应用自动降版本

android app automatically downgrade version

我制作了我的 android 应用程序的一个版本,例如 0.1.#。现在,版本升级到 0.1.9,代码变成这样

defaultConfig {
        applicationId "myapp.app"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "0.1.9"
        multiDexEnabled = true
    }
    productFlavors {
        demo {
            versionName "0.1.9-demo"
        }
        full {
            versionName "0.1.9-full"
        }
    }

问题是当它安装在某些设备(Huawei Y6 II)上时,它会在 one/two 天后自动将版本降级到 0.1.6。也许这是一种罕见的情况,我已经在 google 中搜索过,但我找不到任何答案。请有人向我解释,我非常感谢你的帮助。谢谢

android:versionCode

An internal version number. This number is used only to determine whether one version is more recent than another, with higher numbers indicating more recent versions. This is not the version number shown to users; that number is set by the versionName attribute. The value must be set as an integer, such as "100". You can define it however you want, as long as each successive version has a higher number. For example, it could be a build number. Or you could translate a version number in "x.y" format to an integer by encoding the "x" and "y" separately in the lower and upper 16 bits. Or you could simply increase the number by one each time a new version is released.

android:版本名

The version number shown to users. This attribute can be set as a raw string or as a reference to a string resource. The string has no other purpose than to be displayed to users. The versionCode attribute holds the significant version number used internally.

基于此您应该增加 versionCode

来源:developer.android.com

如果您的应用程序是位于/system/app(或其他一些系统路径)中的系统应用程序 然后你安装一个版本名称较新的版本(可能是 0.1.9),但版本代码与 0.1.6 相同,系统将在 phone 重新启动时将版本重置为 0.1.6。因为系统认为0.1.9和0.1.6是同一个版本。

所以,每次发布新版本都需要增加VersionCode以避免这个问题。