我正在尝试使用风味来构建具有不同资产质量的不同APK。问题在于,在选择了一个构建变体之后,它似乎仍然可以运行所有版本,而不仅仅是正确的版本。
所以我的build.gradle
看起来像这样。
task initialize{
doLast {
configureObbFile.execute()
setupScreenSupport.execute()
}
}
android {
compileSdkVersion 28
defaultConfig {
println("Flavor: default")
applicationId com.test.package
minSdkVersion 19
targetSdkVersion 28
versionName "1.0.0"
}
flavorDimensions "AssetSize"
productFlavors {
tiny {
println("Flavor: tiny assests")
pak_name_suffix = "tiny"
initialize.execute()
}
small {
println("Flavor: small assests")
pak_name_suffix = "small"
initialize.execute()
}
normal {
println("Flavor: normal assests")
pak_name_suffix = "normal"
initialize.execute()
}
tablet {
println("Flavor: tablet assests")
pak_name_suffix = "tablet"
initialize.execute()
}
hightable {
println("Flavor: hightable assests")
pak_name_suffix = "hightable"
initialize.execute()
}
}
[...]
}
我得到类似这样的构建输出
Executing tasks: [:app:assembleHightableDebug]
> Task :app:configureObbFile
> Task :app:setupScreenSupport
Screens pak_name_suffix = "tiny"
> Task :app:initialize
> Task :app:initialize
> Task :app:initialize
> Task :app:initialize
> Task :app:initialize
> Configure project :app
Flavor: default
Flavor: tiny assests
Flavor: small assests
Flavor: normal assests
Flavor: tablet assests
Flavor: hightable assests
如您所见,它确实从 app:assembleHightableDebug 开始,但随后它仅执行从上到下的所有操作。我希望它仅做HighTable分区(默认)。怎么了?我究竟做错了什么?奇怪的是,它似乎只运行一次 configureObbFile 和 setupScreenSupport ,并且具有'微小'风格。