apply plugin: 'com.android.application' def fmodeJpushEnabled = providers.gradleProperty('fmodeJpushEnabled').getOrElse('false').toBoolean() def fmodeJpushAppKey = providers.environmentVariable('JPUSH_APPKEY').getOrElse('') // 厂商通道开关(2026-11-21):默认关。开启前必须已打包对应厂商 AAR,否则初始化崩溃。 def fmodeVendorPushEnabled = providers.environmentVariable('FMODE_VENDOR_PUSH').getOrElse('false').toBoolean() android { namespace = "cn.fmode.app" compileSdk = rootProject.ext.compileSdkVersion /* * 签名仓库(2026-11-23 补) * * 这里只声明「怎么读」,不写死任何口令。 * 没配凭据时 signingConfig 里的字段为 null,下面的 buildTypes 会跳过引用, * 所以 debug 构建和「只编译不发布」的场景完全不受影响。 */ signingConfigs { release { def ksProps = new Properties() def propsFile = rootProject.file('keystore.properties') if (propsFile.exists()) { propsFile.withInputStream { ksProps.load(it) } } def pick = { String k, String env -> System.getenv(env) ?: ksProps.getProperty(k) ?: null } def ksPath = pick('storeFile', 'ANDROID_KEYSTORE_PATH') if (ksPath) storeFile file(ksPath) storePassword pick('storePassword', 'ANDROID_KEYSTORE_PASSWORD') keyAlias pick('keyAlias', 'ANDROID_KEY_ALIAS') keyPassword pick('keyPassword', 'ANDROID_KEY_PASSWORD') } } defaultConfig { applicationId "cn.fmode.app" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion /* * 版本号(2026-11-23 参数化) * * 原来写死 versionCode 1 / versionName "1.0",每发一版都得手改代码, * 而 app_update 的自动更新完全依赖这两个字段判断「有没有新版」: * · versionCode 用于比较大小(必须单调递增) * · versionName 用于展示给用户 * * 现在支持: * -PfmodeVersionCode=12 -PfmodeVersionName=1.2.0 * 发布脚本按 App 表里的版本号自动传入,避免手滑改错。 */ versionCode providers.gradleProperty('fmodeVersionCode').getOrElse('1').toInteger() versionName providers.gradleProperty('fmodeVersionName').getOrElse('1.0') testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" buildConfigField 'boolean', 'JPUSH_ENABLED', fmodeJpushEnabled.toString() // 厂商通道:JPushSdk 读取此值决定 setThirdPushEnable(true/false) buildConfigField 'boolean', 'JPUSH_VENDOR_ENABLED', (fmodeJpushEnabled && fmodeVendorPushEnabled).toString() /* * 厂商通道占位符:必须**始终有值**,否则 Manifest 里的 ${...} 解析失败。 * 未开启厂商通道时填空串 —— 极光 SDK 见到空值会跳过该厂商, * 不会因为占位符缺失而崩溃。 */ manifestPlaceholders += [ JPUSH_XIAOMI_APPID : providers.environmentVariable('XIAOMI_APPID').getOrElse(''), JPUSH_XIAOMI_APPKEY : providers.environmentVariable('XIAOMI_APPKEY').getOrElse(''), JPUSH_HUAWEI_APPID : providers.environmentVariable('HUAWEI_APPID').getOrElse(''), JPUSH_OPPO_APPKEY : providers.environmentVariable('OPPO_APPKEY').getOrElse(''), JPUSH_OPPO_APPID : providers.environmentVariable('OPPO_APPID').getOrElse(''), JPUSH_OPPO_APPSECRET : providers.environmentVariable('OPPO_APPSECRET').getOrElse(''), JPUSH_VIVO_APPKEY : providers.environmentVariable('VIVO_APPKEY').getOrElse(''), JPUSH_VIVO_APPID : providers.environmentVariable('VIVO_APPID').getOrElse(''), JPUSH_HONOR_APPID : providers.environmentVariable('HONOR_APPID').getOrElse(''), ] manifestPlaceholders += [JPUSH_APPKEY: fmodeJpushAppKey, JPUSH_CHANNEL: 'fmode', JPUSH_ENABLED: fmodeJpushEnabled.toString()] aaptOptions { // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61 ignoreAssetsPattern = '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~' } } buildFeatures { buildConfig = true } if (!fmodeJpushEnabled) { sourceSets.main.java { exclude '**/JPushSdk.java', '**/JPushReceiver.java', '**/JPushService.java', '**/JPushClickActivity.java' } } if (fmodeJpushEnabled && file('src/jpush/AndroidManifest.xml').exists()) { sourceSets.debug.manifest.srcFile 'src/jpush/AndroidManifest.xml' sourceSets.release.manifest.srcFile 'src/jpush/AndroidManifest.xml' } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' /* * 签名配置(2026-11-23 补) * * 原来 release 没有任何 signingConfig → 打出来是 unsigned APK, * 手机上根本装不上。补上 keystore 支持: * * 凭据**全部走环境变量/本地 properties,绝不入库**: * ANDROID_KEYSTORE_PATH keystore 绝对路径 * ANDROID_KEYSTORE_PASSWORD 仓库口令 * ANDROID_KEY_ALIAS 别名 * ANDROID_KEY_PASSWORD 别名口令 * * 也可以放 android/keystore.properties(已 gitignore),四行同名 key。 * * ⚠️ 变量缺失时**不报错**,只跳过签名 —— 保证 `assembleDebug`、 * CI 上只跑检查的场景不会因为没配签名而整体失败。 */ def ksFile = null def ksProps = new Properties() def propsFile = rootProject.file('keystore.properties') if (propsFile.exists()) { propsFile.withInputStream { ksProps.load(it) } } def pick = { String k, String env -> System.getenv(env) ?: ksProps.getProperty(k) ?: null } def ksPath = pick('storeFile', 'ANDROID_KEYSTORE_PATH') if (ksPath) { def f = new File(ksPath) if (f.exists()) ksFile = f } if (ksFile != null) { signingConfig signingConfigs.release } } } } repositories { if (fmodeJpushEnabled) { maven { url 'https://maven.jiguang.cn/nexus/content/repositories/releases/' content { includeGroup 'cn.jiguang.sdk' } } } flatDir{ dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs' } } dependencies { if (fmodeJpushEnabled) { implementation('cn.jiguang.sdk:jpush:6.3.1') { exclude group: 'cn.jiguang.sdk', module: 'jcore' } implementation 'cn.jiguang.sdk:jcore:5.6.0' } implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion" implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion" implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion" implementation project(':capacitor-android') testImplementation "junit:junit:$junitVersion" androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion" androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion" implementation project(':capacitor-cordova-android-plugins') } apply from: 'capacitor.build.gradle' try { def servicesJSON = file('google-services.json') if (servicesJSON.text) { apply plugin: 'com.google.gms.google-services' } } catch(Exception e) { logger.info("google-services.json not found, google-services plugin not applied. Push Notifications won't work") }