Reputation: 420
I want to add firebase messaging to my flutter app and I want to register the plugin in application.java
but my app gets stuck at
Installing build\app\outputs\apk\app.apk...
and when I try to launch it gives me an error that it keeps stopping.
the file contains errors in importing the package
My Code:
package com.example.flutter_fcm_java_test;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
//Error in this import
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
//can't read firebase messaging service
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
I've added the firebase messaging plugin dependency in my pubspec.yaml file and changed my name tag in the manifest to .Application and it can read it.
please help me.
My directory to Application.java
C:\Users...\AndroidStudioProjects\flutter_fcm_java_test\android\app\src\main\java\com\example\flutter_fcm_java_test
the file extension is java source file
Upvotes: 4
Views: 2459
Reputation: 612
Any error message with the building? If faced message as
[firebase_messaging] class file for com.google.firebase.messaging.FirebaseMessagingService not found
Try following resolution (tested with firebase_messaging: ^6.0.3) by adding firebase messaging dependency in your app/build.gradle
dependencies {
// ...
implementation 'com.google.firebase:firebase-messaging:20.1.0'
}
Upvotes: 4