当我按下“立即同步"和“刷新"按钮时,IDEA/Android Studio 会运行​​哪些 Gradle 任务? [英] What Gradle task(s) does IDEA / Android Studio run when I press Sync Now and the Refresh button?

查看:30
本文介绍了当我按下“立即同步"和“刷新"按钮时,IDEA/Android Studio 会运行​​哪些 Gradle 任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

见下图:

现在同步(蓝色)和刷新按钮(红色)分别有什么作用?单击这些时,Idea/Android Studio 会启动哪些 Gradle 任务和/或其他进程?

What exactly does the Sync now (blue) and refesh button (red) do respectively? What Gradle Tasks and/or other processes does Idea/Android Studio launche when clicking these?

我需要用我的 gradle.build 文件调试一些错误,知道这些按钮的作用将在这方面帮助我.

I need to debug some errors with my gradle.build file and knowing what these buttons do will help me in that regard.

推荐答案

这两个操作在本质上做同样的事情.他们的主要任务是评估 Gradle 构建文件,以将 Android Studio 的项目结构图与 Gradle 构建文件中的真实来源同步.它不会执行特定的任务来执行此操作,而是评估构建文件,将其执行到实际触发任何任务之前的时间点.Gradle 构建了一个项目状态的内部模型,并将这个模型交给 Android Studio,然后 Android Studio 更新其项目结构的概念以反映任何变化.

Both those actions do essentially the same thing. Their primary task is to evaluate the Gradle build files to synchronize Android Studio's picture of the structure of the project with the source of truth in the Gradle build files. It doesn't execute a specific task to do this, but it instead evaluates the build file, executing it up to the point before it would actually fire off any tasks. Gradle builds up an internal model of the state of the project, and it hands this model off to Android Studio, which then updates its notion of project structure to reflect any changes.

在此模型评估过程之后,再次不调用任何特定任务,Android Studio 会执行 generateSources 任务.此步骤会创建任何自动生成的源文件,例如 R.java,IDE 需要这些文件才能为正常开发提供正确的语法突出显示和内容帮助.

After this model evaluation process, which again doesn't invoke any specific tasks, Android Studio does execute the generateSources task. This step creates any automatically generated source files, such as R.java, which need to be there for the IDE to provide proper syntax highlighting and content assist for doing normal development.

Android Studio 会在实际构建之外的时间执行构建文件的事实是您必须小心了解您放入构建文件的任何自定义代码的执行上下文的原因,特别是如果该代码执行长时间运行或具有潜在破坏性的操作——该代码可能会在您意想不到的时间运行,比您预期的更频繁.

The fact that Android Studio will execute the build file at times other than doing an actual build is a reason why you have to be careful about knowing the execution context of any custom code you put in the build file, especially if that code does long-running or potentially destructive operations -- that code could be run at times you may not expect, more often than you expect.

这篇关于当我按下“立即同步"和“刷新"按钮时,IDEA/Android Studio 会运行​​哪些 Gradle 任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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