build.gradle 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. apply plugin: 'com.android.application'
  2. def fmodeJpushEnabled = providers.gradleProperty('fmodeJpushEnabled').getOrElse('false').toBoolean()
  3. def fmodeJpushAppKey = providers.environmentVariable('JPUSH_APPKEY').getOrElse('')
  4. // 厂商通道开关(2026-11-21):默认关。开启前必须已打包对应厂商 AAR,否则初始化崩溃。
  5. def fmodeVendorPushEnabled = providers.environmentVariable('FMODE_VENDOR_PUSH').getOrElse('false').toBoolean()
  6. android {
  7. namespace = "cn.fmode.app"
  8. compileSdk = rootProject.ext.compileSdkVersion
  9. /*
  10. * 签名仓库(2026-11-23 补)
  11. *
  12. * 这里只声明「怎么读」,不写死任何口令。
  13. * 没配凭据时 signingConfig 里的字段为 null,下面的 buildTypes 会跳过引用,
  14. * 所以 debug 构建和「只编译不发布」的场景完全不受影响。
  15. */
  16. signingConfigs {
  17. release {
  18. def ksProps = new Properties()
  19. def propsFile = rootProject.file('keystore.properties')
  20. if (propsFile.exists()) {
  21. propsFile.withInputStream { ksProps.load(it) }
  22. }
  23. def pick = { String k, String env ->
  24. System.getenv(env) ?: ksProps.getProperty(k) ?: null
  25. }
  26. def ksPath = pick('storeFile', 'ANDROID_KEYSTORE_PATH')
  27. if (ksPath) storeFile file(ksPath)
  28. storePassword pick('storePassword', 'ANDROID_KEYSTORE_PASSWORD')
  29. keyAlias pick('keyAlias', 'ANDROID_KEY_ALIAS')
  30. keyPassword pick('keyPassword', 'ANDROID_KEY_PASSWORD')
  31. }
  32. }
  33. defaultConfig {
  34. applicationId "cn.fmode.app"
  35. minSdkVersion rootProject.ext.minSdkVersion
  36. targetSdkVersion rootProject.ext.targetSdkVersion
  37. /*
  38. * 版本号(2026-11-23 参数化)
  39. *
  40. * 原来写死 versionCode 1 / versionName "1.0",每发一版都得手改代码,
  41. * 而 app_update 的自动更新完全依赖这两个字段判断「有没有新版」:
  42. * · versionCode 用于比较大小(必须单调递增)
  43. * · versionName 用于展示给用户
  44. *
  45. * 现在支持:
  46. * -PfmodeVersionCode=12 -PfmodeVersionName=1.2.0
  47. * 发布脚本按 App 表里的版本号自动传入,避免手滑改错。
  48. */
  49. versionCode providers.gradleProperty('fmodeVersionCode').getOrElse('1').toInteger()
  50. versionName providers.gradleProperty('fmodeVersionName').getOrElse('1.0')
  51. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  52. buildConfigField 'boolean', 'JPUSH_ENABLED', fmodeJpushEnabled.toString()
  53. // 厂商通道:JPushSdk 读取此值决定 setThirdPushEnable(true/false)
  54. buildConfigField 'boolean', 'JPUSH_VENDOR_ENABLED', (fmodeJpushEnabled && fmodeVendorPushEnabled).toString()
  55. /*
  56. * 厂商通道占位符:必须**始终有值**,否则 Manifest 里的 ${...} 解析失败。
  57. * 未开启厂商通道时填空串 —— 极光 SDK 见到空值会跳过该厂商,
  58. * 不会因为占位符缺失而崩溃。
  59. */
  60. manifestPlaceholders += [
  61. JPUSH_XIAOMI_APPID : providers.environmentVariable('XIAOMI_APPID').getOrElse(''),
  62. JPUSH_XIAOMI_APPKEY : providers.environmentVariable('XIAOMI_APPKEY').getOrElse(''),
  63. JPUSH_HUAWEI_APPID : providers.environmentVariable('HUAWEI_APPID').getOrElse(''),
  64. JPUSH_OPPO_APPKEY : providers.environmentVariable('OPPO_APPKEY').getOrElse(''),
  65. JPUSH_OPPO_APPID : providers.environmentVariable('OPPO_APPID').getOrElse(''),
  66. JPUSH_OPPO_APPSECRET : providers.environmentVariable('OPPO_APPSECRET').getOrElse(''),
  67. JPUSH_VIVO_APPKEY : providers.environmentVariable('VIVO_APPKEY').getOrElse(''),
  68. JPUSH_VIVO_APPID : providers.environmentVariable('VIVO_APPID').getOrElse(''),
  69. JPUSH_HONOR_APPID : providers.environmentVariable('HONOR_APPID').getOrElse(''),
  70. ]
  71. manifestPlaceholders += [JPUSH_APPKEY: fmodeJpushAppKey, JPUSH_CHANNEL: 'fmode', JPUSH_ENABLED: fmodeJpushEnabled.toString()]
  72. aaptOptions {
  73. // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
  74. // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
  75. ignoreAssetsPattern = '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
  76. }
  77. }
  78. buildFeatures {
  79. buildConfig = true
  80. }
  81. if (!fmodeJpushEnabled) {
  82. sourceSets.main.java {
  83. exclude '**/JPushSdk.java', '**/JPushReceiver.java', '**/JPushService.java', '**/JPushClickActivity.java'
  84. }
  85. }
  86. if (fmodeJpushEnabled && file('src/jpush/AndroidManifest.xml').exists()) {
  87. sourceSets.debug.manifest.srcFile 'src/jpush/AndroidManifest.xml'
  88. sourceSets.release.manifest.srcFile 'src/jpush/AndroidManifest.xml'
  89. }
  90. buildTypes {
  91. release {
  92. minifyEnabled false
  93. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  94. /*
  95. * 签名配置(2026-11-23 补)
  96. *
  97. * 原来 release 没有任何 signingConfig → 打出来是 unsigned APK,
  98. * 手机上根本装不上。补上 keystore 支持:
  99. *
  100. * 凭据**全部走环境变量/本地 properties,绝不入库**:
  101. * ANDROID_KEYSTORE_PATH keystore 绝对路径
  102. * ANDROID_KEYSTORE_PASSWORD 仓库口令
  103. * ANDROID_KEY_ALIAS 别名
  104. * ANDROID_KEY_PASSWORD 别名口令
  105. *
  106. * 也可以放 android/keystore.properties(已 gitignore),四行同名 key。
  107. *
  108. * ⚠️ 变量缺失时**不报错**,只跳过签名 —— 保证 `assembleDebug`、
  109. * CI 上只跑检查的场景不会因为没配签名而整体失败。
  110. */
  111. def ksFile = null
  112. def ksProps = new Properties()
  113. def propsFile = rootProject.file('keystore.properties')
  114. if (propsFile.exists()) {
  115. propsFile.withInputStream { ksProps.load(it) }
  116. }
  117. def pick = { String k, String env ->
  118. System.getenv(env) ?: ksProps.getProperty(k) ?: null
  119. }
  120. def ksPath = pick('storeFile', 'ANDROID_KEYSTORE_PATH')
  121. if (ksPath) {
  122. def f = new File(ksPath)
  123. if (f.exists()) ksFile = f
  124. }
  125. if (ksFile != null) {
  126. signingConfig signingConfigs.release
  127. }
  128. }
  129. }
  130. }
  131. repositories {
  132. if (fmodeJpushEnabled) {
  133. maven {
  134. url 'https://maven.jiguang.cn/nexus/content/repositories/releases/'
  135. content { includeGroup 'cn.jiguang.sdk' }
  136. }
  137. }
  138. flatDir{
  139. dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
  140. }
  141. }
  142. dependencies {
  143. if (fmodeJpushEnabled) {
  144. implementation('cn.jiguang.sdk:jpush:6.3.1') {
  145. exclude group: 'cn.jiguang.sdk', module: 'jcore'
  146. }
  147. implementation 'cn.jiguang.sdk:jcore:5.6.0'
  148. }
  149. implementation fileTree(include: ['*.jar'], dir: 'libs')
  150. implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
  151. implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
  152. implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
  153. implementation project(':capacitor-android')
  154. testImplementation "junit:junit:$junitVersion"
  155. androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
  156. androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
  157. implementation project(':capacitor-cordova-android-plugins')
  158. }
  159. apply from: 'capacitor.build.gradle'
  160. try {
  161. def servicesJSON = file('google-services.json')
  162. if (servicesJSON.text) {
  163. apply plugin: 'com.google.gms.google-services'
  164. }
  165. } catch(Exception e) {
  166. logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
  167. }