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

如何解决R8编译错误:Missing class android.window.BackEvent

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/admin/Desktop/mobile-app/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

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

问题描述

应用调试模式运行正常,但构建Release版本时触发上述R8编译错误,已尝试添加-dontwarn android.window.BackEvent规则但无效。

解决方案

1. 升级依赖库版本

android.window.BackEvent是Android 13(API 33)新增的类,错误通常源于flutter_inappwebview或Flutter SDK版本与目标Android API级别不匹配:

  • 在pubspec.yaml中更新flutter_inappwebview到最新稳定版,执行flutter pub get同步依赖。
  • 升级Flutter SDK到支持API 33的版本(建议3.10+),执行flutter upgrade。

2. 调整Android构建配置

在android/app/build.gradle文件中,确保编译和目标SDK版本至少为33:

android {
    compileSdkVersion 33
    defaultConfig {
        targetSdkVersion 33
        // 其他原有配置
    }
    // 其他原有配置
}

3. 添加完整的ProGuard/R8规则

在android/app/proguard-rules.pro中同时添加keep和dontwarn规则,替代单独的dontwarn:

-keep class android.window.BackEvent { *; }
-dontwarn android.window.BackEvent
-keep class io.flutter.view.FlutterView { *; }

4. 临时禁用R8(不推荐)

若上述方案无法快速解决,可临时关闭R8压缩(会导致包体积增大),在android/gradle.properties中添加:

android.enableR8=false

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 02:15:01