为什么在Android项目的build.gradle中有一个自定义的“干净”任务? [英] Why is there a custom 'clean' task in build.gradle for Android projects?

查看:498
本文介绍了为什么在Android项目的build.gradle中有一个自定义的“干净”任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android Studio(版本2.1)中创建新项目时,根build.gradle文件具有以下任务:

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

我注意到一些Android项目没有这个自定义任务,并使用默认的gradle clean任务。有没有上述自定义清理任务的缺点是什么?

解决方案

当您编译代码时,这将删除所有生成目录并运行该项目。这是为了做一个完整的清理,如果你修改了一些Gradle配置文件。
由于这个原因,不要在/ build /文件夹内创建任何目录,因为当Gradle运行干净的任务时它将被删除。
https://developer.android中的更多信息。 com / studio / build / build-cache.html#clear_the_build_cache


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?

解决方案

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

这篇关于为什么在Android项目的build.gradle中有一个自定义的“干净”任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