前言
因為現在專案都比較模塊化,組件化,要用到的model比較多,一個model就有一個build.gradle檔案,里面都有compileSdkVersion或buildToolsVersion等可能出現版本不一致導致編譯出現錯誤,所以要做一個版本統一管理
專案新建以.gradle檔案
我這里創建的是versions.gradle

然后在里面寫你對應的版本號
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"]}"
]
}
使用方法
在你的根目錄build.gradle下初始化

這個名字一定是你創建的名字
最后
在子目錄的build.gradle中寫入

這里是依賴的用法

以上是我自己的一套方案,希望大家多多支持
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/271393.html
標籤:其他
上一篇:程式員中年了40歲,公司里熬到中層年薪30w+,突然接到被辭退訊息,應該怎么辦?
下一篇:CodeCraft-21 and Codeforces Round #711 (Div. 2) D. Bananas in a Microwave 優化暴力
