build.gradle 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. plugins {
  2. alias(libs.plugins.android.application)
  3. alias(libs.plugins.kotlin.android)
  4. alias(libs.plugins.kotlin.compose)
  5. id("kotlin-kapt")
  6. }
  7. android {
  8. namespace 'com.narutohuo.xindazhou'
  9. compileSdk {
  10. version = release(36)
  11. }
  12. defaultConfig {
  13. applicationId "com.dongqingkuaidiandian.chat"
  14. minSdk 26
  15. targetSdk 36
  16. versionCode 1
  17. versionName "1.0"
  18. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  19. // 注意:所有配置都在各自的模块的 strings.xml 中管理
  20. // app 模块:只管理 app 模块自己的配置
  21. // capability-push 模块:极光推送和厂商通道配置都在 capability-push/src/main/res/values/strings.xml
  22. // capability-share 模块:分享配置在 capability-share/src/main/res/values/strings.xml
  23. // 所有配置都在各自模块的 AndroidManifest.xml 中使用 @string/ 引用,完全不需要 manifestPlaceholders
  24. }
  25. // 原来的 buildTypes 配置(已注释,保留作为参考)
  26. // buildTypes {
  27. // release {
  28. // minifyEnabled false
  29. // proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  30. // }
  31. // }
  32. // 签名配置
  33. signingConfigs {
  34. release {
  35. storeFile file('../jks/dongqingkuaidiandian.jks') // 你的发布用keystore
  36. storePassword 'dongqingkuaidiandianq29018'
  37. keyAlias 'dongqingkuaidiandianqalias'
  38. keyPassword 'dongqingkuaidiandianq29018'
  39. v1SigningEnabled true
  40. v2SigningEnabled true
  41. }
  42. }
  43. // 新的 buildTypes 配置(带签名)
  44. buildTypes {
  45. release {
  46. minifyEnabled false
  47. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  48. signingConfig signingConfigs.release // 使用 release 签名配置
  49. }
  50. debug {
  51. // Debug 也使用 release 签名,确保分享功能正常(微信需要正确的签名)
  52. signingConfig signingConfigs.release
  53. }
  54. }
  55. compileOptions {
  56. sourceCompatibility JavaVersion.VERSION_17
  57. targetCompatibility JavaVersion.VERSION_17
  58. }
  59. kotlinOptions {
  60. jvmTarget = '17'
  61. }
  62. buildFeatures {
  63. compose true
  64. viewBinding true
  65. buildConfig true // 启用 BuildConfig 生成
  66. }
  67. // ARouter 配置(Kotlin 方式)
  68. kapt {
  69. arguments {
  70. arg("AROUTER_MODULE_NAME", project.getName())
  71. }
  72. }
  73. // 解决资源合并冲突
  74. packaging {
  75. resources {
  76. excludes += ['META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version']
  77. excludes += ['META-INF/DEPENDENCIES']
  78. excludes += ['META-INF/LICENSE']
  79. excludes += ['META-INF/LICENSE.txt']
  80. excludes += ['META-INF/license.txt']
  81. excludes += ['META-INF/NOTICE']
  82. excludes += ['META-INF/NOTICE.txt']
  83. excludes += ['META-INF/notice.txt']
  84. excludes += ['META-INF/ASL2.0']
  85. // 排除未对齐的 x86_64 库(解决 16 KB alignment 警告)
  86. // 只影响 x86_64 模拟器,不影响 ARM 设备(荣耀300等所有真实手机)
  87. excludes += ['assets/libwbsafeedit_x86_64']
  88. excludes += ['assets/libwbsafeedit_x86'] // 也排除 x86 版本(未对齐)
  89. }
  90. // 启用 16 KB 页大小对齐(解决 16 KB alignment 警告)
  91. // 自动对齐原生库(.so 文件),确保兼容 16 KB 页大小的设备
  92. jniLibs {
  93. useLegacyPackaging = false
  94. }
  95. }
  96. }
  97. // 全局排除旧的 support 库,避免与 AndroidX 冲突
  98. configurations.all {
  99. exclude group: 'com.android.support'
  100. }
  101. dependencies {
  102. // 基础模块
  103. // 注意:app 模块不直接依赖 base-core,通过 base-common 间接获得
  104. implementation project(':base-common')
  105. // ============================================================================
  106. // ⚠️⚠️⚠️ 严禁直接依赖能力层里面的具体库 ⚠️⚠️⚠️
  107. // ============================================================================
  108. //
  109. // ❌ 禁止在 app 模块中直接依赖能力层使用的第三方 SDK,例如:
  110. // ❌ implementation 'com.tencent.mm.opensdk:wechat-sdk-android:6.8.24' // 微信 SDK
  111. // ❌ implementation 'cn.jiguang.sdk:jpush:5.9.0' // 极光推送 SDK
  112. // ❌ implementation 'com.umeng.umsdk:share-core:7.3.2' // 友盟分享 SDK
  113. // ❌ implementation files('libs/xxx.jar') // 能力层的 JAR/AAR 文件
  114. //
  115. // ✅ 正确做法:只依赖能力模块本身,能力模块会通过 api 传递必要的依赖
  116. // ✅ implementation project(':capability-share') // 只依赖模块
  117. // ✅ implementation project(':capability-push') // 只依赖模块
  118. //
  119. // 📋 原因:
  120. // 1. 每个能力模块管理自己的依赖,app 模块只负责组装
  121. // 2. 能力模块通过 api 传递必要的依赖,app 模块会自动获得
  122. // 3. 直接依赖会导致版本冲突、重复依赖等问题
  123. // 4. 违反模块化原则,增加维护成本
  124. //
  125. // ============================================================================
  126. // SDK模块(能力层)- 只依赖模块本身,不要依赖模块内部的库!
  127. implementation project(':capability-ble')
  128. implementation project(':capability-socketio')
  129. implementation project(':capability-push')
  130. implementation project(':capability-qrcode')
  131. implementation project(':capability-share')
  132. implementation project(':capability-nfc')
  133. // 业务模块代码已迁移到 app 模块内,不再需要独立的 module-* 依赖
  134. // AndroidX Core
  135. implementation libs.androidx.core.ktx
  136. implementation 'androidx.appcompat:appcompat:1.6.1'
  137. implementation 'com.google.android.material:material:1.11.0'
  138. implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
  139. implementation 'androidx.cardview:cardview:1.0.0'
  140. implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
  141. // ViewModel & LiveData & StateFlow
  142. implementation libs.androidx.lifecycle.runtime.ktx
  143. implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0'
  144. implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.7.0'
  145. implementation 'androidx.lifecycle:lifecycle-process:2.7.0' // ProcessLifecycleOwner(监听 App 前后台切换)
  146. // Navigation
  147. implementation 'androidx.navigation:navigation-fragment-ktx:2.7.6'
  148. implementation 'androidx.navigation:navigation-ui-ktx:2.7.6'
  149. // 注意:基础第三方库(Retrofit、OkHttp、Gson、Glide、Coroutines)
  150. // 已通过 base-common 间接获得(base-common → base-core),不需要直接依赖
  151. // Room
  152. implementation 'androidx.room:room-runtime:2.6.1'
  153. implementation 'androidx.room:room-ktx:2.6.1'
  154. annotationProcessor 'androidx.room:room-compiler:2.6.1'
  155. // Compose
  156. implementation libs.androidx.activity.compose
  157. implementation platform(libs.androidx.compose.bom)
  158. implementation libs.androidx.compose.ui
  159. implementation libs.androidx.compose.ui.graphics
  160. implementation libs.androidx.compose.ui.tooling.preview
  161. implementation libs.androidx.compose.material3
  162. // LogcatViewer 依赖已移至 base-core 模块,通过 ILog 统一管理
  163. // ARouter 编译器(用于生成路由代码)
  164. kapt 'com.alibaba:arouter-compiler:1.5.2'
  165. // Google Play Services Location (用于定位功能)
  166. implementation 'com.google.android.gms:play-services-location:21.0.1'
  167. // Testing
  168. testImplementation libs.junit
  169. androidTestImplementation libs.androidx.junit
  170. androidTestImplementation libs.androidx.espresso.core
  171. androidTestImplementation platform(libs.androidx.compose.bom)
  172. androidTestImplementation libs.androidx.compose.ui.test.junit4
  173. debugImplementation libs.androidx.compose.ui.tooling
  174. debugImplementation libs.androidx.compose.ui.test.manifest
  175. }