build.gradle(Project)和build.gradle(Module)之间的区别 [英] Difference between build.gradle(Project) and build.gradle(Module)
问题描述
我正在尝试将Android异步Http客户端的依赖项添加到我的项目中.因此,项目中有两个build.gradle文件.
I am trying to add a dependency of Android Asynchronous Http Client into my project. So there are two build.gradle files are there in the project.
根据我的理解,存在不同类型的依赖项:
As per my understanding, there are different kind of dependencies:
- 在build.gradle(Project:My-app)的根级别上定义的一个
- 在build.gradle(Project:My-app)的buildscript中一个
- 另一个是build.gradle(Modules:app)
这个问题是关于buildScript依赖关系的存储库,请解释一下前两种类型.
This question is about repositories for dependencies of the buildScript, explain a bit about first two types.
build.gradle(Project:My-app)也说
Also build.gradle(Project:My-app) says
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
所以我想应该在build.gradle(Module:app)中添加Android异步Http客户端的依赖项代码.
So i guess dependency code of Android Asynchronous Http Client should be added in build.gradle(Module:app).
如果有人可以清楚地描述所有这些内容以便更好地理解,那就太好了.
If someone could give a clear picture of all of these for better understanding, it would be great.
推荐答案
build.gradle(Project:My-app)
顶级构建文件,您可以在其中添加通用的配置选项 所有子项目/模块.
Top-level build file where you can add configuration options common to all sub-projects/modules.
每个项目都包含一个top-level gradle file
.它通常包含所有modules
的common configs
.此top-level gradle
中包括的任何内容,都会影响所有modules
.
Each project contains a top-level gradle file
. It usally contains common configs
for all modules
. Whatever is included in this top-level gradle
, it will affect all modules
.
例如:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
//Maven plugin
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module:app)
特定模块的构建文件(您在其中添加依赖项,签名配置,构建类型,风味等)
所有modules
都有特定的gradle
文件.此gradle
文件中包含的所有内容,只会影响其中包含的module
.
All modules
have a specific gradle
file. Whatever is included in this gradle
file, it will only affect the module
that is included on.
例如:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.hrskrs.gesturefun"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
zipAlignEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
zipAlignEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':gesture-fun')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
}
这篇关于build.gradle(Project)和build.gradle(Module)之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!