为什么当前版本的Gradle插件不支持按需配置?

Why Configuration on demand is not supported by the current version of the Gradle plugin?

使用 Gradle 4.6 或更高版本时,Android Gradle 插件的 3.1.2 版不支持按需配置。

gradle 在处理包含大量模块的多模块 android 项目时,按需配置非常有用,可以避免不必要的配置。

我找不到解释最新 android 插件不支持按需配置的原因的官方版本 notes/documentation。有没有人更好地理解为什么它不起作用以及未来的计划是什么? (例如,这只是一个临时错误吗?)是否有任何关于此更改的官方文档?

按需配置被“移除”的原因是为了避免不可预测的构建错误。

尽管如此,您仍在使用 gradle 4.4。

Known issue about Android Studio

Configuration on demand with Gradle 4.6: If you're using either Android Plugin for Gradle 3.0.1 or 3.1.0 with Gradle 4.6, you should disable configuration on demand in your gradle.properties file, as shown below, to avoid some unpredictable build errors. This issue should be fixed in a future version of the plugin.

org.gradle.configureondemand=false

首先从 gradle.properties 中删除 org.gradle.configureondemand。

然后在 Android 工作室中, 对于 Mac,转到 Preferences > Build, Execution, Deployment > Compiler 并取消选中按需配置。 对于 Linux/Windows,转到 File > Settings > Build, Execution, Deployment > Compiler 并取消选中按需配置。

Note, there are 2 gradle.properties files

In your project gradle.properties ~/.gradle/gragle.properties

转到文件 -> 设置 -> 构建、执行、部署 -> 编译器并取消选中按需配置。

注意:我正在使用 Android Gradle com.android.tools.build:gradle:3.1.4 和 Gradle 4.10.2(检查文件 ->项目结构 -> 项目)。