Modify all flavors .class in gradle

I have many flavors in my app.gradle. When I exec gradlew assembleRelease I can find all flavors class in dir app/build/intermediates/classes. Now, I want to modify class(do my task) after class generated. How can I do that?

My task name is 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
            }
        }
    }
}

I have many flavors in my app.gradle. When I exec gradlew assembleRelease I can find all flavors class in dir app/build/intermediates/classes. Now, I want to modify class(do my task) after class generated. How can I do that?

My task name is 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
}
}
}
}
But my task only run once. Help
same question in android - Modify all flavors .class in gradle - Stack Overflow