【发布时间】:2020-01-08 17:18:39
【问题描述】:
因为我尝试了这两种方法(一次使用一个)来重命名 APK
选项 - 一个
// To Change the APK and Bundle Name
archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}"
选项 - 两个
(为此还尝试将 - variant.outputs.all 更改为 variant.outputs.each)
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
output.outputFileName = "${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}.apk"
}
}
当我使用选项一个时,
问题 - 它生成所有拆分,但它用 用 Gradle 编写的最后一种风味。
此外,尝试在 defaultConfig 中仅放置一次选项 One,但正如 productFlavours 之后编写的那样,它会在 versionCode 和 versionName 中返回 null 值。
productFlavors {
aFlavor {
applicationId "com.a"
versionCode 5
versionName "1.0.5"
signingConfig signingConfigs.signingA
// To Change the APK and Bundle Name
archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}"
}
bFlavor {
applicationId "com.b"
versionCode 5
versionName "1.0.5"
signingConfig signingConfigs.signingB
// To Change the APK and Bundle Name
archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}"
}
cFlavor {
applicationId "com.c"
versionCode 3
versionName "1.0.3"
signingConfig signingConfigs.signingC
// To Change the APK and Bundle Name
archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}"
}
}
当我使用选项两个时,
问题 - 它生成正确的名称但生成单个 APK 文件。
splits {
abi {
enable true
reset()
include 'arm64-v8a', 'x86', 'x86_64'
universalApk false
}
}
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
output.outputFileName = "${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}.apk"
}
}
捆绑包问题 - 无法使用选项 Two 重命名捆绑包。
【问题讨论】:
-
google.github.io/android-gradle-dsl/current/… 为什么不使用一些标准属性,例如
versionNameSuffix或applicationIdSuffix? -
@daggett 同意,但如果应用程序 ID 和版本名称完全不同怎么办?
标签: android android-studio gradle groovy build.gradle