I'm trying to split an app into abi specific apks, but the version numbers of all the apks are the same. They need to be different to upload to the play store. 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. 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
}
}
}
For some reason I always got errors when using the presented solutions. I have multiple productFlavors and my solution now looks like this:
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 + ')'
}
}
}
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:
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
.
This works because density and abi are not going to change on a user's device. More work will be needed in this script if you're going to allow for seperate apk files per minSdkVersion
.
Lemme just also add the output of the script:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With