build.gradle(项目)和build.gradle(模块)的区别 [英] 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 in the project.
根据我的理解,有不同类型的依赖:
As per my understanding, there are different kind of dependencies:
- 在 build.gradle (Project:My-app) 的根级别定义的一个
- build.gradle (Project:My-app) 的构建脚本中的一个
- 另一个是 build.gradle (Modules:app)
- One which defined on the root level of build.gradle (Project:My-app)
- One inside the buildscript of the build.gradle (Project:My-app)
- Another is 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
所以我猜Android Asynchronous Http Client的依赖代码应该加在build.gradle(Module:app)中.
So I guess the dependency code of Android Asynchronous Http Client should be added in build.gradle (Module:app).
它们是如何组合在一起的?
How does it all fit together?
推荐答案
build.gradle (Project:My-app)
build.gradle (Project:My-app)
顶级构建文件,您可以在其中添加常见的配置选项所有子项目/模块.
Top-level build file where you can add configuration options common to all sub-projects/modules.
每个项目都包含一个顶级 Gradle 文件.它通常包含所有模块
的通用配置.无论这个顶级 Gradle 文件中包含什么,它都会影响所有模块.
Each project contains a top-level Gradle file. It usually contains common configurations for all modules
. Whatever is included in this top-level Gradle gile, 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)
build.gradle (Module:app)
特定模块的构建文件(在其中添加依赖项、签名配置、构建类型、风格等)
所有模块都有一个特定的 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(项目)和build.gradle(模块)的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!