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

运行合作方Flutter应用时遭遇flutter_local_notifications编译错误

问题描述

运行合作方的Flutter应用时,flutter_local_notifications插件出现编译错误,具体错误信息如下:

C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_local_notifications-9.9.1\android\src\main\java\com\dexterous\flutterlocalnotifications\FlutterLocalNotificationsPlugin.java:1554: error: cannot find symbol
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                                                        ^
      symbol:   variable TIRAMISU
      location: class VERSION_CODES
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_local_notifications-9.9.1\android\src\main\java\com\dexterous\flutterlocalnotifications\FlutterLocalNotificationsPlugin.java:1555: error: cannot find symbol
          String permission = Manifest.permission.POST_NOTIFICATIONS;
                                                 ^
      symbol:   variable POST_NOTIFICATIONS
      location: class permission
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_local_notifications:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* 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

BUILD FAILED in 3m 20s
Exception: Gradle task assembleDebug failed with exit code 1

错误提示无法找到TIRAMISU和POST_NOTIFICATIONS符号,导致Gradle构建失败。

解决方案

这两个符号对应Android 13(API 33)的专属API,错误原因是Android构建环境未配置对应版本的编译SDK,可通过以下方式解决:

  • 修改项目根目录下android/app/build.gradle文件,将compileSdkVersion和targetSdkVersion设置为33或更高版本:

    android {
      compileSdkVersion 33 // 或更高版本
      defaultConfig {
        targetSdkVersion 33 // 或更高版本
      }
    }
    
  • 若使用Flutter 3.3及以上版本,同步更新android/build.gradle中的全局compileSdkVersion配置:

    buildscript {
      ext {
        compileSdkVersion = 33 // 或更高版本
        // 其他配置项保持不变
      }
    }
    
  • 清理缓存并重新构建项目:
    执行以下命令:

    flutter clean
    flutter pub get
    flutter run
    
  • 若无法升级SDK版本,可降级flutter_local_notifications插件至不依赖Android 13 API的版本(比如9.8.0),修改pubspec.yaml:

    dependencies:
      flutter_local_notifications: ^9.8.0
    

    执行flutter pub get重新拉取依赖即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 23:10:25