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

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

问题描述

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

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
}

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

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?

推荐答案

这将在您编译代码和运行项目时删除所有构建目录.如果您修改了一些 Gradle 配置文件,则这样做是为了彻底清理.出于这个原因,重要的是不要在/build/文件夹中创建任何目录,因为当 Gradle 运行清理任务时它会被删除.https://developer.android.com/studio/中的更多信息build/build-cache.html#clear_the_build_cache

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天全站免登陆