Gradle的使用资料网上有的已经够多了,不一一赘述。
这里只说一个方便依赖管理的Tip:
- 在项目(Project)定义全局变量(ext)
def String supportVersion = "25.+"
def String frescoVersion = "1.2.0"
ext {
compileCommon = ([
"com.android.support:appcompat-v7:${supportVersion}",
"com.android.support:support-v13:${supportVersion}",
"com.android.support:design:${supportVersion}",
"com.android.support:percent:${supportVersion}",
"com.google.code.gson:gson:+",
"com.facebook.fresco:fresco:${frescoVersion}",
"com.facebook.fresco:animated-gif:${frescoVersion}",// For animated GIF support
"com.facebook.fresco:animated-webp:${frescoVersion}",// For WebP support, including animated WebP
"com.facebook.fresco:imagepipeline-okhttp3:${frescoVersion}",
"com.squareup.okhttp3:okhttp:+",
"com.squareup.okio:okio:+",
])
compileTest = 'junit:junit:4.12'
}
- 在模块(Module)引用依赖
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(rootProject.ext.compileCommon)
compile([
'com.jcodecraeer:xrecyclerview:1.3.2',
'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:1.0.2',// 微信SDK,
'com.google.zxing:core:3.3.0',
'com.github.mcxtzhang:SwipeCaptcha:V1.0.0'
])
testCompile rootProject.ext.compileTest
}