google 文檔說(shuō)明 對(duì)應(yīng)地址: https://developer.android.com/studio/build
1漏麦、buildscript是gradle腳本執(zhí)行需要的依賴
2贫途、allprojects里是項(xiàng)目本身需要的依賴位他。表示項(xiàng)目里面每個(gè)build.gradle 里面的庫(kù)都會(huì)依賴用這些倉(cāng)庫(kù)。
頂層構(gòu)建文件 :頂層 build.gradle 文件位于項(xiàng)目的根目錄下伏恐,用于定義適用于項(xiàng)目中所有模塊的構(gòu)建配置。默認(rèn)情況下,頂層構(gòu)建文件使用 buildscript 代碼塊定義項(xiàng)目中所有模塊共用的 Gradle 代碼庫(kù)和依賴項(xiàng)璧针。以下代碼示例說(shuō)明了創(chuàng)建新項(xiàng)目后可在頂層 build.gradle 文件中找到的默認(rèn)設(shè)置和 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塊是對(duì)Gradle 配置存儲(chǔ)庫(kù)和依賴渊啰。其意味著探橱,對(duì)你的模塊 module 不應(yīng)該包括依賴項(xiàng)申屹。例如,這個(gè)塊包括Gradle依賴項(xiàng)的Android插件隧膏,因?yàn)樗峁〨radle構(gòu)建Android應(yīng)用程序模塊所需要的額外的指令哗讥。
*/
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搜索或下載依賴項(xiàng)。Gradle預(yù)配置支持對(duì)遠(yuǎn)程JCenter胞枕、Maven Central和Ivy等存儲(chǔ)庫(kù)杆煞。您也可以使用本地存儲(chǔ)庫(kù)或定義您自己的遠(yuǎn)程存儲(chǔ)庫(kù)。下面的代碼定義JCenter作為Gradle用來(lái)查找其依賴關(guān)系的存儲(chǔ)庫(kù)腐泻。
*/
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建立項(xiàng)目所需要使用的依賴項(xiàng)决乎。下面一行為Gradle添加了Android4.0.0插件版本作為類路徑依賴項(xiàng)。
*/
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塊是配置項(xiàng)目中所有模塊使用的依賴項(xiàng)和存儲(chǔ)庫(kù)派桩,例如第三方插件或者庫(kù)构诚。但是,您應(yīng)該在每個(gè)模塊級(jí)別build.gradle 文件中配置特定于模塊的依賴項(xiàng)铆惑。對(duì)于新項(xiàng)目范嘱,Android Studio默認(rèn)情況下包括JCenter和Google的Maven存儲(chǔ)庫(kù),但它沒(méi)有配置任何依賴項(xiàng)(除非選擇的模板需要某些依賴項(xiàng))员魏。
*/
allprojects {
repositories {
google()
jcenter()
}
}