build.gradle 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. defaultConfig {
  10. applicationId "cn.fmode.app"
  11. minSdkVersion rootProject.ext.minSdkVersion
  12. targetSdkVersion rootProject.ext.targetSdkVersion
  13. versionCode 1
  14. versionName "1.0"
  15. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  16. buildConfigField 'boolean', 'JPUSH_ENABLED', fmodeJpushEnabled.toString()
  17. // 厂商通道:JPushSdk 读取此值决定 setThirdPushEnable(true/false)
  18. buildConfigField 'boolean', 'JPUSH_VENDOR_ENABLED', (fmodeJpushEnabled && fmodeVendorPushEnabled).toString()
  19. /*
  20. * 厂商通道占位符:必须**始终有值**,否则 Manifest 里的 ${...} 解析失败。
  21. * 未开启厂商通道时填空串 —— 极光 SDK 见到空值会跳过该厂商,
  22. * 不会因为占位符缺失而崩溃。
  23. */
  24. manifestPlaceholders += [
  25. JPUSH_XIAOMI_APPID : providers.environmentVariable('XIAOMI_APPID').getOrElse(''),
  26. JPUSH_XIAOMI_APPKEY : providers.environmentVariable('XIAOMI_APPKEY').getOrElse(''),
  27. JPUSH_HUAWEI_APPID : providers.environmentVariable('HUAWEI_APPID').getOrElse(''),
  28. JPUSH_OPPO_APPKEY : providers.environmentVariable('OPPO_APPKEY').getOrElse(''),
  29. JPUSH_OPPO_APPID : providers.environmentVariable('OPPO_APPID').getOrElse(''),
  30. JPUSH_OPPO_APPSECRET : providers.environmentVariable('OPPO_APPSECRET').getOrElse(''),
  31. JPUSH_VIVO_APPKEY : providers.environmentVariable('VIVO_APPKEY').getOrElse(''),
  32. JPUSH_VIVO_APPID : providers.environmentVariable('VIVO_APPID').getOrElse(''),
  33. JPUSH_HONOR_APPID : providers.environmentVariable('HONOR_APPID').getOrElse(''),
  34. ]
  35. manifestPlaceholders += [JPUSH_APPKEY: fmodeJpushAppKey, JPUSH_CHANNEL: 'fmode', JPUSH_ENABLED: fmodeJpushEnabled.toString()]
  36. aaptOptions {
  37. // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
  38. // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
  39. ignoreAssetsPattern = '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
  40. }
  41. }
  42. buildFeatures {
  43. buildConfig = true
  44. }
  45. if (!fmodeJpushEnabled) {
  46. sourceSets.main.java {
  47. exclude '**/JPushSdk.java', '**/JPushReceiver.java', '**/JPushService.java', '**/JPushClickActivity.java'
  48. }
  49. }
  50. if (fmodeJpushEnabled && file('src/jpush/AndroidManifest.xml').exists()) {
  51. sourceSets.debug.manifest.srcFile 'src/jpush/AndroidManifest.xml'
  52. sourceSets.release.manifest.srcFile 'src/jpush/AndroidManifest.xml'
  53. }
  54. buildTypes {
  55. release {
  56. minifyEnabled false
  57. proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  58. }
  59. }
  60. }
  61. repositories {
  62. if (fmodeJpushEnabled) {
  63. maven {
  64. url 'https://maven.jiguang.cn/nexus/content/repositories/releases/'
  65. content { includeGroup 'cn.jiguang.sdk' }
  66. }
  67. }
  68. flatDir{
  69. dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
  70. }
  71. }
  72. dependencies {
  73. if (fmodeJpushEnabled) {
  74. implementation('cn.jiguang.sdk:jpush:6.3.1') {
  75. exclude group: 'cn.jiguang.sdk', module: 'jcore'
  76. }
  77. implementation 'cn.jiguang.sdk:jcore:5.6.0'
  78. }
  79. implementation fileTree(include: ['*.jar'], dir: 'libs')
  80. implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
  81. implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
  82. implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
  83. implementation project(':capacitor-android')
  84. testImplementation "junit:junit:$junitVersion"
  85. androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
  86. androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
  87. implementation project(':capacitor-cordova-android-plugins')
  88. }
  89. apply from: 'capacitor.build.gradle'
  90. try {
  91. def servicesJSON = file('google-services.json')
  92. if (servicesJSON.text) {
  93. apply plugin: 'com.google.gms.google-services'
  94. }
  95. } catch(Exception e) {
  96. logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
  97. }