Last active
October 28, 2016 03:10
-
-
Save zhEdward/c58e9eef07563963b135f036787c0e5d to your computer and use it in GitHub Desktop.
gradle 统一 常量/依赖库 管理方式(二)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion rootProject.ext.compileSdkVersion | |
//在project-level 定义的常量,编译时会默认,所以不必指定'ext' | |
buildToolsVersion rootProject.buildToolsVersion | |
defaultConfig { | |
..... | |
} | |
buildTypes { | |
debug { | |
..... | |
} | |
prod{ | |
...... | |
} | |
} | |
} | |
/* | |
Dependency versions are defined in the top level build.gradle file. This helps keeping track of | |
all versions in a single place. This improves readability and helps managing project complexity. | |
这里开始 引用 project-leve build.gradle 中定义的常量 | |
*/ | |
dependencies { | |
// App's dependencies, including test | |
compile "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion" | |
//不用添加'ext'也可以(理由同上) | |
compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion" | |
//Q:不用添加'$'符号也可以? | |
compile "com.android.support:support-v4:rootProject.supportLibraryVersion" | |
compile "com.google.guava:guava:$rootProject.guavaVersion" | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:2.2.0' | |
// NOTE: Do not place your application dependencies here; they belong | |
// in the individual module build.gradle files | |
} | |
} | |
allprojects { | |
repositories { | |
jcenter() | |
} | |
} | |
// Define versions in a single place | |
//需要使用的依赖库版本 和 编译工具的版本 统一定义如下 | |
ext { | |
// Sdk and tools | |
minSdkVersion = 10 | |
targetSdkVersion = 24 | |
compileSdkVersion = 24 | |
buildToolsVersion = '24.0.2' | |
// App dependencies | |
supportLibraryVersion = '24.2.0' | |
guavaVersion = '18.0' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment