From a654609c8ade6dfbf046e466f9bbf4bea8cc48c8 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Mon, 21 Apr 2025 18:07:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=AF=E7=94=A8=E4=BB=A3=E7=A0=81=E6=B7=B7?= =?UTF-8?q?=E6=B7=86=E5=92=8C=E8=B5=84=E6=BA=90=E5=8E=8B=E7=BC=A9=E4=BB=A5?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=91=E5=B8=83=E5=92=8C=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle.kts | 14 +++++- android/app/proguard-rules.pro | 87 ++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 android/app/proguard-rules.pro 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