diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 883dea602..609facd8c 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -97,12 +97,22 @@ android { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - isMinifyEnabled = false - isShrinkResources = false + isMinifyEnabled = true + isShrinkResources = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) signingConfig = signingConfigs.getByName("release") // signingConfig = signingConfigs.getByName("debug") } debug { + isMinifyEnabled = true + isShrinkResources = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) signingConfig = signingConfigs.getByName("debug") } } diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro new file mode 100644 index 000000000..62f534c82 --- /dev/null +++ b/android/app/proguard-rules.pro @@ -0,0 +1,87 @@ +# Flutter Framework +# 这些规则保留了 Flutter 引擎和插件系统正常运行所需的类。 +-ignorewarnings +-keep class io.flutter.app.** { *; } +-keep class io.flutter.plugin.** { *; } +-keep class io.flutter.util.** { *; } +-keep class io.flutter.view.** { *; } +-keep class io.flutter.embedding.android.** { *; } +-keep class io.flutter.embedding.engine.** { *; } +-keep class io.flutter.embedding.engine.plugins.** { *; } +-keep class io.flutter.plugin.common.** { *; } +-keep class io.flutter.plugins.** { *; } +-keep class io.flutter.plugin.platform.** { *; } + +# 保留你的应用程序的主 Activity。 +# !!! 请将 com.example.deep_voice.MainActivity 替换为你的实际包名和 Activity 类名 !!! +-keep class com.yunqiinnovation.deepsound.MainActivity { *; } + +# 保留 open_ai_service 包下的所有类 +-keep class com.yunqiinnovation.open_ai_service.** { *; } + +# 保留 MCPClient 相关类 +-keep class com.yunqiinnovation.open_ai_service.MCPClient { *; } +-keep class com.yunqiinnovation.open_ai_service.MCPSubClient { *; } +-keep class com.yunqiinnovation.open_ai_service.FunctionHandler { *; } +-keep class com.yunqiinnovation.open_ai_service.ToolType { *; } +-keep class com.yunqiinnovation.open_ai_service.mcp.** { *; } +-keep class com.yunqiinnovation.open_ai_service.mcp.CustomSseClientTransport { *; } +-keep class com.yunqiinnovation.open_ai_service.SystemFunctionHandler { *; } +-keep class com.yunqiinnovation.open_ai_service.OpenAIService { *; } +-keep class com.yunqiinnovation.open_ai_service.OpenAIService$* { *; } + +# 保留 OpenAIServicePlugin 类 +-keep class com.yunqiinnovation.open_ai_service.OpenAIServicePlugin { *; } + +# 保留 Jackson 相关类 +-keep class com.fasterxml.jackson.** { *; } +-keep class com.fasterxml.jackson.databind.** { *; } +-keep class com.fasterxml.jackson.core.** { *; } + +# 保留 Ktor 相关类 +-keep class io.ktor.** { *; } +-keep class kotlinx.coroutines.** { *; } +-keep class kotlinx.serialization.** { *; } + +# 如果你的应用直接使用了 AndroidX 的某些特定类(例如,通过原生代码或插件),可能需要保留它们。 +# 例如,保留所有 Parcelable 实现类,如果它们被跨进程使用或序列化。 +# -keep class * implements android.os.Parcelable { +# public static final android.os.Parcelable$Creator *; +# } + +# 保留 MCP 相关依赖库 +-keep class io.modelcontextprotocol.** { *; } +-keep class com.anthropic.** { *; } + +# 保留 OkHttp 相关类 +-keep class okhttp3.** { *; } +-keep class okio.** { *; } + +# 如果你使用了特定的第三方库,并且这些库需要特定的 ProGuard 规则,请在此处添加。 +# 例如,OkHttp/Retrofit, Gson, Glide 等通常需要保留模型类或特定方法。 +# 查看库的官方文档通常会提供所需的 ProGuard 规则。 + +# -keepclasseswithmembers class * { +# @android.webkit.JavascriptInterface ; +# } + +# -keepattributes Signature +# -keepattributes *Annotation* + +# 如果你有自定义的原生插件,需要保留它们的类。 +# !!! 将 com.yourcompany.yourplugin.** 替换为你的插件的实际包名 !!! +# -keep class com.yourcompany.yourplugin.** { *; } + +# 保留枚举类,防止 switch 语句因混淆出错 +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +# 保留 R 类及其内部类,防止资源访问出错 +-keep class **.R$* { *; } + +# 保留 native 方法 +-keepclasseswithmembernames class * { + native ; +} \ No newline at end of file