[英]Android gradle apk splits, setting versionCode
I'm trying to split an app into abi specific apks, but the version numbers of all the apks are the same.我正在尝试将应用拆分为特定于 abi 的 apk,但所有 apk 的版本号都是相同的。 They need to be different to upload to the play store.它们需要不同才能上传到 Play 商店。 Am I missing something?我错过了什么吗?
splits {
abi {
enable true
reset()
include 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
universalApk true
}
}
This is how your Gradle should look like. 这就是你的Gradle应该是这样的。 You have missed assigning an identifier to the different architecture builds. 您错过了为不同的体系结构构建分配标识符。
android
{
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0
defaultConfig {
applicationId "com.example.app"
minSdkVersion 15
targetSdkVersion 22
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
}
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
universalApk true
}
}
// map for the version code
project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + android.defaultConfig.versionCode
}
}
}
I think this might be a bit cleaner. 我想这可能会更清洁一些。 It might not be as 100% automatable though, but I don't like that * 1000000
and dictionary-lookup trick: 它可能不是100%自动化,但我不喜欢* 1000000
和字典查找技巧:
ext {
versionCodeBase = 30 // 1 higher than current highest versionCode in Play store
}
android {
splits {
density {
enable true // just enable them all
}
abi {
enable true
universalApk false
}
}
android.applicationVariants.all { variant ->
variant.outputs.eachWithIndex { output, outputIndex ->
output.versionCodeOverride = project.ext.versionCodeBase + outputIndex
println variant.buildType.name + ' - ' + output.getFilter(OutputFile.ABI) + ' - ' + output.getFilter(OutputFile.DENSITY) + ': ' + output.versionCodeOverride
}
}
}
Note I'm looping over the variants using eachWithIndex
. 注意我正在使用eachWithIndex
循环变体。
This works because density and abi are not going to change on a user's device. 这是因为密度和abi不会在用户的设备上发生变化。 More work will be needed in this script if you're going to allow for seperate apk files per minSdkVersion
. 如果你打算每minSdkVersion
允许单独的apk文件,那么这个脚本将需要更多的工作。
Lemme just also add the output of the script: Lemme只是添加了脚本的输出:
debug - mips64 - null: 30
debug - x86_64 - null: 31
debug - x86 - null: 32
debug - armeabi-v7a - null: 33
debug - armeabi - null: 34
debug - mips - null: 35
debug - arm64-v8a - null: 36
debug - mips64 - xxxhdpi: 37
debug - x86_64 - xxxhdpi: 38
debug - x86 - xxxhdpi: 39
debug - armeabi-v7a - xxxhdpi: 40
debug - armeabi - xxxhdpi: 41
debug - mips - xxxhdpi: 42
debug - arm64-v8a - xxxhdpi: 43
debug - mips64 - mdpi: 44
debug - x86_64 - mdpi: 45
debug - x86 - mdpi: 46
debug - armeabi-v7a - mdpi: 47
debug - armeabi - mdpi: 48
debug - mips - mdpi: 49
debug - arm64-v8a - mdpi: 50
debug - mips64 - ldpi: 51
debug - x86_64 - ldpi: 52
debug - x86 - ldpi: 53
debug - armeabi-v7a - ldpi: 54
debug - armeabi - ldpi: 55
debug - mips - ldpi: 56
debug - arm64-v8a - ldpi: 57
debug - mips64 - xxhdpi: 58
debug - x86_64 - xxhdpi: 59
debug - x86 - xxhdpi: 60
debug - armeabi-v7a - xxhdpi: 61
debug - armeabi - xxhdpi: 62
debug - mips - xxhdpi: 63
debug - arm64-v8a - xxhdpi: 64
debug - mips64 - hdpi: 65
debug - x86_64 - hdpi: 66
debug - x86 - hdpi: 67
debug - armeabi-v7a - hdpi: 68
debug - armeabi - hdpi: 69
debug - mips - hdpi: 70
debug - arm64-v8a - hdpi: 71
debug - mips64 - xhdpi: 72
debug - x86_64 - xhdpi: 73
debug - x86 - xhdpi: 74
debug - armeabi-v7a - xhdpi: 75
debug - armeabi - xhdpi: 76
debug - mips - xhdpi: 77
debug - arm64-v8a - xhdpi: 78
release - mips64 - null: 30
release - x86_64 - null: 31
release - x86 - null: 32
release - armeabi-v7a - null: 33
release - armeabi - null: 34
release - mips - null: 35
release - arm64-v8a - null: 36
release - mips64 - xxxhdpi: 37
release - x86_64 - xxxhdpi: 38
release - x86 - xxxhdpi: 39
release - armeabi-v7a - xxxhdpi: 40
release - armeabi - xxxhdpi: 41
release - mips - xxxhdpi: 42
release - arm64-v8a - xxxhdpi: 43
release - mips64 - mdpi: 44
release - x86_64 - mdpi: 45
release - x86 - mdpi: 46
release - armeabi-v7a - mdpi: 47
release - armeabi - mdpi: 48
release - mips - mdpi: 49
release - arm64-v8a - mdpi: 50
release - mips64 - ldpi: 51
release - x86_64 - ldpi: 52
release - x86 - ldpi: 53
release - armeabi-v7a - ldpi: 54
release - armeabi - ldpi: 55
release - mips - ldpi: 56
release - arm64-v8a - ldpi: 57
release - mips64 - xxhdpi: 58
release - x86_64 - xxhdpi: 59
release - x86 - xxhdpi: 60
release - armeabi-v7a - xxhdpi: 61
release - armeabi - xxhdpi: 62
release - mips - xxhdpi: 63
release - arm64-v8a - xxhdpi: 64
release - mips64 - hdpi: 65
release - x86_64 - hdpi: 66
release - x86 - hdpi: 67
release - armeabi-v7a - hdpi: 68
release - armeabi - hdpi: 69
release - mips - hdpi: 70
release - arm64-v8a - hdpi: 71
release - mips64 - xhdpi: 72
release - x86_64 - xhdpi: 73
release - x86 - xhdpi: 74
release - armeabi-v7a - xhdpi: 75
release - armeabi - xhdpi: 76
release - mips - xhdpi: 77
release - arm64-v8a - xhdpi: 78
For some reason I always got errors when using the presented solutions. 出于某种原因,在使用所提出的解决方案时总是会出错。 I have multiple productFlavors and my solution now looks like this: 我有多个productFlavors,我的解决方案现在看起来像这样:
android {
flavorDimensions 'app', 'store'
productFlavors {
appFlavorOne {
dimension 'app'
applicationId "com.my.application.id"
versionCode 123
versionName '1.2.3'
}
appFlavorTwo {
dimension 'app'
applicationId "com.my.other.application.id"
versionCode 100
versionName '1.0.0'
}
}
splits {
abi {
enable true
reset()
include 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86'
universalApk true
}
}
// APK Splits based on ABI, map for the version code. Uncomment for appFlavorTwo Builds!
project.ext.versionCodes = ['null':0, 'armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'x86': 4]
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride = android.productFlavors.appFlavorOne.versionCode + project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0)
output.versionNameOverride = android.productFlavors.appFlavorOne.versionName + ' (' + (project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) == 0 ? 'universal' : output.getFilter(com.android.build.OutputFile.ABI)) + ')'
println output.versionNameOverride + ' (' + output.versionCodeOverride + ')'
}
}
}
Create multiple APKs files for the android application using ABI Filters and APK split使用 ABI 过滤器和 APK 拆分为 android 应用程序创建多个 APK 文件
splits {
density {
enable true
exclude "ldpi", "tvdpi", "xxxhdpi"
compatibleScreens 'small', 'normal', 'large', 'xlarge'
}
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a'
exclude "armeabi", "mips", "mips64", 'x86', 'x86_64'
universalApk false
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.