Skip to content

Commit 7a7f296

Browse files
committed
适配 Gradle 的 Version Catalogs 特性
1 parent 754e461 commit 7a7f296

8 files changed

Lines changed: 199 additions & 92 deletions

File tree

app/build.gradle

Lines changed: 32 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
plugins {
2-
id 'com.android.application'
3-
id 'org.jetbrains.kotlin.android'
4-
id 'android.aop'
5-
id 'com.starter.easylauncher'
2+
alias(libs.plugins.application)
3+
alias(libs.plugins.kotlin)
4+
alias(libs.plugins.aop)
5+
alias(libs.plugins.easylauncher)
66
}
77

88
apply from : '../common.gradle'
@@ -179,86 +179,57 @@ dependencies {
179179
// 友盟封装
180180
implementation project(':library:umeng')
181181

182-
// 设备兼容框架:https://github.com/getActivity/DeviceCompat
183-
implementation 'com.github.getActivity:DeviceCompat:2.5'
184-
// 权限请求框架:https://github.com/getActivity/XXPermissions
185-
implementation 'com.github.getActivity:XXPermissions:28.0'
182+
implementation libs.deviceCompat
183+
implementation libs.xxPermissions
186184

187-
// 标题栏框架:https://github.com/getActivity/TitleBar
188-
implementation 'com.github.getActivity:TitleBar:10.8'
185+
implementation libs.titleBar
189186

190-
// 吐司框架:https://github.com/getActivity/Toaster
191-
implementation 'com.github.getActivity:Toaster:13.8'
187+
implementation libs.toaster
192188

193-
// 网络请求框架:https://github.com/getActivity/EasyHttp
194-
implementation 'com.github.getActivity:EasyHttp:13.0'
195-
// OkHttp 框架:https://github.com/square/okhttp
196-
// noinspection GradleDependency
197-
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
189+
implementation libs.easyHttp
190+
implementation libs.okHttp
198191

199-
// Gson 解析容错:https://github.com/getActivity/GsonFactory
200-
implementation ('com.github.getActivity:GsonFactory:10.3') {
192+
implementation(libs.gsonFactory) {
201193
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-reflect'
202194
}
203-
// Json 解析框架:https://github.com/google/gson
204-
implementation ('com.google.code.gson:gson:2.13.2') {
195+
implementation(libs.gson) {
205196
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
206197
}
207-
// Kotlin 反射库:用于反射 Kotlin data class 类对象
208-
implementation 'org.jetbrains.kotlin:kotlin-reflect:2.2.20'
198+
implementation libs.kotlinReflect
209199

210-
// ShapeView:https://github.com/getActivity/ShapeView
211-
implementation 'com.github.getActivity:ShapeView:10.0'
212-
// ShapeDrawable:https://github.com/getActivity/ShapeDrawable
213-
implementation 'com.github.getActivity:ShapeDrawable:3.3'
200+
implementation libs.shapeView
201+
implementation libs.shapeDrawable
214202

215-
// 嵌套滚动布局:https://github.com/getActivity/NestedScrollLayout
216-
implementation 'com.github.getActivity:NestedScrollLayout:2.0'
203+
implementation libs.nestedScrollLayout
217204

218-
// 图片加载框架:https://github.com/bumptech/glide
219-
// 官方使用文档:https://github.com/Muyangmin/glide-docs-cn
220-
implementation 'com.github.bumptech.glide:glide:5.0.5'
221-
annotationProcessor 'com.github.bumptech.glide:compiler:5.0.5'
205+
implementation libs.glide
206+
annotationProcessor libs.glideCompiler
222207

223-
// 沉浸式框架:https://github.com/gyf-dev/ImmersionBar
224-
implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
208+
implementation libs.immersionBar
225209

226-
// 手势 ImageView:https://github.com/Baseflow/PhotoView
227-
implementation 'com.github.Baseflow:PhotoView:2.3.0'
210+
implementation libs.photoView
228211

229-
// Bugly 异常捕捉:https://bugly.tds.qq.com/docs/sdk/android/
230-
implementation 'com.tencent.bugly_16kb:bugly-pro:4.4.7.3'
212+
implementation libs.buglyPro
231213

232-
// 动画解析库:https://github.com/airbnb/lottie-android
233-
// 动画资源:https://lottiefiles.com、https://icons8.com/animated-icons
234-
implementation 'com.airbnb.android:lottie:6.7.1'
214+
implementation libs.lottie
235215

236-
// 上拉刷新下拉加载框架:https://github.com/scwang90/SmartRefreshLayout
237-
implementation 'io.github.scwang90:refresh-layout-kernel:3.0.0-alpha'
238-
implementation 'io.github.scwang90:refresh-header-material:3.0.0-alpha'
216+
implementation libs.refreshLayoutKernel
217+
implementation libs.refreshHeaderMaterial
239218

240-
// 日志打印框架:https://github.com/JakeWharton/timber
241-
implementation 'com.jakewharton.timber:timber:5.0.1'
219+
implementation libs.timber
242220

243-
// 指示器框架:https://github.com/ongakuer/CircleIndicator
244-
implementation 'me.relex:circleindicator:2.1.6'
221+
implementation libs.circleIndicator
245222

246-
// 腾讯 MMKV:https://github.com/Tencent/MMKV
247-
implementation ('com.tencent:mmkv-static:2.3.0') {
248-
// 避免版本不一致导致的依赖冲突,从而导致编译报错
223+
implementation(libs.mmkvStatic) {
249224
exclude group: 'androidx.annotation', module: 'annotation'
250225
}
251226

252-
// 内存泄漏监测框架:https://github.com/square/leakcanary
253-
debugImplementation 'com.squareup.leakcanary:leakcanary-android:3.0-alpha-8'
254-
previewImplementation 'com.squareup.leakcanary:leakcanary-android:3.0-alpha-8'
227+
implementation libs.softInputEvent
228+
implementation libs.androidAopCore
229+
annotationProcessor libs.androidAopApt
255230

256-
// 软键盘遮挡解决方案:https://github.com/liangjingkanji/soft-input-event
257-
implementation 'com.github.liangjingkanji:soft-input-event:1.0.9'
258-
259-
// Android AOP 框架:https://github.com/FlyJingFish/AndroidAOP
260-
implementation 'io.github.flyjingfish:androidaop-core:2.7.4'
261-
annotationProcessor 'io.github.flyjingfish:androidaop-apt:2.7.4'
231+
debugImplementation libs.leakCanary
232+
previewImplementation libs.leakCanary
262233

263234
// 多语种:https://github.com/getActivity/MultiLanguages
264235
// 悬浮窗:https://github.com/getActivity/EasyWindow

build.gradle

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// AndroidProject 版本:v15.0
22
plugins {
3-
id 'com.android.application' version '8.13.2' apply false
4-
id 'com.android.library' version '8.13.2' apply false
5-
id 'org.jetbrains.kotlin.android' version '2.2.21' apply false
6-
// AOP 插件:https://github.com/FlyJingFish/AndroidAOP
7-
id 'io.github.flyjingfish.androidaop' version '2.7.4' apply false
8-
// 多 buildType 图标插件:https://github.com/usefulness/easylauncher-gradle-plugin
9-
id 'com.starter.easylauncher' version '6.4.1' apply false
3+
alias(libs.plugins.application) apply false
4+
alias(libs.plugins.library) apply false
5+
alias(libs.plugins.kotlin) apply false
6+
alias(libs.plugins.aop) apply false
7+
alias(libs.plugins.easylauncher) apply false
108
}
119

1210
// 导入配置文件

common.gradle

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ android {
3030
// 调试版本
3131
debug {}
3232
// 预览版本
33-
preview {}
33+
preview {
34+
matchingFallbacks = ['debug']
35+
}
3436
// 正式版本
3537
release {}
3638
}
@@ -67,9 +69,6 @@ dependencies {
6769
// 依赖 libs 目录下所有的 jar 和 aar 包
6870
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
6971

70-
// AndroidX 库:https://github.com/androidx/androidx
71-
// 更新日志:https://developer.android.google.cn/jetpack/androidx/releases/appcompat?hl=zh-cn
72-
implementation 'androidx.appcompat:appcompat:1.7.1'
73-
// Material 库:https://github.com/material-components/material-components-android
74-
implementation 'com.google.android.material:material:1.13.0'
72+
implementation libs.appCompat
73+
implementation libs.material
7574
}

gradle/libs.versions.toml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
[versions]
2+
agp = "8.13.2"
3+
kotlin = "2.2.21"
4+
androidAop = "2.7.4"
5+
easyLauncher = "6.4.1"
6+
appCompat = "1.7.1"
7+
material = "1.13.0"
8+
deviceCompat = "2.5"
9+
xxPermissions = "28.0"
10+
titleBar = "10.8"
11+
toaster = "13.8"
12+
easyHttp = "13.0"
13+
okHttp = "3.12.13"
14+
gsonFactory = "10.3"
15+
gson = "2.13.2"
16+
kotlinReflect = "2.2.20"
17+
shapeView = "10.0"
18+
shapeDrawable = "3.3"
19+
nestedScrollLayout = "2.0"
20+
glide = "5.0.5"
21+
immersionBar = "3.2.2"
22+
photoView = "2.3.0"
23+
buglyPro = "4.4.7.3"
24+
lottie = "6.7.1"
25+
refreshAlpha = "3.0.0-alpha"
26+
timber = "5.0.1"
27+
circleIndicator = "2.1.6"
28+
mmkv = "2.3.0"
29+
leakCanary = "3.0-alpha-8"
30+
softInputEvent = "1.0.9"
31+
umengCommon = "9.8.8"
32+
umengAsms = "1.8.7.2"
33+
umengShareCore = "7.3.7"
34+
umengShareWX = "7.3.7"
35+
umengShareQQ = "7.3.7"
36+
qqSdk = "3.5.18.0"
37+
wechatSdk = "6.8.34"
38+
39+
[plugins]
40+
# Android 应用构建插件(AGP):https://developer.android.com/build
41+
application = { id = "com.android.application", version.ref = "agp" }
42+
# Android 库构建插件(AGP Library):https://developer.android.com/build
43+
library = { id = "com.android.library", version.ref = "agp" }
44+
# Kotlin Android 插件:Kotlin 代码与 Android 集成:https://kotlinlang.org/docs/gradle.html
45+
kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
46+
# Android AOP 插件:切面编程框架:https://github.com/FlyJingFish/AndroidAOP
47+
aop = { id = "io.github.flyjingfish.androidaop", version.ref = "androidAop" }
48+
# 多构建类型图标标记插件:在不同 buildType 添加角标:https://github.com/usefulness/easylauncher-gradle-plugin
49+
easylauncher = { id = "com.starter.easylauncher", version.ref = "easyLauncher" }
50+
51+
[libraries]
52+
# AndroidX AppCompat:兼容支持库(ActionBar 等)
53+
# 发布说明:https://developer.android.google.cn/jetpack/androidx/releases/appcompat
54+
appCompat = { module = "androidx.appcompat:appcompat", version.ref = "appCompat" }
55+
# Material 组件库:Material Design 组件
56+
# 项目主页:https://github.com/material-components/material-components-android
57+
material = { module = "com.google.android.material:material", version.ref = "material" }
58+
59+
# 设备兼容框架:统一设备品牌、系统等差异 https://github.com/getActivity/DeviceCompat
60+
deviceCompat = { module = "com.github.getActivity:DeviceCompat", version.ref = "deviceCompat" }
61+
# 权限请求框架:https://github.com/getActivity/XXPermissions
62+
xxPermissions = { module = "com.github.getActivity:XXPermissions", version.ref = "xxPermissions" }
63+
64+
# 标题栏框架:https://github.com/getActivity/TitleBar
65+
titleBar = { module = "com.github.getActivity:TitleBar", version.ref = "titleBar" }
66+
67+
# 吐司框架:https://github.com/getActivity/Toaster
68+
toaster = { module = "com.github.getActivity:Toaster", version.ref = "toaster" }
69+
70+
# 网络请求封装:https://github.com/getActivity/EasyHttp
71+
easyHttp = { module = "com.github.getActivity:EasyHttp", version.ref = "easyHttp" }
72+
73+
# OkHttp 客户端:https://github.com/square/okhttp
74+
okHttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okHttp" }
75+
76+
# Gson 容错工厂:提升解析稳定性 https://github.com/getActivity/GsonFactory
77+
gsonFactory = { module = "com.github.getActivity:GsonFactory", version.ref = "gsonFactory" }
78+
# Gson JSON 解析库:https://github.com/google/gson
79+
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
80+
# Kotlin 反射库:反射 data class 等 https://kotlinlang.org/docs/reflection.html
81+
kotlinReflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlinReflect" }
82+
83+
# ShapeView:形状控件封装 https://github.com/getActivity/ShapeView
84+
shapeView = { module = "com.github.getActivity:ShapeView", version.ref = "shapeView" }
85+
# ShapeDrawable:更灵活的 Shape 绘制 https://github.com/getActivity/ShapeDrawable
86+
shapeDrawable = { module = "com.github.getActivity:ShapeDrawable", version.ref = "shapeDrawable" }
87+
88+
# NestedScrollLayout:嵌套滚动容器 https://github.com/getActivity/NestedScrollLayout
89+
nestedScrollLayout = { module = "com.github.getActivity:NestedScrollLayout", version.ref = "nestedScrollLayout" }
90+
91+
# Glide 图片加载:https://github.com/bumptech/glide
92+
# 中文文档:https://github.com/Muyangmin/glide-docs-cn
93+
glide = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
94+
# Glide 编译期注解处理器
95+
glideCompiler = { module = "com.github.bumptech.glide:compiler", version.ref = "glide" }
96+
97+
# 沉浸式状态栏框架:https://github.com/gyf-dev/ImmersionBar
98+
immersionBar = { module = "com.geyifeng.immersionbar:immersionbar", version.ref = "immersionBar" }
99+
100+
# 手势缩放 ImageView:https://github.com/Baseflow/PhotoView
101+
photoView = { module = "com.github.Baseflow:PhotoView", version.ref = "photoView" }
102+
103+
# Bugly 异常捕捉与上报:https://bugly.tds.qq.com/docs/sdk/android/
104+
buglyPro = { module = "com.tencent.bugly_16kb:bugly-pro", version.ref = "buglyPro" }
105+
106+
# Lottie 动画解析:https://github.com/airbnb/lottie-android
107+
lottie = { module = "com.airbnb.android:lottie", version.ref = "lottie" }
108+
109+
# SmartRefreshLayout 刷新控件:https://github.com/scwang90/SmartRefreshLayout
110+
refreshLayoutKernel = { module = "io.github.scwang90:refresh-layout-kernel", version.ref = "refreshAlpha" }
111+
refreshHeaderMaterial = { module = "io.github.scwang90:refresh-header-material", version.ref = "refreshAlpha" }
112+
113+
# Timber 日志打印:https://github.com/JakeWharton/timber
114+
timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }
115+
116+
# ViewPager 指示器:https://github.com/ongakuer/CircleIndicator
117+
circleIndicator = { module = "me.relex:circleindicator", version.ref = "circleIndicator" }
118+
119+
# 腾讯 MMKV 高性能 Key-Value 存储:https://github.com/Tencent/MMKV
120+
mmkvStatic = { module = "com.tencent:mmkv-static", version.ref = "mmkv" }
121+
122+
# LeakCanary 内存泄漏监测:https://github.com/square/leakcanary
123+
leakCanary = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakCanary" }
124+
125+
# 软键盘遮挡解决方案:https://github.com/liangjingkanji/soft-input-event
126+
softInputEvent = { module = "com.github.liangjingkanji:soft-input-event", version.ref = "softInputEvent" }
127+
128+
# Android AOP 核心与注解处理器:https://github.com/FlyJingFish/AndroidAOP
129+
androidAopCore = { module = "io.github.flyjingfish:androidaop-core", version.ref = "androidAop" }
130+
androidAopApt = { module = "io.github.flyjingfish:androidaop-apt", version.ref = "androidAop" }
131+
132+
# 友盟 SDK:统计 & 分享组件
133+
# 统计文档:https://developer.umeng.com/docs/119267/detail/118584
134+
# 社会化分享文档:https://developer.umeng.com/docs/128606/detail/193879
135+
umengCommon = { module = "com.umeng.umsdk:common", version.ref = "umengCommon" }
136+
umengAsms = { module = "com.umeng.umsdk:asms", version.ref = "umengAsms" }
137+
umengShareCore = { module = "com.umeng.umsdk:share-core", version.ref = "umengShareCore" }
138+
umengShareWX = { module = "com.umeng.umsdk:share-wx", version.ref = "umengShareWX" }
139+
umengShareQQ = { module = "com.umeng.umsdk:share-qq", version.ref = "umengShareQQ" }
140+
141+
# QQ 开放平台组件文档:https://wikinew.open.qq.com/#/iwiki/4007776153
142+
qqSdk = { module = "com.tencent.qq:open-sdk", version.ref = "qqSdk" }
143+
# 微信开放平台组件文档:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/Android.html
144+
wechatSdk = { module = "com.tencent.mm.opensdk:wechat-sdk-android", version.ref = "wechatSdk" }

library/base/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'com.android.library'
2+
alias(libs.plugins.library)
33
}
44
apply from : '../../common.gradle'
55

library/copy/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'com.android.library'
2+
alias(libs.plugins.library)
33
}
44
apply from: '../../common.gradle'
55

library/umeng/build.gradle

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'com.android.library'
2+
alias(libs.plugins.library)
33
}
44
apply from : '../../common.gradle'
55

