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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013867301/article/details/52837785

单独建立一个: 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},不是很理解后面的方式

猜你喜欢

转载自blog.csdn.net/u013867301/article/details/52837785
今日推荐