简体   繁体   中英

Can't use flutter_local_notifications

I using the latest version of flutter_local_notifications in my project, but keep getting this issue

Launching lib/main.dart on Mi A2 in debug mode...
/home/xxx/Desktop/flutter_linux_1.22.6-stable/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_local_notifications-4.0.1+1/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java:1260: error: cannot find symbol
            List<NotificationChannel> channels = notificationManagerCompat.getNotificationChannels();
                                                                          ^
  symbol:   method getNotificationChannels()
  location: variable notificationManagerCompat of type NotificationManagerCompat
1 error

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 25s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

My flutter version

Flutter 1.22.6 • channel stable 

pubspec.yaml

firebase_messaging: ^9.0.0
firebase_core: ^1.0.0
flutter_local_notifications: ^4.0.1+1

在此处输入图像描述

I finally reproduced such kind of issue and could solve it by upgrading or downgrading the plugin or remove the plugin from.pub_chace and install it, in your case flutter_local_notifications .

open android\build.gradle find this

subprojects { project.evaluationDependsOn(':app')

project.configurations.all {
    resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'androidx.core' &&
                !details.requested.name.contains('androidx')) {
            details.useVersion "1.0.1"
        }
    }
}

delete project.configurations.all and all its content

the new code now looks like this

subprojects { project.evaluationDependsOn(':app') }

flutter clean flutter pub get

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM