liufumingren 01599d1716 新增打包体系:exe/APK 一键打包与配置统一
- Windows exe:electron-builder 配置 + build:exe 一键打包
- Android APK:离线打包脚手架(命令打包,无需 Android Studio),包名/签名沿用散单项目
- 版本统一:package.json 三段版本,APK versionCode 自动推导
- 配置统一到 config/ 目录,含密钥文件 git 忽略并配套 example 模板
- env.js 接口地址改为环境变量注入,移除敏感信息
- 删除 info/basicinfo.txt(含账号/IP 数据)
- tsconfig 移除已弃用的 baseUrl
2026-09-18 20:13:41 +08:00

98 lines
3.7 KiB
Groovy

apply plugin: 'com.android.application'
// ===== 统一配置:动态读取项目根 config/android.json 与 package.json(见 config/README.md)=====
// 本文件不包含任何密码/包名等可变配置,可直接提交 git。
def projectRoot = file('../../..')
def cfgFile = new File(projectRoot, 'config/android.json')
if (!cfgFile.exists()) {
throw new GradleException('config/android.json not found. Copy config/android.example.json to config/android.json first. See config/README.md')
}
def cfg = new groovy.json.JsonSlurper().parseText(cfgFile.getText('UTF-8'))
def pkgFile = new File(projectRoot, 'package.json')
def pkg = new groovy.json.JsonSlurper().parseText(pkgFile.getText('UTF-8'))
def versionNameValue = pkg.version
def versionParts = versionNameValue.tokenize('.')
if (versionParts.size() < 3) {
throw new GradleException("package.json version must be three-part X.Y.Z, got: ${versionNameValue}")
}
// versionCode = X*1000000 + Y*1000 + Z (each part 0-999)
def versionCodeValue = versionParts[0].toInteger() * 1000000 + versionParts[1].toInteger() * 1000 + versionParts[2].toInteger()
android {
compileSdkVersion 35
buildToolsVersion '35.0.0'
namespace cfg.packageName
defaultConfig {
applicationId cfg.packageName
minSdkVersion 21
targetSdkVersion 33
versionCode versionCodeValue
versionName versionNameValue
multiDexEnabled true
resValue 'string', 'app_name', cfg.appName
manifestPlaceholders = [
'dcloud_appkey': cfg.appKey ?: ''
]
ndk {
abiFilters = cfg.abis
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
signingConfigs {
config {
keyAlias cfg.signing.keyAlias
keyPassword cfg.signing.keyPassword
storeFile file('../../../' + cfg.signing.keystore)
storePassword cfg.signing.storePassword
v1SigningEnabled true
v2SigningEnabled true
}
}
buildTypes {
debug {
signingConfig signingConfigs.config
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
signingConfig signingConfigs.config
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
aaptOptions {
additionalParameters '--auto-add-overlay'
ignoreAssetsPattern "!.svn:!.git:.*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"
}
}
// 每次构建前从 config 生成 dcloud_control.xml(appid)
task generateDcloudControl {
doLast {
def controlFile = file('src/main/assets/data/dcloud_control.xml')
controlFile.parentFile.mkdirs()
controlFile.setText("<hbuilder>\n<apps>\n <app appid=\"${cfg.appId}\" appver=\"\"/>\n</apps>\n</hbuilder>\n", 'UTF-8')
}
}
preBuild.dependsOn generateDcloudControl
dependencies {
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'androidx.core:core:1.1.0'
implementation "androidx.fragment:fragment:1.1.0"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.facebook.fresco:fresco:2.5.0'
implementation "com.facebook.fresco:animated-gif:2.5.0"
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.alibaba:fastjson:1.2.83'
implementation 'androidx.webkit:webkit:1.5.0'
}