OCR 模型按需下载(P8 瘦身): - 移除 plugins/ppocr/assets/ 内置模型(det 9.8MB + rec 21MB + dict),APK 减包 ~31MB - 新增 modelDownloader.ts:优先从 HuggingFace/CDN 下载,兜底从 APK assets 拷贝 - OcrModule.kt 新增 setModelDir,支持从 filesystem 加载模型,回退 assets 兼容旧用户 - settingsStore 持久化 ocrModelVersion / ocrModelDir - 自动化页集成模型状态检查与一键下载 UI OCR 三层独立控制: - OcrProcessorConfig 从单一 aiVisionEnabled 拆分为 layer1/2/3 三个独立开关 - 设置页可按层启停(L1 正则规则 / L2 本地 OCR / L3 AI Vision) - OCR 处理增加耗时与字符数日志 日志系统升级: - logger.ts 新增 LogFileBackend 抽象,支持磁盘持久化(按日期 app-YYYY-MM-DD.log) - 新增 logBackend.ts(ExpoLogFileBackend)+ 日志中心页 settings/logs.tsx - 日志中心:实时缓冲 + 历史文件、4 级过滤、Tag/关键词搜索、JSON 展开、分享导出、7 天过期清理 - _layout.tsx 启动时初始化文件后端 + 日志脱敏(验证码/卡号) 原生浮层 UI 主题同步(P6): - 新增 floatingUiConfig.ts:JS 侧从 theme tokens + i18n 构建 FloatingUiConfig 推送原生 - 新增 FloatingUiConfigStore.kt:SharedPreferences 存储,三浮层组件读取 - FloatingBillView 重设计:颜色/文案走配置、新增币种 chip、金额校验改 BigDecimal - FloatingHelper / FloatingTip 同步适配 - _layout.tsx 新增 FloatingUiConfigSyncer,主题/语言切换自动推送 UI 与组件增强: - FormModal 新增 select/dropdown 控件、行内布局(row/flex)、联动回调 onValuesChange - 新增 Touchable 通用触摸组件、AccountCreateModal 快速建账弹窗 - 信用卡页展示账单周期/到期还款日/本期应还/剩余可用额度,关联账户改下拉选择 - AI 设置页重做:OpenAI/Gemini/DeepSeek 预设 + 默认 URL/模型 - 引导页新增 Android 权限检查步骤(无障碍/通知/短信/存储/悬浮窗) 去重优化: - 对手方匹配改为模糊包含(includes),双方均无对手方时判定低置信度重复 - DedupResult 新增 matchedItem 返回匹配对比项 文档重构: - README.md 重写为入口索引(品牌更新 + 模块概览 + 文档导航表) - 新增 AGENTS.md(AI 助手贡献指南)、docs/architecture.md(Mermaid 数据流/分层/OCR 级联图) - 新增 docs/development.md(环境/命令/编码规范/测试/提交规范)、plugins/README.md - UI 重设计文档(design spec + p1-p8)移入 docs/design/ 其他: - i18n 新增权限/信用卡详情/日志中心/AI 设置等翻译键 - ppocr Config Plugin 修复 import 注入去重;size-optimization 增强 - 新增测试:logger.test.ts、floating-ui-config.test.ts
159 lines
5.7 KiB
JavaScript
159 lines
5.7 KiB
JavaScript
const { withDangerousMod } = require('@expo/config-plugins');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
function withSizeOptimization(config) {
|
|
// 1. 在 prebuild 时修改 gradle.properties (开启 R8/ProGuard 代码混淆 + 资源裁剪 + .so 库压缩)
|
|
config = withDangerousMod(config, [
|
|
'android',
|
|
async (modConfig) => {
|
|
const projectRoot = modConfig.modRequest.platformProjectRoot;
|
|
const propertiesPath = path.join(projectRoot, 'gradle.properties');
|
|
if (fs.existsSync(propertiesPath)) {
|
|
let content = fs.readFileSync(propertiesPath, 'utf8');
|
|
|
|
// 限制打包架构为 arm64-v8a
|
|
if (content.includes('reactNativeArchitectures=')) {
|
|
content = content.replace(/reactNativeArchitectures=.*/, 'reactNativeArchitectures=arm64-v8a');
|
|
} else {
|
|
content += '\nreactNativeArchitectures=arm64-v8a\n';
|
|
}
|
|
|
|
// 1. 开启 R8 代码混淆与摇树裁剪
|
|
if (!content.includes('android.enableMinifyInReleaseBuilds=')) {
|
|
content += 'android.enableMinifyInReleaseBuilds=true\n';
|
|
} else {
|
|
content = content.replace(/android\.enableMinifyInReleaseBuilds=.*/, 'android.enableMinifyInReleaseBuilds=true');
|
|
}
|
|
|
|
// 1. 开启无用资源裁剪
|
|
if (!content.includes('android.enableShrinkResourcesInReleaseBuilds=')) {
|
|
content += 'android.enableShrinkResourcesInReleaseBuilds=true\n';
|
|
} else {
|
|
content = content.replace(/android\.enableShrinkResourcesInReleaseBuilds=.*/, 'android.enableShrinkResourcesInReleaseBuilds=true');
|
|
}
|
|
|
|
// 2. 开启 .so 动态库在 APK 内的高倍率压缩 (useLegacyPackaging=true)
|
|
if (!content.includes('expo.useLegacyPackaging=')) {
|
|
content += 'expo.useLegacyPackaging=true\n';
|
|
} else {
|
|
content = content.replace(/expo\.useLegacyPackaging=.*/, 'expo.useLegacyPackaging=true');
|
|
}
|
|
|
|
fs.writeFileSync(propertiesPath, content, 'utf8');
|
|
}
|
|
return modConfig;
|
|
}
|
|
]);
|
|
|
|
// 2. 在 prebuild 时修改 app/build.gradle 启用 ABI Splits 分包 + 字体裁剪
|
|
config = withDangerousMod(config, [
|
|
'android',
|
|
async (modConfig) => {
|
|
const projectRoot = modConfig.modRequest.platformProjectRoot;
|
|
const buildGradlePath = path.join(projectRoot, 'app/build.gradle');
|
|
if (fs.existsSync(buildGradlePath)) {
|
|
let content = fs.readFileSync(buildGradlePath, 'utf8');
|
|
|
|
// ABI Splits 分包配置
|
|
if (!content.includes('splits {')) {
|
|
content = content.replace(
|
|
/android\s*\{/,
|
|
`android {\n splits {\n abi {\n enable true\n reset()\n include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"\n universalApk true\n }\n }`
|
|
);
|
|
}
|
|
|
|
// 3. 裁剪未使用的 @expo/vector-icons 矢量字体
|
|
if (!content.includes('variant.mergeAssetsProvider.configure')) {
|
|
content += `
|
|
android.applicationVariants.all { variant ->
|
|
if (variant.buildType.name == "release") {
|
|
variant.mergeAssetsProvider.configure {
|
|
doLast {
|
|
delete fileTree(dir: outputDir, includes: [
|
|
"**/fonts/AntDesign.ttf",
|
|
"**/fonts/Entypo.ttf",
|
|
"**/fonts/EvilIcons.ttf",
|
|
"**/fonts/Feather.ttf",
|
|
"**/fonts/FontAwesome*.ttf",
|
|
"**/fonts/Fontisto.ttf",
|
|
"**/fonts/Foundation.ttf",
|
|
"**/fonts/MaterialCommunityIcons.ttf",
|
|
"**/fonts/MaterialIcons.ttf",
|
|
"**/fonts/Octicons.ttf",
|
|
"**/fonts/SimpleLineIcons.ttf",
|
|
"**/fonts/Zocial.ttf"
|
|
])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
}
|
|
fs.writeFileSync(buildGradlePath, content, 'utf8');
|
|
}
|
|
return modConfig;
|
|
}
|
|
]);
|
|
|
|
// 3. 在 prebuild 时修改 proguard-rules.pro 保护原生插件与 ONNX 模块
|
|
config = withDangerousMod(config, [
|
|
'android',
|
|
async (modConfig) => {
|
|
const projectRoot = modConfig.modRequest.platformProjectRoot;
|
|
const proguardPath = path.join(projectRoot, 'app/proguard-rules.pro');
|
|
if (fs.existsSync(proguardPath)) {
|
|
let content = fs.readFileSync(proguardPath, 'utf8');
|
|
if (!content.includes('com.beancount.mobile')) {
|
|
content += `
|
|
# Size optimization: keep custom native packages & ONNX
|
|
-keep class com.beancount.mobile.** { *; }
|
|
-keep class com.example.driftledger.** { *; }
|
|
-keep class ai.onnxruntime.** { *; }
|
|
`;
|
|
fs.writeFileSync(proguardPath, content, 'utf8');
|
|
}
|
|
}
|
|
return modConfig;
|
|
}
|
|
]);
|
|
|
|
// 4. 在 prebuild 时修改 root build.gradle 强制指定所有模块的 NDK 版本以匹配 27.1.12297006
|
|
config = withDangerousMod(config, [
|
|
'android',
|
|
async (modConfig) => {
|
|
const projectRoot = modConfig.modRequest.platformProjectRoot;
|
|
const rootBuildGradlePath = path.join(projectRoot, 'build.gradle');
|
|
if (fs.existsSync(rootBuildGradlePath)) {
|
|
let content = fs.readFileSync(rootBuildGradlePath, 'utf8');
|
|
if (!content.includes('ndkVersion = "27.1.12297006"')) {
|
|
content += `
|
|
subprojects { project ->
|
|
def configureProject = { proj ->
|
|
if (proj.hasProperty("android")) {
|
|
proj.android {
|
|
ndkVersion = "27.1.12297006"
|
|
}
|
|
}
|
|
}
|
|
if (project.state.executed) {
|
|
configureProject(project)
|
|
} else {
|
|
project.afterEvaluate {
|
|
configureProject(project)
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
fs.writeFileSync(rootBuildGradlePath, content, 'utf8');
|
|
}
|
|
}
|
|
return modConfig;
|
|
}
|
|
]);
|
|
|
|
return config;
|
|
}
|
|
|
|
module.exports = withSizeOptimization;
|