Android config.gradle

对版本以及依赖控件版本进行统一管理:

1、创建config.gradle放在项目跟目录

Android config.gradle_第1张图片

ext{
    android=[

            compileSdkVersion       : 27,
            buildToolsVersion       : "27.0.3",
            minSdkVersion           : 15,
            targetSdkVersion        : 27,
            versionCode      : 1,
            versionName     : "1.0"
    ]
    versions = [
            retrofitSdkVersion      : "2.3.0",
    ]
    dependencies=[
            //support
            "constraint-layout":"com.android.support.constraint:constraint-layout:1.0.2",
            "appcompat-v7":"com.android.support:appcompat-v7:26.1.0",
            //net
            "retrofit":"com.squareup.retrofit2:retrofit:${version["retrofitSdkVersion"]}",
            "retrofit-converter-gson"  : "com.squareup.retrofit2:converter-gson:${version["retrofitSdkVersion"]}",
            "retrofit-converter-scalars"  : "com.squareup.retrofit2:converter-scalars:${version["retrofitSdkVersion"]}",
    ]

}
2、在project的build.gradle添加
apply from:"config.gradle"
如图

Android config.gradle_第2张图片

3、在app的gradle中添加config.gradle中的依赖

compileSdkVersion rootProject.ext.android['compileSdkVersion']
    buildToolsVersion rootProject.ext.android['buildToolsVersion']
    defaultConfig {
        applicationId "com.flyfish.df.dfhttp"
        minSdkVersion rootProject.ext.android.minSdkVersion
        targetSdkVersion rootProject.ext.android.targetSdkVersion
        versionCode rootProject.ext.android.versionCode
        versionName rootProject.ext.android.versionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    
 //添加依赖
    implementation rootProject.ext.dependencies["appcompat-v7"]
    //添加retrofit
    implementation rootProject.ext.dependencies["retrofit"]
    implementation rootProject.ext.dependencies["retrofit-converter-gson"]
    implementation rootProject.ext.dependencies["retrofit-converter-scalars"]
    implementation rootProject.ext.dependencies["retrofit-adapter-rxjava2"]

    implementation rootProject.ext.dependencies["butterknife"]
    annotationProcessor(rootProject.ext.dependencies["butterknife-compiler"]) {
        exclude module: 'support-annotations'
    }





你可能感兴趣的:(Android)