项目根目录和app文件夹中的两个build.gradles有什么区别?

What is the difference of two build.gradles in project root directory and in app folder?

我刚刚注意到我的项目中有两个 build.gradle 文件。是因为我在导入项目时使用了 gradle wrapper 吗?

在 Android Studio 中,项目根目录中的 build.gradle 和应用程序文件夹中的 build.gradle 有什么区别?

"app" 文件夹只是一个模块。在编写更复杂的应用程序时,您可能有多个模块。模块级别的 build.gradle 仅与该模块相关,而根目录的 build.gradle 与项目中的所有模块相关。

来自项目级别的示例 build.gradle

allprojects {
    repositories {
        jcenter()
    }
}

这就是说所有模块都应该使用 jcenter 存储库来解决依赖关系。现在一个可能令人困惑的事情是 gradle 和 android 工作室之间的术语冲突。 android 工作室 "module" 是 gradle "project" 因此 "allprojects".