如何定义在摇篮(Android的一室公寓)构建类型的字符串和替换的文件名 [英] How to define a String by build types in Gradle (Android Studio) and replace the file name
问题描述
我想通过指定的生成类型来替换生成的apk的名称:
I want to replace the name of the generated apks by the specified build type:
android {
buildTypes {
def String proguard
release {
minifyEnabled false
zipAlignEnabled true
proguard = "noproguard"
}
releaseProguard {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
zipAlignEnabled true
proguard = "proguard"
}
}
// Replace the file names
android.applicationVariants.all { variant ->
variant.preBuild.doLast {
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}-${variant.versionCode}-" + proguard +.apk"))
}
}
}
}
但是,如果我做了放签署的APK,我没有得到的APK文件的文件名的noproguard字符串,它越来越被最后生成类型重写。releaseProguard
However, if I make a signed APK with "release", I'm not getting the "noproguard" string in the APK's file name, it's getting overriden by the last build type: releaseProguard.
预计输出的发布:
APP-QA-RELEASE-1.3.1-noprguard.apk
Expected output release: app-qa-release-1.3.1-noprguard.apk
期望的输出 releaseProguard :APP-QA-RELEASE-1.3.1-proguard.apk
Expected output releaseProguard: app-qa-release-1.3.1-proguard.apk
推荐答案
这是你在找不完全的东西。
It is not exactly what you are looking for.
您可以使用的build.gradle
来设置此属性:
You can use your build.gradle
to set this attribute:
android {
//...
defaultConfig {
//...
project.ext.set("archivesBaseName", "XXXX_" + defaultConfig.versionCode);
}
}
分配 archivesBaseName
您将获得类似:
xxxx_0.9.6-flavorName-buildType.apk
您可以使用这个味道块中指定特定的值。
You can use this inside the flavor block to assign specific value.
该属性需要gradle这个-插件 1.3.1
或更高。
This attribute requires the gradle-plugin 1.3.1
or higher.
这篇关于如何定义在摇篮(Android的一室公寓)构建类型的字符串和替换的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!