build: 配置 Android Release 签名和构建优化

- 添加 Release 签名配置 (build.gradle.kts)
- 配置 ProGuard 混淆规则 (proguard-rules.pro)
- 优化 Gradle 内存配置 (gradle.properties)
- 更新 .gitignore 排除签名密钥文件

签名密钥存放于 publish/ 目录 (已排除版本控制)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Developer 2025-12-01 18:37:27 -08:00
parent 1fe66f34fd
commit 097396bb93
4 changed files with 91 additions and 4 deletions

View File

@ -43,3 +43,9 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release
# Release signing keys (IMPORTANT: never commit these!)
/publish/
*.keystore
*.jks
key.properties

View File

@ -1,3 +1,6 @@
import java.util.Properties
import java.io.FileInputStream
plugins {
id("com.android.application")
id("kotlin-android")
@ -5,6 +8,13 @@ plugins {
id("dev.flutter.flutter-gradle-plugin")
}
// Load key.properties
val keyPropertiesFile = rootProject.file("app/../publish/key.properties")
val keyProperties = Properties()
if (keyPropertiesFile.exists()) {
keyProperties.load(FileInputStream(keyPropertiesFile))
}
android {
namespace = "com.rwadurian.rwa_android_app"
compileSdk = flutter.compileSdkVersion
@ -30,11 +40,30 @@ android {
versionName = flutter.versionName
}
signingConfigs {
create("release") {
if (keyPropertiesFile.exists()) {
keyAlias = keyProperties["keyAlias"] as String
keyPassword = keyProperties["keyPassword"] as String
storeFile = file(keyProperties["storeFile"] as String)
storePassword = keyProperties["storePassword"] as String
}
}
}
buildTypes {
release {
// 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")
signingConfig = if (keyPropertiesFile.exists()) {
signingConfigs.getByName("release")
} else {
signingConfigs.getByName("debug")
}
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}

View File

@ -0,0 +1,45 @@
# Flutter wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
# Google Play Core (suppress warnings for deferred components)
-dontwarn com.google.android.play.core.splitcompat.SplitCompatApplication
-dontwarn com.google.android.play.core.splitinstall.SplitInstallException
-dontwarn com.google.android.play.core.splitinstall.SplitInstallManager
-dontwarn com.google.android.play.core.splitinstall.SplitInstallManagerFactory
-dontwarn com.google.android.play.core.splitinstall.SplitInstallRequest$Builder
-dontwarn com.google.android.play.core.splitinstall.SplitInstallRequest
-dontwarn com.google.android.play.core.splitinstall.SplitInstallSessionState
-dontwarn com.google.android.play.core.splitinstall.SplitInstallStateUpdatedListener
-dontwarn com.google.android.play.core.tasks.OnFailureListener
-dontwarn com.google.android.play.core.tasks.OnSuccessListener
-dontwarn com.google.android.play.core.tasks.Task
# Keep Kotlin metadata
-keep class kotlin.Metadata { *; }
# Keep web3dart classes
-keep class org.web3j.** { *; }
-dontwarn org.web3j.**
# Keep crypto classes
-keep class org.bouncycastle.** { *; }
-dontwarn org.bouncycastle.**
# Keep Gson classes
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.google.gson.** { *; }
# Keep R8 from stripping interface information
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
# Keep native methods
-keepclasseswithmembernames class * {
native <methods>;
}

View File

@ -1,2 +1,9 @@
org.gradle.jvmargs=-Xmx1536m -XX:MaxMetaspaceSize=384m -XX:ReservedCodeCacheSize=256m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:ReservedCodeCacheSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:+UseParallelGC
android.useAndroidX=true
# Disable parallel builds to reduce memory usage
org.gradle.parallel=false
org.gradle.caching=true
# Disable lint to reduce memory usage during release build
android.enableR8.fullMode=false