1,在project目录下新建 myConfig.gradle , 里面内容格式如下:
/**
* 项目使用自定义gradle文件来统一管理三方依赖。
*/
ext {
android = [
compileSdkVersion: 30,
buildToolsVersion: "30.0.2",
minSdkVersion : 21,
targetSdkVersion : 30,
versionCode : 1,
versionName : "1.0",
]
version = [
retrofitVersion : '2.8.1',
converterGsonVersion : '2.8.1',
gsonVersion : '2.8.6',
]
lib = [
//网络请求
retrofit : "com.squareup.retrofit2:retrofit:${version.retrofitVersion}",
converterGson : "com.squareup.retrofit2:converter-gson:${version.converterGsonVersion}",
gson : "com.google.code.gson:gson:${version.gsonVersion}",
]
}
2,在project的 build.gradle 添加:
apply from: this.rootProject.file('myConfig.gradle')
3,在 module 的build.gradle 调用:
android {
compileSdkVersion rootProject.android.compileSdkVersion
buildToolsVersion rootProject.android.buildToolsVersion
}
dependencies {
implementation rootProject.lib.retrofit
}