Unified management of Android version

Preface

Because the projects are now more modular and componentized, there are more models to be used, and a model has a build.gradle file, which contains compileSdkVersion or buildToolsVersion. Inconsistent versions may cause compilation errors, so make a version Unified management

Create a new project with a .gradle file

What I created here is versions.gradle
Insert picture description here

Then write your corresponding version number in it

ext {

    android = [
            compileSdkVersion        : 29,
            buildToolsVersion        : "29.0.3",
            minSdkVersion            : 23,
            targetSdkVersion         : 29,
            versionCode              : 1,
            versionName              : "1.0.0",
            applicationId            : "com.team.demo",
            testInstrumentationRunner: "androidx.test.runner.AndroidJUnitRunner"
    ]
    version = [
            appcompat_version          : "1.2.0",
            material_version           : "1.2.1",
            constraintlayout_version   : "2.0.4",
            junit_version              : "4.+",
            ext_junit_version          : "1.1.2",
            espresso_version           : "3.3.0",
            glide_version              : "4.9.0",
            fastjson_version           : "1.2.59",
            lib_dialog_version         : "1.1.0",
            eventbus_version           : "3.0.0",
            rxjava                     : "1.1.0",

            butterknife_version        : "10.1.0",
            compiler_version           : "10.1.0",
            SmartRefreshLayout_version : "1.0.3",
            SmartRefreshHeader_version : "1.0.3",
            butterknife_compile_version: "10.1.0",
            legacy_support_v4_version  : "1.0.0"
    ]

    dependencies = [
            appcompat         : "androidx.appcompat:appcompat:${version["appcompat_version"]}",
            material          : "com.google.android.material:material:${version["material_version"]}",
            constraintlayout  : "androidx.constraintlayout:constraintlayout:${version["constraintlayout_version"]}",
            glide             : "com.github.bumptech.glide:glide:${version["glide_version"]}",
            fastjson          : "com.alibaba:fastjson:${version["fastjson_version"]}",
            lib_dialog        : "com.ninetripods:lib-dialog:${version["lib_dialog_version"]}",
            eventbus          : "org.greenrobot:eventbus:${version["eventbus_version"]}",
            rxjava            : "io.reactivex:rxjava:${version["rxjava"]}",

            butterknife       : "com.jakewharton:butterknife:${version["butterknife_version"]}",
            SmartRefreshLayout: "com.scwang.smartrefresh:SmartRefreshLayout:${version["SmartRefreshLayout_version"]}",
            SmartRefreshHeader: "com.scwang.smartrefresh:SmartRefreshHeader:${version["SmartRefreshHeader_version"]}",
            legacy_support_v4 : "androidx.legacy:legacy-support-v4:${version["legacy_support_v4_version"]}"
    ]

    androidTestImplementations = [
            espresso: "androidx.test.espresso:espresso:${version["espresso_version"]}",
            junit   : "androidx.test.ext:junit:${version["ext_junit_version"]}"
    ]

    testImplementationExcludes = [
            junit: "junit:junit:${version["junit_version"]}"
    ]
}

Instructions

Initialize in your root directory build.gradle.
Insert picture description here
This name must be the name you created

At last

Write in the build.gradle of the subdirectory.
Insert picture description here
Here is the usage of the dependency. The
Insert picture description here
above is my own set of solutions. I hope you can support me

Guess you like

Origin blog.csdn.net/weixin_44357587/article/details/115352939