我想为versionCode
构建类型提供不同的debug
,而不是release
构建类型中的variant.mergedFlavor.versionCode
。这曾经在Gradle Android插件v2.3.2(Gradle v3.3)中使用下面的配置工作,但现在在v3.0.0-alpha5中没有任何效果(Gradle v4.1-milestone-1) 。有关最新Gradle插件中哪些内容发生变化的想法会忽略buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-" + buildTime()
android.applicationVariants.all { variant ->
if (variant.buildType.name != buildTypes.debug.name) return
variant.outputs.all {
outputFileName = "${archivesBaseName}-${variant.name}-v${variant.versionName}-signed.apk"
variant.mergedFlavor.versionCode = Integer.parseInt(buildTimeSmall())
}
}
}
}
属性吗?
{{1}}
答案 0 :(得分:7)
作为3.0版本之前的解决方法,如果有人在寻找解决方案,您可以使用:
output.setVersionCodeOverride(Integer.parseInt(buildTimeSmall()))
感谢杰罗姆,参考:https://issuetracker.google.com/issues/63785806#comment6
答案 1 :(得分:2)
使用 Variant API 操作变体输出会被新插件破坏。它仍然适用于简单的任务,例如在构建时更改APK名称,如下所示:
// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
但是,涉及访问 outputFile 对象的更复杂的任务不再有效。这是因为在配置阶段不再创建特定于变体的任务。这导致插件不能预先知道所有输出,但也意味着更快的配置时间。作为替代方案,我们将引入新的API以提供类似的功能。