firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.46k stars 3.91k forks source link

[firebase_messaging] Application.kt: Type mismatch: inferred type is PluginRegistry but FlutterEngine was expected #1684

Closed manuuuel closed 3 years ago

manuuuel commented 4 years ago

Problem

customerApplication/android/app/src/main/kotlin/com/application/customerApplication/Application.kt: (17, 48): 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 12s
Finished with error: Gradle task assembleDebug failed with exit code 1

I'm using the master repo version of firebase_messaging and I also done the fix suggested in last README.md.

My environment

[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.1 19B88, locale it-IT)
    • Flutter version 1.12.13+hotfix.5 at /Users/user/flutter
    • Framework revision 27321ebbad (9 days ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/user/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = /Users/user/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/user/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3, Build version 11C29
    • CocoaPods version 1.8.4

[✓] Android Studio (version 3.5)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 42.1.1
    • Dart plugin version 191.8593
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.41.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.7.1

[✓] Connected device (1 available)
    • AOSP on IA Emulator • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!

Code:

MainActivity.kt

package com.application.customerApplication

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.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)
    }
}
marcoparioli commented 4 years ago

+1 same problem here!

Jeanlo commented 4 years ago

I'm having the same issue with my Application.kt file after upgrading to Flutter v1.12.13 and firebase_message v6.0.9.

daadu commented 4 years ago

+1 same problem here!

NateNjuguna commented 4 years ago

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" />
manuuuel commented 4 years ago

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.

daadu commented 4 years ago

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?

idevol commented 4 years ago

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)
iapicca commented 4 years ago

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

manuuuel commented 4 years ago

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.

manuuuel commented 4 years ago

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 ).

4RSIM3R commented 4 years ago

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?

Hey, Thank You This Is Work For Me

NeXT405 commented 4 years ago

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
pneves001 commented 4 years ago

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.

odysahe commented 4 years ago

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.

peternagy1332 commented 4 years ago

@collinjackson @kroikie Any updates, please? This issue blocks new projects receive push notifications from Cloud Messaging.

schankam commented 4 years ago

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 registerWithmethod 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...

pneves001 commented 4 years ago

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 commented 4 years ago

And this is a bug with the documentation in MYHO making it a bug with the plugin.

LasseRosenow commented 4 years ago

@pneves001 but you still don't get background notifications ..

pneves001 commented 4 years ago

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); 

          });

}
LasseRosenow commented 4 years ago

@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.

pneves001 commented 4 years ago

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">
LasseRosenow commented 4 years ago

I know I did that. Otherwise I wouldn't have gotten it to work with v1 embedding

pneves001 commented 4 years ago

I'm just checking my app to see if there is anything else I neglected to mention.

LasseRosenow commented 4 years ago

Are you sending data messages or notification messages? Because I'm using data messages ..

pneves001 commented 4 years ago

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.

pneves001 commented 4 years ago

Here is the version of the plugin I'm using:

firebase_messaging: ^6.0.12

pneves001 commented 4 years ago

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

pneves001 commented 4 years ago

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.

pneves001 commented 4 years ago

BTW... I believe I'm using V2.

LasseRosenow commented 4 years ago

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!"
      }
}
pneves001 commented 4 years ago

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

LasseRosenow commented 4 years ago

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

giorgio79 commented 4 years ago

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.

awhitford commented 4 years ago

I expect the documentation to clarify what needs to be done for Kotlin when that is the new default for Flutter projects now.

pneves001 commented 4 years ago

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.

mnorhamizan commented 4 years ago

@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());
  }
bartekpacia commented 4 years ago

Any update on this? I'm getting the same error as the OP had 4 months ago.

krunduev commented 4 years ago

Me too.

Aurora12 commented 4 years ago

@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

firatcetiner commented 3 years ago

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.

pneves001 commented 3 years ago

The FlutterApplication() base class already implements the configureFlutterEngine(). So you don't need to do it again.

aidandavis commented 3 years ago

@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.

yanivshaked commented 3 years ago

Same issue here.

awhitford commented 3 years ago

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.

akoua commented 3 years ago

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

dmiedev commented 3 years ago

Can we get any attention to this problem from the team? The documentation is all messed up.

Xbobo5530 commented 3 years ago

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?

khacnha commented 3 years ago

+1 same problem here!

awhitford commented 3 years ago

Still no Kotlin instructions on the latest firebase_messaging 7.0.0 release: https://pub.dev/packages/firebase_messaging 😢