diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 22499b7..bc2e45c 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -35,6 +35,13 @@ android { ndk { abiFilters += listOf("arm64-v8a", "armeabi-v7a") } + // R8 裁剪未使用的 Java/Kotlin 代码与资源,减小 dex 与 res。 + isMinifyEnabled = true + isShrinkResources = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro", + ) // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig = signingConfigs.getByName("debug") @@ -52,6 +59,9 @@ kotlin { androidComponents { onVariants(selector().withBuildType("release")) { variant -> variant.packaging.jniLibs.excludes.add("lib/x86_64/**") + // 原生库随 APK 压缩存储:下载体积明显小于解压后的体积,代价是安装时解压。 + // 本包 90% 体积是 so,这一项对国内商店的 APK 分发影响最大。 + variant.packaging.jniLibs.useLegacyPackaging = true } } diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro new file mode 100644 index 0000000..eb2a8ef --- /dev/null +++ b/android/app/proguard-rules.pro @@ -0,0 +1,11 @@ +# Author: fruit.com.cn +# +# R8 保号规则:Flutter 引擎与插件自带的 consumer rules 已覆盖大部分场景, +# 这里只补本项目原生层通过反射/通道访问、裁剪后容易失效的入口。 + +# 画中画与权限通道由 MainActivity 直接注册,保留应用包名下的入口类。 +-keep class com.stormg.lumadrama.** { *; } + +# Flutter 引擎在 release 下通过 JNI 回调这些类,禁止改名。 +-keep class io.flutter.** { *; } +-dontwarn io.flutter.embedding.** diff --git a/android/gradle.properties b/android/gradle.properties index 19e019d..96c9d73 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -6,3 +6,8 @@ android.useAndroidX=true android.newDsl=false # This builtInKotlin flag was added by the Flutter template android.builtInKotlin=false + +# release 包默认剥离 Dart 调试符号并混淆:libapp.so 由 ~8MB 降到 ~1MB/ABI。 +# 符号表输出到 build/symbols,崩溃分析时用它还原堆栈,发布前务必归档。 +split-debug-info=build/symbols +dart-obfuscation=true diff --git a/pubspec.lock b/pubspec.lock index 9d2f1e3..f6fdda0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -105,14 +105,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.2" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - sha256: "41e005c33bd814be4d3096aff55b1908d419fde52ca656c8c47719ec745873cd" - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.0.9" dio: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 64d1b19..53a0714 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,9 +33,6 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.8 # 网络层用 dio(统一拦截器/超时/错误映射);纯 Dart 无原生插件,仍然不引代码生成与图片缓存库 dio: ^5.7.0 provider: ^6.1.5+1 @@ -90,7 +87,8 @@ flutter: - assets/icon/splash_logo.png - assets/icon/splash_logo_android12.png - assets/icon/rail/ - - assets/auth/ + # 只打包代码实际引用的那张登录背景(其余 3 张留在仓库但不进包)。 + - assets/auth/bg_3.jpg # To add assets to your application, add an assets section, like this: # assets: