google 文档说明 对应地址: https://developer.android.com/studio/build
1、buildscript是gradle脚本执行需要的依赖
2、allprojects里是项目本身需要的依赖。表示项目里面每个build.gradle 里面的库都会依赖用这些仓库。
顶层构建文件 :顶层 build.gradle 文件位于项目的根目录下,用于定义适用于项目中所有模块的构建配置。默认情况下,顶层构建文件使用 buildscript 代码块定义项目中所有模块共用的 Gradle 代码库和依赖项。以下代码示例说明了创建新项目后可在顶层 build.gradle 文件中找到的默认设置和 DSL 元素。
/**
* The buildscript block is where you configure the repositories and
* dependencies for Gradle itself—meaning, you should not include dependencies
* for your modules here. For example, this block includes the Android plugin for
* Gradle as a dependency because it provides the additional instructions Gradle
* needs to build Android app modules.
翻译软件后解释:
buildscript块是对Gradle 配置存储库和依赖。其意味着,对你的模块 module 不应该包括依赖项。例如,这个块包括Gradle依赖项的Android插件,因为它提供Gradle构建Android应用程序模块所需要的额外的指令。
*/
buildscript {
/**
* The repositories block configures the repositories Gradle uses to
* search or download the dependencies. Gradle pre-configures support for remote
* repositories such as JCenter, Maven Central, and Ivy. You can also use local
* repositories or define your own remote repositories. The code below defines
* JCenter as the repository Gradle should use to look for its dependencies.
*
* New projects created using Android Studio 3.0 and higher also include
* Google's Maven repository.
翻译软件后解释:
repositories块用于配置Gradle搜索或下载依赖项。Gradle预配置支持对远程JCenter、Maven Central和Ivy等存储库。您也可以使用本地存储库或定义您自己的远程存储库。下面的代码定义JCenter作为Gradle用来查找其依赖关系的存储库。
*/
repositories {
google()
jcenter()
}
/**
* The dependencies block configures the dependencies Gradle needs to use
* to build your project. The following line adds Android plugin for Gradle
* version 4.0.0 as a classpath dependency.
翻译软件后解释:
dependencies块配置Gradle建立项目所需要使用的依赖项。下面一行为Gradle添加了Android4.0.0插件版本作为类路径依赖项。
*/
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
/**
* The allprojects block is where you configure the repositories and
* dependencies used by all modules in your project, such as third-party plugins
* or libraries. However, you should configure module-specific dependencies in
* each module-level build.gradle file. For new projects, Android Studio
* includes JCenter and Google's Maven repository by default, but it does not
* configure any dependencies (unless you select a template that requires some).
翻译软件后解释:
allprojects块是配置项目中所有模块使用的依赖项和存储库,例如第三方插件或者库。但是,您应该在每个模块级别build.gradle 文件中配置特定于模块的依赖项。对于新项目,Android Studio默认情况下包括JCenter和Google的Maven存储库,但它没有配置任何依赖项(除非选择的模板需要某些依赖项)。
*/
allprojects {
repositories {
google()
jcenter()
}
}