0
我在app.gradle中有很多風味。當我執行gradlew assembleRelease
我可以在目錄app/build/intermediates/classes
中找到所有的口味類。現在,我想在類生成後修改類(執行我的任務)。我怎樣才能做到這一點?修改gradle中的所有風味.class
我的任務名稱是m。
gradle.projectsEvaluated {
def buildTypes = android.buildTypes.collect { type -> type.name }
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
// When no product flavors defined, use empty
if (!productFlavors) {
productFlavors.add('')
}
productFlavors.each { productFlavorName ->
buildTypes.each { buildTypeName ->
def flavorNameCapitalized = "${productFlavorName.capitalize()}"
def buildNameCapitalized = "${buildTypeName.capitalize()}"
def targetName = "${flavorNameCapitalized}${buildNameCapitalized}"
def preTaskName = "compile${targetName}JavaWithJavac"
def nextTaskName = "compile${targetName}Ndk"
if (!isDebug(buildNameCapitalized.toString())) {
project.tasks.findByName("generate${targetName}Sources").doLast { //generate${targetName}Sources
println("projectsEvaluated flavorName: " + flavorNameCapitalized.toString())
println("projectsEvaluated buildName: " + buildNameCapitalized.toString())
project.ext.set("flavorName", flavorNameCapitalized.toString());
project.ext.set("buildName", buildNameCapitalized.toString());
}
m.dependsOn project.tasks.findByName(preTaskName)
project.tasks.findByName(nextTaskName).dependsOn m
}
}
}
}
但我的任務只運行一次。幫助