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

添加flutter_local_notification后Android12真机崩溃(模拟器正常)

解决Android 12真机添加flutter_local_notification后崩溃问题

问题原因

Android 12系统内置的androidx.window.extensions组件版本较低,和你引入的androidx.window:1.0.0正式版存在API兼容问题——系统组件没有实现新版本中的addWindowLayoutInfoListener方法,导致运行时触发NoSuchMethodError崩溃。

解决方案

  • 强制使用兼容Android 12的window库版本
    在android/app/build.gradle中添加版本强制策略,确保依赖的window库版本和系统组件兼容:

    configurations.all {
        resolutionStrategy {
            force 'androidx.window:window:1.0.0-beta04'
            force 'androidx.window:window-java:1.0.0-beta04'
        }
    }
    

    同时可以移除之前单独添加的implementation 'androidx.window:window:1.0.0'相关行,让Gradle自动处理依赖。

  • 升级flutter_local_notification到最新稳定版
    打开项目根目录的pubspec.yaml,更新通知库版本到最新:

    dependencies:
      flutter_local_notifications: ^16.1.0 # 替换为当前最新稳定版本
    

    执行flutter pub get同步依赖,新版本通常会修复这类系统兼容问题。

  • 清理项目缓存
    执行以下命令清除旧依赖缓存,避免残留冲突:

    flutter clean
    cd android && ./gradlew clean
    cd .. && flutter pub get
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 02:20:31