android gradle的全局管理

转自:https://github.com/stormzhang

工程目录下建立baseConfig.gradle文件

内容如下

ext {

    android = [compileSdkVersion: 23,
               buildToolsVersion: "23.0.2",
               applicationId    : "me.storm.ninegag",
               minSdkVersion    : 14,
               targetSdkVersion : 22,
               versionCode      : 2,
               versionName      : "1.1.0"]

    dependencies = ["support-v4"               : 'com.android.support:support-v4:23.1.1',
                    "appcompat-v7"             : 'com.android.support:appcompat-v7:23.1.1',
                    "design"                   : 'com.android.support:design:23.1.1',
                    "cardview-v7"              : 'com.android.support:cardview-v7:23.1.1',
                    "recyclerview-v7"          : 'com.android.support:recyclerview-v7:23.1.1',
                    "multidex"                 : "com.android.support:multidex:1.0.+",
                    "butterknife"              : 'com.jakewharton:butterknife:7.0.1',
                    "volley"                   : 'com.mcxiaoke.volley:library:1.0.19',
                    "okhttp"                   : 'com.squareup.okhttp:okhttp:2.7.0',
                    "okhttp-urlconnection"     : 'com.squareup.okhttp:okhttp-urlconnection:2.7.0',
                    "leakcanary"               : 'com.squareup.leakcanary:leakcanary-android:1.3.1',
                    "glide"                    : 'com.github.bumptech.glide:glide:3.6.1',
                    "glide-okhttp-integration" : 'com.github.bumptech.glide:okhttp-integration:1.3.1',
                    "foldable-layout"          : 'com.alexvasilkov:foldable-layout:1.0.1',
                    "etsy-grid"                : 'com.etsy.android.grid:library:1.0.5']

在工程的build.gradle文件首行设置从哪个gradle文件继承配置(apply from: "config.gradle"

然后在module的build.gradle文件中就可以引用根中的配置了

compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion
    defaultConfig {
        applicationId rootProject.ext.android.applicationId
        minSdkVersion rootProject.ext.android.minSdkVersion
        targetSdkVersion rootProject.ext.android.targetSdkVersion
        versionCode rootProject.ext.android.versionCode
        versionName rootProject.ext.android.versionName
    }

dependencies的配置如下所示:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    compile project(':extras:ShimmerAndroid')
    compile rootProject.ext.dependencies["support-v4"]
    compile rootProject.ext.dependencies["foldable-layout"]
    compile rootProject.ext.dependencies["etsy-grid"]
}

这样如果v4包升级,或者编译版本要提高,只用改动一处即可

 

posted on 2016-04-07 16:35  行殇  阅读(677)  评论(0编辑  收藏  举报

导航