Android--抽取Module Gradle中的版本号

单独建立一个: dependencies.gradle

ext {
    //Android sdk
    androidBuildToolsVersion = "25.0.2"
    androidMinSdkVersion = 19
    androidTargetSdkVersion = 25
    androidCompileSdkVersion = 25
    //Android lib
    supportAppCompatVersion = "25.3.1"
    supportConstraintLayoutVersion = "1.0.2"
    //test
    espressoCoreVersion = "2.2.2"
    junitVersion = "4.12"
    //other lib
    orhanobutLoggerVersion = "1.15"

    mainDependencies = [

            orhanobutLogger : "com.orhanobut:logger:${orhanobutLoggerVersion}",

            espresso        : "com.android.support.test.espresso:espresso-core:${espressoCoreVersion}",
    ]
}

然后在project的build.gradle中加一行:

//相对路径
apply from: 'dependencies.gradle'

就可以使用了:

def mD = rootProject.ext.mainDependencies;

compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile(mD.espresso, {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile mD.appcompat

问题:

看google的android-architecture中的todo-mvp。

compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"

部分使用rootProject.ext.{value},部分使用rootProject.{value},不是很理解后面的方式

你可能感兴趣的:(Android--抽取Module Gradle中的版本号)