Why is there a custom 'clean' task in buil

2019-04-07 07:23发布

问题:

When creating a new project in Android Studio (version 2.1), the root build.gradle file has the following task:

task clean(type: Delete) {
    delete rootProject.buildDir
}

I've noticed that some Android projects does not have this custom task and uses the default gradle clean task. What is the drawback with not having the above custom clean task?

回答1:

This will delete all the build directory when you compile the code and run the project. This is done in order to do a complete clean if you have modified some Gradle config files. For this reason it is important to not create any directory inside the /build/ folder as it will be deleted when Gradle runs the clean task. Some more info in https://developer.android.com/studio/build/build-cache.html#clear_the_build_cache



回答2:

As you said this template is likely new in template of new projects. That would be easy to override it for trending apt (Compile-Time Annotation Processing) libraries which generates codes to clean them.