You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 8.6KB

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