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

Flutter打包release版appbundle报:app:minifyReleaseWithR8任务执行失败

问题排查与解决步骤

第一步:获取具体报错详情

  • 执行带堆栈日志的构建命令,定位R8编译失败的具体原因:
    flutter build appbundle --release --stacktrace
  • 重点查看报错日志中是否有类缺失、重复依赖、规则冲突类的明确提示。

第二步:常见问题对应解决方案

方案1:补全第三方依赖的混淆规则

你引入的Firebase、Facebook SDK、广告中介、支付SDK等第三方服务都需要配套混淆规则,检查android/app/proguard-rules.pro文件,添加以下规则:

# Flutter 基础混淆规则
-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.**  { *; }

# Firebase 全系列规则
-keep class com.google.firebase.** { *; }
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.firebase.**
-dontwarn com.google.android.gms.**

# Facebook SDK 规则
-keep class com.facebook.** { *; }
-keep interface com.facebook.** { *; }
-dontwarn com.facebook.**

# 广告中介规则
-keep class com.google.ads.mediation.facebook.** { *; }
-dontwarn com.google.ads.mediation.facebook.**

# 支付SDK规则
-keep class com.android.billingclient.** { *; }
-dontwarn com.android.billingclient.**

方案2:修复依赖版本冲突

你当前的依赖配置存在Firebase版本不统一问题:已经引入了Firebase Bom统一管理版本,不需要再给单个Firebase库指定版本,去掉各个Firebase依赖后的版本号即可,避免版本不一致导致R8编译失败。
修改后依赖示例:

implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-perf'

方案3:临时验证问题范围

如果暂时定位不到具体原因,可以先禁用代码收缩验证构建流程是否正常:
执行命令flutter build appbundle --release --no-shrink
如果构建成功,即可确认问题出在R8混淆规则配置上,再针对性排查即可。

方案4:升级R8/AGP版本

如果是R8本身的bug导致编译失败,可以在项目根目录的gradle.properties文件添加配置开启R8完整模式:
android.enableR8.fullMode=true
也可以升级Android Gradle插件版本到7.0及以上,同步更新R8版本解决兼容问题。

第三步:清理缓存重新构建

每次修改配置后执行以下命令清理缓存再发起构建:

flutter clean
cd android
./gradlew clean
cd ..
flutter build appbundle --release

内容的提问来源于stack exchange,提问作者Dani

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 14:36:05