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?
clean will delete a build directory, all your classes will be removed for a fresh compile. assemble will create an archive (JAR) file from your Java project and will run all other tasks that require compile, test and so on.
You don't need to run the clean task. Gradle will track task dependencies and clean appropriate parts for you. Here's an example Gradle project I created to show that the accepted answer is incorrect. If custom tasks don't track their dependencies well (they're bugged), then clean is a workaround.
Clear your project directory Obviously, try to clean your project from android studio : “Build -> Clean Project”. This will clear your build folders. Clear the cache of Android Studio using “File -> Invalidate Caches / Restart” choose “Invalidate and restart option” and close Android Studio.
In this way the clean task (with the type=delete) deletes the build directory when it runs. It is useful when you modify some config files like the settings.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With