Closed manuuuel closed 3 years ago
+1 same problem here!
I'm having the same issue with my Application.kt file after upgrading to Flutter v1.12.13 and firebase_message v6.0.9.
+1 same problem here!
Hi all,
I had the same issue with Application.java
and was able to solve this by changing AndroidManifest.xml from:
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
to:
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="1" />
Hi all, I had the same issue with
Application.java
and was able to solve this by changing AndroidManifest.xml from:</activity> <!-- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> <meta-data android:name="flutterEmbedding" android:value="2" />
to:
</activity> <!-- Don't delete the meta-data below. This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> <meta-data android:name="flutterEmbedding" android:value="1" />
I tried but it doesn't solve. I had to back to activity V1.
There is a workaround mentioned in: #1613
Replace:
override fun registerWith(registry: PluginRegistry?) {
GeneratedPluginRegistrant.registerWith(registry) //Error thrown here
}
To:
override fun registerWith(registry: PluginRegistry?) {
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
Also temporary downgrade firebase_messaging
to 5.1.6
firebase_messaging: ^5.1.6
The build crash is solved. Don't know if "background messaging" works. If someone can confirm that?
I had the same problem in Application.kt:
package com.application.customerApplication
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
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry) {
GeneratedPluginRegistrant.registerWith(registry)
}
}
To solve the problem I now use in Application.tk:
package com.application.customerApplication
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
override fun registerWith(registry: PluginRegistry?) {
registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin");
}
}
I found this solution in here.
But there are still problems in background notifications, like:
E/flutter (22439): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method FcmDartService#initialized on channel plugins.flutter.io/firebase_messaging_background)
Hi @ManuelDiPietro
in case you updated an app originally created in v1.9
you may want to run
flutter clean
flutter pub cache repair
let me know if this is the case and if the issue persists
thank you
I had the same problem in Application.kt:
package com.application.customerApplication 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 class Application : FlutterApplication(), PluginRegistrantCallback { override fun onCreate() { super.onCreate() FlutterFirebaseMessagingService.setPluginRegistrant(this) } override fun registerWith(registry: PluginRegistry) { GeneratedPluginRegistrant.registerWith(registry) } }
To solve the problem I now use in Application.tk:
package com.application.customerApplication import io.flutter.app.FlutterApplication import io.flutter.plugin.common.PluginRegistry import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService class Application : FlutterApplication(), PluginRegistrantCallback { override fun onCreate() { super.onCreate() FlutterFirebaseMessagingService.setPluginRegistrant(this); } override fun registerWith(registry: PluginRegistry?) { registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"); } }
I found this solution in here.
But there are still problems in background notifications, like:
E/flutter (22439): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method FcmDartService#initialized on channel plugins.flutter.io/firebase_messaging_background)
Yep, but in this way you cannot manage background message.
Hi @ManuelDiPietro in case you updated an app originally created in v1.9 you may want to run
flutter clean
flutter pub cache repair
let me know if this is the case and if the issue persists thank you
Yes, It works but using previous version of plugin ( <=6.0.6 ).
There is a workaround mentioned in: #1613
Replace:
override fun registerWith(registry: PluginRegistry?) { GeneratedPluginRegistrant.registerWith(registry) //Error thrown here }
To:
override fun registerWith(registry: PluginRegistry?) { io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin")); }
Also temporary downgrade
firebase_messaging
to5.1.6
firebase_messaging: ^5.1.6
The build crash is solved. Don't know if "background messaging" works. If someone can confirm that?
Hey, Thank You This Is Work For Me
any update on this? Same issue with a new project created with:
Flutter 1.12.13+hotfix.8 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 0b8abb4724 (2 weeks ago) • 2020-02-11 11:44:36 -0800
Engine • revision e1e6ced81d
Tools • Dart 2.7.0
I have been struggling with this issue for the last 4 days. To say that this is a massive issue is an understatement. Its making this plugin in android completely unusable for what I'm doing. The version I've been trying to get working is version 6.0.9. It's the latest version. If you need more information on this issue I'll be happy to provide it to you. Please let me know. It's kind of urgent I get this working. And the trouble is I have other plugins I am using and If I break flutters plugin system to get this plugin working it kind of defeats the benefit.
it's likely that you deleted the default metadata in AndroidManifest.xml I experienced the same thing, but after I changed to the initial settings everything was fine.
@collinjackson @kroikie Any updates, please? This issue blocks new projects receive push notifications from Cloud Messaging.
It is currently impossible to handle background push notifications (what you need the most basically) on Android because of this problem. When can we expect a fix ?
It is not working with latest 6.0.13, also getting the same error.
Changing the registerWith
method is not a fix, as it will crash if we define the onBackgroundMessage.
Push Notification is a very basic feature of any application, I was expecting it to be simple when I switched to Flutter + FCM but it looks like I was wrong...
I managed to fix the issue. The following are changes I had to make. It took an exhaustive search on the internet to figure this out. I wish the people associated with this project would just fix the docs with the correct information. The other piece of the for this is that when you set your intent you use the URL on the firebase console. NOT the url you encoded. This was one little line on an obscure page in the firebase dock. It took me weeks to find it. Cheers hope this helps.
Add the following to the AndroidManifest.xml
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="yourfirebaseconsole.page.link" android:scheme="https"/>
</intent-filter>
FirebaseCloudMessagingPluginRegistrant.kt
package com.your.packagename
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin
object FirebaseCloudMessagingPluginRegistrant {
fun registerWith(registry: PluginRegistry) {
if (alreadyRegisteredWith(registry)) {
return
}
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
}
private fun alreadyRegisteredWith(registry: PluginRegistry): Boolean {
val key: String = FirebaseCloudMessagingPluginRegistrant::class.java.getCanonicalName()
if (registry.hasPlugin(key)) {
return true
}
registry.registrarFor(key)
return false
}
}
MainActivity.kt
package com.your.packagename
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
// override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
// GeneratedPluginRegistrant.registerWith(flutterEngine);
//
// }
}
Application.kt
package com.your.packagename
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry) {
FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
}
}
And this is a bug with the documentation in MYHO making it a bug with the plugin.
@pneves001 but you still don't get background notifications ..
No I got it working. But background notifications happen when the app is closed. I also added this to the main.dart file of my app Some of it is in the main function
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:platform/platform.dart';
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
if (message.containsKey('data')) {
// Handle data message
final dynamic data = message['data'];
}
if (message.containsKey('notification')) {
// Handle notification message
final dynamic notification = message['notification'];
print(notification.toString());
}
void iosPermissions()
{
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings)
{
print("Settings registered: $settings");
});
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true)
);
}
void main() async {
Platform platform = LocalPlatform();
if (platform.isIOS == true) iosPermissions();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async
{
print("#### onMessage: $message");
},
onBackgroundMessage: (platform.isIOS == true) ? null : myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async
{
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async
{
print("onResume: $message");
},
);
_firebaseMessaging.getToken().then((token)
{
print(token);
},
onError: (error)
{
print(error);
});
}
@pneves001 that is weird because in my case background messages work if i set the android embedding to version 1 and switch back to the old kotlin implementation...
but with embedding v2 and your new implementation it's only working if the app is in the foreground.
Oh I forgot to mention. You need to change the application name to point to your new Application at the top of your AndroidManifest.xml.
<application
android:name=".Application"
android:label="yourappname"
android:icon="@mipmap/ic_launcher">
I know I did that. Otherwise I wouldn't have gotten it to work with v1 embedding
I'm just checking my app to see if there is anything else I neglected to mention.
Are you sending data messages or notification messages? Because I'm using data messages ..
This plugin is so finicky it took me a long time to get this to work right. One thing I had to do is store the message in local storage so that I can pass it to other widgets in separate files. Dart likes to keep everything in different files separate. It creates a contained space in every file. So I resorted to storing the messages in local storage.
Here is the version of the plugin I'm using:
firebase_messaging: ^6.0.12
Just text. No additional information.
On Sat, Mar 28, 2020 at 2:55 PM Lazy Llama notifications@github.com wrote:
Are you sending data messages or notification messages? Because I'm using data messages ..
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FirebaseExtended/flutterfire/issues/1684#issuecomment-605524716, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJGTQUJQQIWFY6DW7LNQWLRJZW6NANCNFSM4J52JVEQ .
--
Philip Neves - Director/CEO Neves Software Inc. Website: https://www.nevessoftware.com Email: philip.neves@gmail.com twitter: nevessoftware Cell: 778 232 9847 Office: 604 259 2645
And btw... I found this information in a stack overflow article. So it would be nice to have complete documentation that we needed to make everything work.
BTW... I believe I'm using V2.
Just text. No additional information. … On Sat, Mar 28, 2020 at 2:55 PM Lazy Llama @.**> wrote: Are you sending data messages or notification messages? Because I'm using data messages .. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#1684 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJGTQUJQQIWFY6DW7LNQWLRJZW6NANCNFSM4J52JVEQ . -- Philip Neves - Director/CEO Neves Software Inc. Website: https://www.nevessoftware.com Email: philip.neves@gmail.com twitter: nevessoftware Cell: 778 232 9847 Office:* 604 259 2645
What do you mean with "just text"?
Are you doing
{
"to": "/topics/mytopic",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
}
}
or
{
"to": "/topics/mytopic",
"data":{
"property":"Portugal vs. Denmark",
"property3":"great match!"
}
}
Well let me put it this way. When it comes to receiving messages out right and displaying them in app. I'm using websockets. I use firebase notifications just for text and to notify my users that there is a message that came in. The plugin is too finicky for that. IMO
Okay I found the issue... I am using the local notifications plugin and it wasn't able to execute in the background... So I had to do write a FlutterLocalNotificationPluginRegistrant ... now everything is working fine. Thank you.
I got the solution from here: https://stackoverflow.com/questions/53572110/flutter-push-notifications-even-if-the-app-is-closed
Managed to get a ticket with the Google team to provide a Kotlin based example for https://pub.dev/packages/firebase_messaging at https://github.com/FirebaseExtended/flutterfire/issues/2311
Reading through this issue, also I have no application.kt, just MainActivity.kt so this whole thing is a mess.
I expect the documentation to clarify what needs to be done for Kotlin when that is the new default for Flutter projects now.
I expect the documentation to clarify what needs to be done for Kotlin when that is the new default for Flutter projects now.
No you need to create the Application.kt yourself. Your actually replacing the MainActivity.kt file with that.
@pneves001, After doing these workarounds. Do we not use GeneratedPluginRegistrant.java anymore?
I have this in the file and I'm not sure what's causing the crash after installation during debugging. There's no error whatsoever on my side.
public final class GeneratedPluginRegistrant {
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
de.mintware.barcode_scan.BarcodeScanPlugin.registerWith(shimPluginRegistry.registrarFor("de.mintware.barcode_scan.BarcodeScanPlugin"));
io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin"));
flutterEngine.getPlugins().add(new com.mr.flutter.plugin.filepicker.FilePickerPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.firebaseauth.FirebaseAuthPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.core.FirebaseCorePlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.storage.FirebaseStoragePlugin());
com.roughike.facebooklogin.facebooklogin.FacebookLoginPlugin.registerWith(shimPluginRegistry.registrarFor("com.roughike.facebooklogin.facebooklogin.FacebookLoginPlugin"));
io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin"));
com.noeatsleepdev.geoflutterfire.GeoflutterfirePlugin.registerWith(shimPluginRegistry.registrarFor("com.noeatsleepdev.geoflutterfire.GeoflutterfirePlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.googlemaps.GoogleMapsPlugin());
io.flutter.plugins.googlesignin.GoogleSignInPlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.googlesignin.GoogleSignInPlugin"));
flutterEngine.getPlugins().add(new io.flutter.plugins.imagepicker.ImagePickerPlugin());
flutterEngine.getPlugins().add(new com.lyokone.location.LocationPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
flutterEngine.getPlugins().add(new com.tekartik.sqflite.SqflitePlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.urllauncher.UrlLauncherPlugin());
}
Any update on this? I'm getting the same error as the OP had 4 months ago.
Me too.
@mnorhamizan This is what I get too. :( I followed @pneves001 instructions and got the app crashing upon launch.
Flutter Channel master, 1.18.0-9.0.pre.122 firebase_messaging: 6.0.13
I managed to fix the issue. The following are changes I had to make. It took an exhaustive search on the internet to figure this out. I wish the people associated with this project would just fix the docs with the correct information. The other piece of the for this is that when you set your intent you use the URL on the firebase console. NOT the url you encoded. This was one little line on an obscure page in the firebase dock. It took me weeks to find it. Cheers hope this helps.
Add the following to the AndroidManifest.xml
<intent-filter> <action android:name="FLUTTER_NOTIFICATION_CLICK" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:host="yourfirebaseconsole.page.link" android:scheme="https"/> </intent-filter>
FirebaseCloudMessagingPluginRegistrant.kt
package com.your.packagename import io.flutter.plugin.common.PluginRegistry import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin object FirebaseCloudMessagingPluginRegistrant { fun registerWith(registry: PluginRegistry) { if (alreadyRegisteredWith(registry)) { return } FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin")) } private fun alreadyRegisteredWith(registry: PluginRegistry): Boolean { val key: String = FirebaseCloudMessagingPluginRegistrant::class.java.getCanonicalName() if (registry.hasPlugin(key)) { return true } registry.registrarFor(key) return false } }
MainActivity.kt
package com.your.packagename import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugins.GeneratedPluginRegistrant class MainActivity: FlutterActivity() { // override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { // GeneratedPluginRegistrant.registerWith(flutterEngine); // // } }
Application.kt
package com.your.packagename import io.flutter.app.FlutterApplication import io.flutter.plugin.common.PluginRegistry import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService class Application : FlutterApplication(), PluginRegistrantCallback { override fun onCreate() { super.onCreate() FlutterFirebaseMessagingService.setPluginRegistrant(this) } override fun registerWith(registry: PluginRegistry) { FirebaseCloudMessagingPluginRegistrant.registerWith(registry) } }
@pneves001 Why did you commented out the configureFlutterEngine()
from MainActivity.kt
? It is important to keep that function in order to register other types of plugins.
The FlutterApplication() base class already implements the configureFlutterEngine(). So you don't need to do it again.
@mnorhamizan This is what I get too. :( I followed @pneves001 instructions and got the app crashing upon launch.
Flutter Channel master, 1.18.0-9.0.pre.122 firebase_messaging: 6.0.13
Hi @Aurora12 , did you gix the crash on launch? I am having the same issue, can't get around it.
Same issue here.
I'd like to second this comment:
I wish the people associated with this project would just fix the docs with the correct information.
The Readme should have instructions for Kotlin since it is the default for new Flutter projects.
I'd like to second this comment:
I wish the people associated with this project would just fix the docs with the correct information.
The Readme should have instructions for Kotlin since it is the default for new Flutter projects.
Yes I'm agree
Can we get any attention to this problem from the team? The documentation is all messed up.
This is what I am still getting:
e: ...Application.kt: (10, 7): 'onCreate' hides member of supertype 'FlutterApplication' and needs 'override' modifier
e: .../Application.kt: (14, 7): 'registerWith' hides member of supertype 'PluginRegistrantCallback' and needs 'override' modifier
e: .../Application.kt: (15, 44): Type mismatch: inferred type is PluginRegistry but FlutterEngine was expected
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more 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 42s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
I still have this same issue, seems like this new set up complicates things... I guess I might have to put off notifications on my app for the time being... are there any known alternatives?
+1 same problem here!
Still no Kotlin instructions on the latest firebase_messaging 7.0.0
release: https://pub.dev/packages/firebase_messaging 😢
Problem
I'm using the master repo version of firebase_messaging and I also done the fix suggested in last README.md.
My environment
• No issues found!
Code:
MainActivity.kt
Application.kt