在不超过 Google 播放限制的情况下区分 ABI 和密度的 VersionCode?
differentiate VersionCode for ABI and Density without going over the Google Play limit?
Google Play 版本代码允许的最大数量是 2100000000 但我的应用程序已经有一个 8 位版本代码(2 = 主要,2 = 次要,1 = 补丁,3 = 提交数数)。 abi/density 版本留下一位数字。如何区分这两者,使我的 APK 版本不同?
ext.abiCodes = ['armeabi-v7a':1, 'arm64-v8a':2]
// Map for the version code that gives each density a value.
ext.densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3, 'xxhdpi': 4, 'xxxhdpi': 5]
android.applicationVariants.all { variant ->
// Assigns a different version code for each output APK.
variant.outputs.each { output ->
// Indexes: 0 = density/abi version, 1-2 = Major, 3-4 = Minor, 5 = Patch, 6-8 = commit count.
int baseVersionCode = 100000000
// Stores the value of ext.densityCodes that is associated with the density for this variant.
def baseDensityVersionCode =
// Determines the density for this variant and returns the mapped value.
project.ext.densityCodes.get(output.getFilter(OutputFile.DENSITY))
if (baseDensityVersionCode != null) {
// Set the APK version
output.versionCodeOverride =
baseDensityVersionCode * baseVersionCode + variant.versionCode
}
// Stores the value of ext.abiCodes that is associated with the ABI for this variant.
def baseAbiVersionCode =
// Determines the ABI for this variant and returns the mapped value.
project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
if (baseAbiVersionCode != null) {
// Set the APK version
output.versionCodeOverride =
baseAbiVersionCode * baseVersionCode + variant.versionCode
}
}
}```
This gives me the same version code for all density variations of a specific abi.
您是否考虑过发布 Android App Bundle?这会处理它,因为您只有一个工件(具有单个版本代码)上传到 Play 控制台,Play 将负责为不同的 ABI 和密度(具有相同的版本代码)生成 APK。
如果出于某种原因您不想这样做,假设您有 2 个 ABI 和 5 个密度,那就是 10 种组合,所以这应该足以容纳一个数字,例如(abiNum - 1) * 5 + densityNum.
但请记住,您正坐在一颗定时炸弹上,因为您将更快地刻录版本代码,而且一旦您决定支持额外的 ABI 或屏幕密度,这将不起作用没有了。
Google Play 版本代码允许的最大数量是 2100000000 但我的应用程序已经有一个 8 位版本代码(2 = 主要,2 = 次要,1 = 补丁,3 = 提交数数)。 abi/density 版本留下一位数字。如何区分这两者,使我的 APK 版本不同?
ext.abiCodes = ['armeabi-v7a':1, 'arm64-v8a':2]
// Map for the version code that gives each density a value.
ext.densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3, 'xxhdpi': 4, 'xxxhdpi': 5]
android.applicationVariants.all { variant ->
// Assigns a different version code for each output APK.
variant.outputs.each { output ->
// Indexes: 0 = density/abi version, 1-2 = Major, 3-4 = Minor, 5 = Patch, 6-8 = commit count.
int baseVersionCode = 100000000
// Stores the value of ext.densityCodes that is associated with the density for this variant.
def baseDensityVersionCode =
// Determines the density for this variant and returns the mapped value.
project.ext.densityCodes.get(output.getFilter(OutputFile.DENSITY))
if (baseDensityVersionCode != null) {
// Set the APK version
output.versionCodeOverride =
baseDensityVersionCode * baseVersionCode + variant.versionCode
}
// Stores the value of ext.abiCodes that is associated with the ABI for this variant.
def baseAbiVersionCode =
// Determines the ABI for this variant and returns the mapped value.
project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
if (baseAbiVersionCode != null) {
// Set the APK version
output.versionCodeOverride =
baseAbiVersionCode * baseVersionCode + variant.versionCode
}
}
}```
This gives me the same version code for all density variations of a specific abi.
您是否考虑过发布 Android App Bundle?这会处理它,因为您只有一个工件(具有单个版本代码)上传到 Play 控制台,Play 将负责为不同的 ABI 和密度(具有相同的版本代码)生成 APK。
如果出于某种原因您不想这样做,假设您有 2 个 ABI 和 5 个密度,那就是 10 种组合,所以这应该足以容纳一个数字,例如(abiNum - 1) * 5 + densityNum.
但请记住,您正坐在一颗定时炸弹上,因为您将更快地刻录版本代码,而且一旦您决定支持额外的 ABI 或屏幕密度,这将不起作用没有了。