@@ -37,18 +37,13 @@ android {
3737
// 友盟社会化集成文档:https://developer.umeng.com/docs/128606/detail/193879
3838
// 友盟远程仓库地址:https://repo1.maven.org/maven2
3939
dependencies {
40-
// 友盟公共库
41-
api 'com.umeng.umsdk:common:9.8.8'
42-
api 'com.umeng.umsdk:asms:1.8.7.2'
43-
// 友盟分享库
44-
api 'com.umeng.umsdk:share-core:7.3.7'
45-
// 友盟微信分享
46-
api 'com.umeng.umsdk:share-wx:7.3.7'
47-
// 友盟 QQ 分享
48-
api 'com.umeng.umsdk:share-qq:7.3.7'
49-
50-
// QQ 组件:https://wikinew.open.qq.com/#/iwiki/4007776153
51-
api 'com.tencent.qq:open-sdk:3.5.18.0'
52-
// 微信组件:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/Android.html
53-
api 'com.tencent.mm.opensdk:wechat-sdk-android:6.8.34'
40+
api libs.umengCommon
41+
api libs.umengAsms
42+
43+
api libs.umengShareCore
44+
api libs.umengShareWX
45+
api libs.umengShareQQ
46+
47+
api libs.qqSdk
48+
api libs.wechatSdk
5449
}

library/widget/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'com.android.library'
2+
alias(libs.plugins.library)
33
}
44
apply from : '../../common.gradle'
55

0 commit comments

Comments
 (0)