You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

启用ProGuard后Compose Desktop生成发布包失败求助

解决Compose Desktop ProGuard混淆打包失败问题

处理重复类定义

  • 执行./gradlew dependencies生成依赖树,定位重复类对应的库,找出被多次引入的版本
  • 在build.gradle.kts里用exclude剔除多余依赖,示例:
    implementation("目标依赖") {
        exclude(group = "重复库的组名", module = "重复库的模块名")
    }
    
  • 也可以强制统一依赖版本,在dependencyManagement块里配置:
    dependencyManagement {
        dependencies {
            dependency("重复库组名:重复库模块名:统一版本号")
        }
    }
    

解决未依赖库的类找不到警告

  • 先排查是否有间接依赖引入了kotlinx.serialization:执行./gradlew dependencies | grep kotlinx-serialization,如果存在,要么排除该传递依赖,要么按需添加对应依赖
  • 若确定不需要该库,在ProGuard规则文件(比如proguard-rules.pro)中添加忽略规则:
    -dontwarn kotlinx.serialization.**
    
  • 若担心运行异常,也可保留相关类(非必要不建议):
    -keep class kotlinx.serialization.** { *; }
    

适配Compose Desktop的ProGuard规则

  • 必须保留Compose相关类与注解,否则打包后运行会崩溃,规则示例:
    -keep class androidx.compose.** { *; }
    -keep class org.jetbrains.compose.** { *; }
    -keepclassmembers class * {
        @androidx.compose.runtime.Composable <methods>;
    }
    
  • 不要混淆主入口类,替换为你的主类全路径:
    -keep class com.yourpackage.MainKt { *; }
    

重新执行打包

  • 先清理缓存:./gradlew clean
  • 再执行打包命令:./gradlew createReleaseDistributable

内容的提问来源于stack exchange,提问作者Dang Xuan Thong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 14:12:11