如何重命名和生成所有 APK &来自 Gradle 的具有产品风味和 APK 拆分的捆绑包 [英] How to Rename and Generate all APK & Bundle from Gradle with Product flavour and APK Splits
问题描述
因为我已经尝试了这两种方法(一次使用一个)来重命名 APK
选项 - 一个
//更改 APK 和 Bundle 名称archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}";
选项 - 两个
(为此也尝试将 - variant.outputs.all
更改为 variant.outputs.each
)
android.applicationVariants.all { 变体 ->variant.outputs.all { 输出 ->output.outputFileName = "${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}.apk";}}
当我使用选项One时,
<块引用>问题 - 它生成所有拆分,但它使用用 Gradle 编写的最后一种风格.
此外,尝试在 defaultConfig
中只放置一次选项 One 但作为之后编写的 productFlavours,它会在 中返回
和 null
值versionCodeversionName
.
productFlavors {风味{applicationIdcom.a"版本代码 5版本名称1.0.5"签名配置signingConfigs.signingA//更改 APK 和捆绑包名称archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}";}b风味{applicationIdcom.b"版本代码 5版本名称1.0.5"签名配置signingConfigs.signingB//更改 APK 和捆绑包名称archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}";}c风味{applicationIdcom.c"版本代码 3版本名称1.0.3"签名配置signingConfigs.signingC//更改 APK 和捆绑包名称archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}";}}
当我使用选项两个时,
<块引用>问题 - 它生成正确的名称,但生成一个 APK 文件.
splits {阿比{启用真重启()包括arm64-v8a"、x86"、x86_64"通用应用程序错误}}android.applicationVariants.all { 变体 ->variant.outputs.all { 输出 ->output.outputFileName = "${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}.apk";}}
<块引用>
捆绑包问题 - 无法使用选项两个重命名捆绑包.
根据这个 答案,您可以使用 Option - Two
进行细微更改,如下所述仅适用于 APK
,不适用于Bundle/AAB 文件
splits {阿比{启用真重启()包括arm64-v8a"、x86"、x86_64"通用应用程序错误}}android.applicationVariants.all { 变体 ->variant.outputs.all { 输出 ->//新的或更新的output.outputFileName = "${variant.getFlavorName()}-${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}-${output.getFilter(com.android.build.OutputFile.ABI)}.apk"//旧的//output.outputFileName = "${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}.apk";}}
另外,从每个 Flavor 的块中删除该行
//更改 APK 和 Bundle 名称archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}";
通过这个,你得到这样的输出文件名
为了一种味道
- 发布
aFlavor-release-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk
aFlavor-release-v5_1.0.5-16Jan2020_21-26-x86_64.apk
aFlavor-release-v5_1.0.5-16Jan2020_21-26-x86.apk
- 调试
aFlavor-debug-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk
aFlavor-debug-v5_1.0.5-16Jan2020_21-26-x86_64.apk
aFlavor-debug-v5_1.0.5-16Jan2020_21-26-x86.apk
对于 bFlavor
与上面类似的名称只是将前缀aFlavor
更改为bFlavor
like
bFlavor-release-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk
对于 cFlavor
与上面类似的名称只是将前缀aFlavor
更改为cFlavor
并且,versionCode
和 versionName
尊重
cFlavor-release-v3_1.0.3-16Jan2020_21-26-arm64-v8a.apk
As I have tried these 2 ways (using a single at a time) to rename the APK
Option - One
// To Change the APK and Bundle Name
archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}"
Option - Two
(for this also tried to change the - variant.outputs.all
to 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"
}
}
When I use option One,
Issue - it generates all splits but it overrides the flavor config with the last flavor written in Gradle.
Also, try to put option One only once in defaultConfig
but as productFlavours written after that it returns the null
value in versionCode
and versionName
.
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')}"
}
}
When I use option Two,
Issue - it generates the correct name but generates a single APK file.
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"
}
}
Issue for bundle - not able to rename the bundle using option Two.
As per This answer, you can go with Option - Two
with minor changes as mention below only works for APK
, not the Bundle / AAB files
splits {
abi {
enable true
reset()
include 'arm64-v8a', 'x86', 'x86_64'
universalApk false
}
}
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
// New one or Updated one
output.outputFileName = "${variant.getFlavorName()}-${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}-${output.getFilter(com.android.build.OutputFile.ABI)}.apk"
// Old one
// output.outputFileName = "${variant.buildType.name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}.apk"
}
}
Also, remove the line from each Flavor's block
// To Change the APK and Bundle Name
archivesBaseName = "${name}-v${versionCode}_${versionName}-${new Date().format('ddMMMyyyy_HH-mm')}"
By this, you get the output file name like this
For aFlvour
- Release
aFlavor-release-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk
aFlavor-release-v5_1.0.5-16Jan2020_21-26-x86_64.apk
aFlavor-release-v5_1.0.5-16Jan2020_21-26-x86.apk
- Debug
aFlavor-debug-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk
aFlavor-debug-v5_1.0.5-16Jan2020_21-26-x86_64.apk
aFlavor-debug-v5_1.0.5-16Jan2020_21-26-x86.apk
For bFlavor
Similar name as above just change the prefix aFlavor
with bFlavor
like
bFlavor-release-v5_1.0.5-16Jan2020_21-26-arm64-v8a.apk
For cFlavor
Similar name as above just change the prefix aFlavor
with cFlavor
and, versionCode
and versionName
as respected
cFlavor-release-v3_1.0.3-16Jan2020_21-26-arm64-v8a.apk
这篇关于如何重命名和生成所有 APK &来自 Gradle 的具有产品风味和 APK 拆分的捆绑包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!