我有以下应用 build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "io.gresse.hugo.anecdote"
minSdkVersion 16
targetSdkVersion 23
versionCode 12
versionName "1.0.0"
}
buildTypes {
release {
archivesBaseName = "anecdote-" + defaultConfig.versionName
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
archivesBaseName = "anecdote-DEBUGDEBUGDEBUG-"
}
}
}
当我执行./gradlew assembleRelease assembleDebug
输出的 .apk 是:
- 轶事-DEBUGDEBUGDEBUG-debug-unaligned.apk
- 轶事-DEBUGDEBUGDEBUG-debug.apk
- 轶事-DEBUGDEBUGDEBUG-release-unaligned.apk
- 轶事-DEBUGDEBUGDEBUG-release.apk
我想要的:
- 轶事-DEBUGDEBUGDEBUG-debug-unaligned.apk
- 轶事-DEBUGDEBUGDEBUG-debug.apk
- anecdote-1.0.0-release-unaligned.apk
- anecdote-1.0.0-release.apk
有什么方法可以将 archiveBaseName 应用到特定的构建类型 还是一个错误?
谢谢,
最佳答案
您可能会注意到,这个问题围绕着 SO 一团糟。
这是对我有用的。我想保留简单的 archiveBaseName
但它似乎已被弃用并且它适用于所有 buildTypes。
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "io.gresse.hugo.anecdote"
minSdkVersion 16
targetSdkVersion 23
versionCode 12
versionName "1.0.0"
}
project.ext.set("archivesBaseName", "Anecdote");
applicationVariants.all { variant ->
variant.outputs.each { output ->
if(variant.buildType.name == "release"){
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-"+variant.versionName + ".apk"))
}
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
关于android - 应用于所有构建类型的 archiveBaseName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38084675/