forked from getActivity/AndroidProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
216 lines (182 loc) · 8.58 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
apply plugin : 'com.android.application'
apply plugin : 'android-aspectjx'
apply from : '../common.gradle'
// Android 代码规范文档:https://github.com/getActivity/AndroidCodeStandard
android {
// 资源目录存放指引:https://developer.android.google.cn/guide/topics/resources/providing-resources
defaultConfig {
// 无痛修改包名:https://www.jianshu.com/p/17327e191d2e
applicationId 'com.hjq.demo'
// 仅保留中文语种的资源
resConfigs 'zh'
// 仅保留 xxhdpi 图片资源(目前主流分辨率 1920 * 1080)
resConfigs 'xxhdpi'
// 混淆配置
proguardFiles 'proguard-sdk.pro', 'proguard-app.pro'
// 日志打印开关
buildConfigField('boolean', 'LOG_ENABLE', '' + LOG_ENABLE + '')
// 测试包下的 BuglyId
buildConfigField('String', 'BUGLY_ID', '"' + BUGLY_ID + '"')
// 测试服务器的主机地址
buildConfigField('String', 'HOST_URL', '"' + HOST_URL + '"')
}
// Apk 签名的那些事:https://www.jianshu.com/p/a1f8e5896aa2
signingConfigs {
config {
storeFile file(StoreFile)
storePassword StorePassword
keyAlias KeyAlias
keyPassword KeyPassword
}
}
// 构建配置:https://developer.android.google.cn/studio/build/build-variants
buildTypes {
debug {
// 给包名添加后缀
applicationIdSuffix '.debug'
// 调试模式开关
debuggable true
jniDebuggable true
// 压缩对齐开关
zipAlignEnabled false
// 移除无用的资源
shrinkResources false
// 代码混淆开关
minifyEnabled false
// 签名信息配置
signingConfig signingConfigs.config
// 添加清单占位符
addManifestPlaceholders([
'app_name' : '安卓技术中台 Debug 版'
])
// 调试模式下只保留一种架构的 so 库,提升打包速度
ndk {
abiFilters 'armeabi-v7a'
}
}
preview.initWith(debug)
preview {
applicationIdSuffix ''
// 添加清单占位符
addManifestPlaceholders([
'app_name' : '安卓技术中台 Preview 版'
])
}
release {
// 调试模式开关
debuggable false
jniDebuggable false
// 压缩对齐开关
zipAlignEnabled true
// 移除无用的资源
shrinkResources true
// 代码混淆开关
minifyEnabled true
// 签名信息配置
signingConfig signingConfigs.config
// 添加清单占位符
addManifestPlaceholders([
'app_name' : '@string/app_name'
])
// 仅保留两种架构的 so 库,根据 Bugly 统计得出
ndk {
// armeabi:万金油架构平台(占用率:0%)
// armeabi-v7a:曾经主流的架构平台(占用率:10%)
// arm64-v8a:目前主流架构平台(占用率:95%)
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
}
packagingOptions {
// 剔除这个包下的所有文件(不会移除签名信息)
exclude 'META-INF/*******'
}
// AOP 配置(exclude 和 include 二选一)
// 需要进行配置,否则就会引发冲突,具体表现为:
// 第一种:编译不过去,报错:java.util.zip.ZipException:Cause: zip file is empty
// 第二种:编译能过去,但运行时报错:ClassNotFoundException: Didn't find class on path: DexPathList
aspectjx {
// 排除一些第三方库的包名(Gson、 LeakCanary 和 AOP 有冲突)
// exclude 'androidx', 'com.google', 'com.squareup', 'org.apache', 'com.alipay', 'com.taobao', 'versions.9'
// 只对以下包名做 AOP 处理
include android.defaultConfig.applicationId
}
applicationVariants.all { variant ->
// apk 输出文件名配置
variant.outputs.all { output ->
outputFileName = rootProject.getName() + '_v' + variant.versionName + '_' + variant.buildType.name
if (variant.buildType.name == buildTypes.release.getName()) {
outputFileName += '_' + new Date().format('MMdd')
}
outputFileName += '.apk'
}
}
}
// 添加构建依赖项:https://developer.android.google.cn/studio/build/dependencies
// api 与 implementation 的区别:https://www.jianshu.com/p/8962d6ba936e
dependencies {
// 基类封装
implementation project(':library:base')
// 控件封装
implementation project(':library:widget')
// 友盟封装
implementation project(':library:umeng')
// 权限请求框架:https://github.com/getActivity/XXPermissions
implementation 'com.github.getActivity:XXPermissions:12.3'
// 标题栏框架:https://github.com/getActivity/TitleBar
implementation 'com.github.getActivity:TitleBar:9.2'
// 吐司框架:https://github.com/getActivity/ToastUtils
implementation 'com.github.getActivity:ToastUtils:9.5'
// 网络请求框架:https://github.com/getActivity/EasyHttp
implementation 'com.github.getActivity:EasyHttp:10.2'
// OkHttp 框架:https://github.com/square/okhttp
// noinspection GradleDependency
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
// Json 解析框架:https://github.com/google/gson
implementation 'com.google.code.gson:gson:2.8.8'
// Gson 解析容错:https://github.com/getActivity/GsonFactory
implementation 'com.github.getActivity:GsonFactory:5.2'
// Shape 框架:https://github.com/getActivity/ShapeView
implementation 'com.github.getActivity:ShapeView:6.0'
// AOP 插件库:https://mvnrepository.com/artifact/org.aspectj/aspectjrt
implementation 'org.aspectj:aspectjrt:1.9.6'
// 图片加载框架:https://github.com/bumptech/glide
// 官方使用文档:https://github.com/Muyangmin/glide-docs-cn
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
// 沉浸式框架:https://github.com/gyf-dev/ImmersionBar
implementation 'com.gyf.immersionbar:immersionbar:3.0.0'
// 手势 ImageView:https://github.com/Baseflow/PhotoView
implementation 'com.github.Baseflow:PhotoView:2.3.0'
// Bugly 异常捕捉:https://bugly.qq.com/docs/user-guide/instruction-manual-android/?v=20190418140644
implementation 'com.tencent.bugly:crashreport:3.4.4'
implementation 'com.tencent.bugly:nativecrashreport:3.9.2'
// 动画解析库:https://github.com/airbnb/lottie-android
// 动画资源:https://lottiefiles.com、https://icons8.com/animated-icons
implementation 'com.airbnb.android:lottie:4.1.0'
// 上拉刷新下拉加载框架:https://github.com/scwang90/SmartRefreshLayout
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.3'
implementation 'com.scwang.smart:refresh-header-material:2.0.3'
// 日志打印框架:https://github.com/JakeWharton/timber
implementation 'com.jakewharton.timber:timber:4.7.1'
// 指示器框架:https://github.com/ongakuer/CircleIndicator
implementation 'me.relex:circleindicator:2.1.6'
// 腾讯 MMKV:https://github.com/Tencent/MMKV
implementation 'com.tencent:mmkv-static:1.2.10'
// 内存泄漏监测框架:https://github.com/square/leakcanary
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
previewImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
// 多语种:https://github.com/getActivity/MultiLanguages
// 悬浮窗:https://github.com/getActivity/XToast
// 日志输出:https://github.com/getActivity/Logcat
// 工具类:https://github.com/Blankj/AndroidUtilCode
// 轮播图:https://github.com/bingoogolapple/BGABanner-Android
// 二维码:https://github.com/bingoogolapple/BGAQRCode-Android
// 跑马灯:https://github.com/sunfusheng/MarqueeView
// 对象注解:https://www.jianshu.com/p/f1f888e4a35f
// 对象存储:https://github.com/leavesC/DoKV
// 多渠道打包:https://github.com/Meituan-Dianping/walle
// 设备唯一标识:http://msa-alliance.cn/col.jsp?id=120
// 嵌套滚动容器:https://github.com/donkingliang/ConsecutiveScroller
// 隐私调用监控:https://github.com/huage2580/PermissionMonitor
}