Gradle统一版本配置

增加 config.gradle

ext {
    //android开发版本配置
    androidConfig = [
            compileSdkVersion: 30,
            buildToolsVersion: "30.0.3",
            applicationId    : "com.thorn.gradleconfig",
            minSdkVersion    : 23,
            targetSdkVersion : 30,
            versionCode      : 1,
            versionName      : "V0.0.1",
    ]
    //version配置
    versions = [
            "support-version"             : "28.0.0",
            "junit-version"               : "4.12",
            "junitInstrumentation-version": "1.1.1",
            "espresso-version"            : "3.2.0",
            "material-version"            : "1.1.0",
    ]
    //support配置
    support = [
            "constraint_layout"       : "com.android.support.constraint:constraint-layout:2.0.0-alpha1",
            'support_v4'              : "com.android.support:support-v4:${versions["support-version"]}",
            'appcompat_v7'            : "com.android.support:appcompat-v7:${versions["support-version"]}",
            'recyclerview_v7'         : "com.android.support:recyclerview-v7:${versions["support-version"]}",
            'support_v13'             : "com.android.support:support-v13:${versions["support-version"]}",
            'support_fragment'        : "com.android.support:support-fragment:${versions["support-version"]}",
            'cardview_v7'             : "com.android.support:cardview-v7:${versions["support-version"]}",
            'design'                  : "com.android.support:design:${versions["support-version"]}",
            'animated-vector-drawable': "com.android.support:animated-vector-drawable:${versions["support-version"]}",
            'junit'                   : "junit:junit:${versions["junit-version"]}",
            'junitInstrumentation'    : "androidx.test.ext:junit:${versions["junitInstrumentation-version"]}",
            'espresso'                : "androidx.test.espresso:espresso-core:${versions["espresso-version"]}",
            'material'                : "com.google.android.material:material:${versions["material-version"]}",
    ]
    //依赖第三方配置
    dependencies = [
            "arouter"                              : "com.alibaba:arouter-api:1.5.1",
            "compiler"                             : "com.alibaba:arouter-compiler:1.5.1",
            //rxjava
            "rxjava"                               : "io.reactivex.rxjava2:rxjava:2.1.1",
            "rxandroid"                            : "io.reactivex.rxjava2:rxandroid:2.0.1",
            //rx系列与View生命周期同步
            "rxlifecycle"                          : "com.trello.rxlifecycle2:rxlifecycle:2.2.2",
            "rxlifecycle-components"               : "com.trello.rxlifecycle2:rxlifecycle-components:2.2.2",
            //rxbinding
            "rxbinding"                            : "com.jakewharton.rxbinding2:rxbinding:2.1.1",
            //rx 6.0权限请求
            "rxpermissions"                        : "com.github.tbruyelle:rxpermissions:0.10.2",
            //network
            "okhttp"                               : "com.squareup.okhttp3:okhttp:3.14.0",
            "retrofit"                             : "com.squareup.retrofit2:retrofit:2.4.0",
            "converter-gson"                       : "com.squareup.retrofit2:converter-gson:2.4.0",
            "adapter-rxjava"                       : "com.squareup.retrofit2:adapter-rxjava2:2.4.0",
            //glide图片加载
            "glide"                                : "com.github.bumptech.glide:glide:4.8.0",
            "glide_compiler"                       : "com.github.bumptech.glide:compiler:4.8.0",
            //json解析
            "gson"                                 : "com.google.code.gson:gson:2.8.5",
            //material-dialogs
            "material-dialogs-core"                : "com.afollestad.material-dialogs:core:0.9.4.5",
            "material-dialogs-commons"             : "com.afollestad.material-dialogs:commons:0.9.4.5",
            //recyclerview的databinding套装
            "bindingcollectionadapter"             : "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:2.2.0",
            "bindingcollectionadapter-recyclerview": "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:2.2.0",
            //Google AAC
            "lifecycle-extensions"                 : "android.arch.lifecycle:extensions:1.1.1",
            "lifecycle-compiler"                   : "android.arch.lifecycle:compiler:1.1.1",
            "fastjson"                             : "com.alibaba:fastjson:1.2.67",
            "greendao"                             : "org.greenrobot:greendao:3.2.2",
    ]
}

项目级 build.gradle中增加引用 config.gradle

apply from: 'config.gradle'

替换app级别build.gradle版本引用

比如:compileSdkVersion 30 修改为:compileSdkVersion rootProject.ext.androidConfig.compileSdkVersion

整体替换代码如下:

plugins {
    id 'com.android.application'
}
android {
    compileSdkVersion rootProject.ext.androidConfig.compileSdkVersion
    buildToolsVersion rootProject.ext.androidConfig.buildToolsVersion

    defaultConfig {
        applicationId rootProject.ext.androidConfig.applicationId
        minSdkVersion rootProject.ext.androidConfig.minSdkVersion
        targetSdkVersion rootProject.ext.androidConfig.targetSdkVersion
        versionCode rootProject.ext.androidConfig.versionCode
        versionName rootProject.ext.androidConfig.versionName

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation rootProject.ext.support.appcompat_v7
    implementation rootProject.ext.support.support_v4
    implementation rootProject.ext.support.material
    implementation rootProject.ext.support.constraint_layout
    testImplementation rootProject.ext.support.junit
    androidTestImplementation rootProject.ext.support.junitInstrumentation
    androidTestImplementation rootProject.ext.support.espresso
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值