Android config.gradle

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

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

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


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"
如图

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'
    }





阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页