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

Flutter InAppWebView编译失败求助:minifyReleaseWithR8任务执行出错

Flutter Release构建失败:R8缺失android.window.BackEvent类

错误信息

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in D:home_page_design\build\flutter_inappwebview\outputs\mapping\release\missing_rules.txt.
ERROR: R8: Missing class android.window.BackEvent (referenced from: void io.flutter.view.FlutterView.startBackGesture(android.window.BackEvent) and 1 other context)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_inappwebview:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete

可能原因

  • android.window.BackEvent是Android 13(API 33)新增的系统类,若项目的compileSdkVersion或targetSdkVersion低于33,R8混淆时会找不到该类
  • flutter_inappwebview库的版本依赖了高版本Android API,但项目构建环境未适配对应版本

解决方案

1. 升级Android构建API版本

打开android/app/build.gradle文件,修改配置适配高版本API:

android {
    compileSdkVersion 33 // 可升级至34,保持与最新API兼容
    defaultConfig {
        targetSdkVersion 33 // 与compileSdkVersion版本保持一致
    }
}

同时检查android/build.gradle中的Kotlin版本,确保适配高版本API(推荐1.8.0及以上):

buildscript {
    ext.kotlin_version = '1.8.0'
    // 其他配置
}

2. 添加R8混淆保留规则

  • 找到错误提示里的missing_rules.txt文件,将其中的规则复制到android/app/proguard-rules.pro中
  • 若找不到该文件,手动添加以下规则跳过类检查:
-dontwarn android.window.BackEvent
-keep class android.window.BackEvent { *; }

还可添加flutter_inappwebview专属的保留规则,避免其他类缺失:

-keep class com.pichillilorenzo.flutter_inappwebview.** { *; }
-keep class io.flutter.view.** { *; }

3. 调整依赖版本兼容性

  • 确认flutter_inappwebview版本与当前Flutter版本兼容,可参考库的版本说明确认适配环境
  • 若升级API后仍有问题,尝试降级flutter_inappwebview到稳定兼容的版本(比如5.8.0,根据实际情况调整)

4. 彻底清理后重新构建

执行以下命令清理项目缓存,再重新构建Release版本:

flutter clean
rm -rf android/.gradle
flutter pub get
flutter build apk --release

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 12:05:05