問題描述
將 Eclipse 項目導入 Android Studio 后,我看到兩個 build.gradle
文件:
After having imported an Eclipse project into Android Studio, I see two build.gradle
files:
1 - <PROJECT_ROOT>uild.gradle
2 - <PROJECT_ROOT>appuild.gradle
第一個版本較短,第二個版本包含compileSdkVersion
等的定義.
The first version is shorter, the second version contains definitions for compileSdkVersion
, etc.
擁有兩個獨立文件的目的是什么?是否有單獨的構建任務?
What is the purpose behind having two separate files? Are there separate build tasks?
推薦答案
<PROJECT_ROOT>appuild.gradle
專用于 app 模塊.
<PROJECT_ROOT>uild.gradle
是一個頂級構建文件",您可以在其中添加所有子項目/模塊通用的配置選項.
<PROJECT_ROOT>uild.gradle
is a "Top-level build file" where you can add configuration options common to all sub-projects/modules.
如果您在項目中使用另一個模塊,作為本地庫,您將擁有另一個 build.gradle
文件:<PROJECT_ROOT>moduleuild.gradle
If you use another module in your project, as a local library you would have another build.gradle
file:
<PROJECT_ROOT>moduleuild.gradle
對于頂級文件中的 example,您可以指定以下常用屬性:
For example in your top level file you can specify these common properties:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
ext {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
}
在你的 appuild.gradle
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
這篇關于為什么一個 Android Studio 項目中有兩個 build.gradle 文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!