简体   繁体   中英

How can I fix a bug in an old version of an android app when the latest version has a higher minSDKversion level?

Say I release an android app that requires API Level 2, and I have the following in the manifest.

android:versionCode="1"
android:versionName="1.0"
android:minSdkVersion=2

Then I create a major update which now requires API level 3

android:versionCode="3"
android:versionName="2.0"
android:minSdkVersion=3

Now what if I find a bug in version 1.0 that I want to fix? There may still be version 1.0 users that have a device that does not support API level 3.

I could release the following

android:versionCode="4"
android:versionName="1.1"
android:minSdkVersion=2

But then all the the original 2.0 users will get downgraded to 1.1. Would I just need to simultaneously release an even newer API level 3 release?

android:versionCode="5"
android:versionName="2.1"
android:minSdkVersion=3

Is there a better way to handle this situation? Should I instead space out my version code values to allow for intermediate updates like this?

Should I instead space out my version code values to allow for intermediate updates like this?

This. If you release an update with a higher version requirement, and you intend to continue to support users of the older version, it's best to leave sufficient space in your version codes to update both versions independently.

I'd say the best way to achieve this is to include either the version of Android you are targeting as part of the version code, or derive the version code from the version name (if your version names provide sufficient space for updates).

android:versionCode="2001"
android:versionName="1.0"
android:minSdkVersion=2

android:versionCode="3001"
android:versionName="2.0"
android:minSdkVersion=3

android:versionCode="2002"
android:versionName="1.1"
android:minSdkVersion=2

android:versionCode="3002"
android:versionName="2.1"
android:minSdkVersion=3

or

android:versionCode="1000"
android:versionName="1.0"
android:minSdkVersion=2

android:versionCode="2000"
android:versionName="2.0"
android:minSdkVersion=3

android:versionCode="1001"
android:versionName="1.1"
android:minSdkVersion=2

android:versionCode="2001"
android:versionName="2.1"
android:minSdkVersion=3

You might be able to use maxSdkVersion for this purpose. For version 1.1 you could do:

android:versionCode="4"
android:versionName="1.1"
android:minSdkVersion=2
android:maxSdkVersion=2

maxSdkVersion is deprecated and not recommended by Google, but it should still filter version 1.1 for devices with API level 3 in Google Play (although they could still side load it, but I wouldn't worry about that). For more info about this attribute, check the docs .

For another answer, check here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM