[firebase_messaging] Compile error
Describe the bug
Can't install the plugin on a fresh new project created using: flutter create -a java bug
To Reproduce
- Create a new project using
flutter create -a java bug - Follow each step in Android Integration of the plugin
- Running the app results in:
Launching lib\main.dart on Android SDK built for x86 in debug mode...
C:\Users\Alex\Desktop\codes\bug\android\app\src\main\java\com\example\bug\Application.java:13: error: cannot access FirebaseMessagingService
FlutterFirebaseMessagingService.setPluginRegistrant(this);
^
class file for com.google.firebase.messaging.FirebaseMessagingService not found
C:\Users\Alex\Desktop\codes\bug\android\app\src\main\java\com\example\bug\Application.java:18: error: incompatible types: PluginRegistry cannot be converted to FlutterEngine
GeneratedPluginRegistrant.registerWith(registry);
^
Application.java:
package com.example.bug;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
Flutter Doctor:
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.17763.529], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 3.5)
[√] VS Code (version 1.42.1)
[√] Connected device (1 available)
• No issues found!
Expected behavior Working plugin
I'm having the same issue right now,
did anyone find the solution?
here is flutter doctor -v output
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.15.3 19D76, locale en)
• Flutter version 1.12.13+hotfix.8 at /Users/username/works/compilers/flutter
• Framework revision 0b8abb4724 (8 days ago), 2020-02-11 11:44:36 -0800
• Engine revision e1e6ced81d
• Dart version 2.7.0
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/username/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Users/username/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.6010548/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Users/username/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191.6010548/Android Studio.app/Contents
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] Connected device (1 available)
• iPhone 6 • 17f9c1bb33484cbe484f26b1 • ios • iOS 12.4.5
! Doctor found issues in 1 category.
I think this is related to #1904, which is unsolved yet too
Same issue... any progress on it? Thanx
you can follow this tutorial to make it work, @furiousdazzewizard https://www.djamware.com/post/5e4b26e26cdeb308204b427f/flutter-tutorial-firebase-cloud-messaging-fcm-push-notification
~but beware, some of plugin might not work,~
~in my case, google map plugin is not working.~
~since the tutorial told us to disable Plugin Registrant on MainActivity~
disabling Plugin Registrant on MainActivity is not mandatory, it seems , we can still receive notification even if it still enabled.
I didn't know what the purpose of disabling it on the tutorial.
you can follow this tutorial to make it work, @furiousdazzewizard https://www.djamware.com/post/5e4b26e26cdeb308204b427f/flutter-tutorial-firebase-cloud-messaging-fcm-push-notification
~but beware, some of plugin might not work,~ ~in my case,
google mapplugin is not working.~~since the tutorial told us to disable
Plugin RegistrantonMainActivity~disabling
Plugin RegistrantonMainActivityis not mandatory, it seems , we can still receive notification even if it still enabled.I didn't know what the purpose of disabling it on the tutorial.
--> Thanks @sidhijakpat for your reply!.. I managed to make it work with a similar solution, using this code on 'Application.java':
import my.package.name; import io.flutter.app.FlutterApplication; import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback; import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin; import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
public class Application extends FlutterApplication implements PluginRegistrantCallback { @Override public void onCreate() { super.onCreate(); FlutterFirebaseMessagingService.setPluginRegistrant(this); }
@Override
public void registerWith(PluginRegistry registry) {
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
My problem now is that I'm trying to add local push notification functionality to my app, in order to display the received background messages on the system tray. Here is the code I'm trying out as the relevant callback:
Future
Future
I still cannot making it work, I'm getting the following error message in the logcat window:
2020-02-21 08:12:49.412 16846-16846 /my.package.name E/MethodChannel#dexterous.com/flutter/local_notifications: Failed to handle method call java.lang.NullPointerException: name is null at android.content.res.ResourcesImpl.getIdentifier(ResourcesImpl.java:252) at android.content.res.Resources.getIdentifier(Resources.java:1942) at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.isValidDrawableResource(FlutterLocalNotificationsPlugin.java:684) at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.initialize(FlutterLocalNotificationsPlugin.java:805) at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:706) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231) at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93) at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:326) at android.os.Looper.loop(Looper.java:181) at android.app.ActivityThread.main(ActivityThread.java:7078) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
Also, on the flutter console I'm getting the following:
I/flutter (16846): Unable to handle incoming background message. I/flutter (16846): MissingPluginException(No implementation found for method show on channel dexterous.com/flutter/local_notifications)
ANY IDEAS??? thanks in advance!
Android or iOS @furiousdazzewizard ?
on iOS, I've read somewhere when trying to figure out this problem, that it prevent multiple notification handler or something, let me try finding it again.
on Android, if I'm not read it wrong, it is something to do with empty/null asset icon for local notification, have you set it? if you do, make sure the file is there
EDIT: oh it was Android 😬
Closing in favour of trying the latest messaging version which has since this issue was created been heavily reworked to improve it along with detailed documentation: https://firebase.flutter.dev/docs/messaging/overview
If you still have a problem please raise a new GitHub issue with up to date information and code snippets if possible. Thanks.