我試圖將應用程序拆分爲abi特定的apks,但所有apks的版本號都是相同的。他們需要不同才能上傳到Play商店。我錯過了什麼嗎?Android gradle apk分割,設置版本代碼
splits {
abi {
enable true
reset()
include 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
universalApk true
}
}
我試圖將應用程序拆分爲abi特定的apks,但所有apks的版本號都是相同的。他們需要不同才能上傳到Play商店。我錯過了什麼嗎?Android gradle apk分割,設置版本代碼
splits {
abi {
enable true
reset()
include 'x86', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
universalApk true
}
}
我想如果你想做一個快速的谷歌搜索,你會得到所有的答案。無論如何,這就是你的gradle應該是什麼樣子的。您錯過了將標識符分配給不同的架構版本。
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
}
}
}
感謝。我嘗試了一些這樣的事情,但沒有奏效。但是當我有機會時,我會逐字地嘗試你的代碼。 – Daykm
我認爲這可能有點乾淨。它可能不是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
}
}
}
注意我在循環使用eachWithIndex
的變種。
這是可行的,因爲密度和abi不會在用戶的設備上發生變化。如果您打算根據minSdkVersion
允許單獨的apk文件,則需要在此腳本中進行更多的工作。
還是讓我也只是添加腳本的輸出:
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
請注意,這並不理想。版本代碼需要正確排序,例如xxxhdpi設備將採用適用於他們的最高版本代碼。如果xhdpi是比xxxhdpi更高版本的代碼,它將運行xhdpi應用程序。在另一個答案中使用查找表對它們排序並不是一個壞主意。 – xorgate
出於某種原因,使用提出解決方案時,我總是得到錯誤。我有多個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 + ')'
}
}
}
了最新的AS和gradle這個版本我得到使用此:找不到搖籃DSL方法:「universalapk()」 – David