我想为我的项目添加一个 firebase 推送通知服务。但我面临一些问题。请帮帮我。我已经被这个问题困住了一个星期。我正在使用颤振 stable 1.22.6。
在我添加的pubspec.yaml 文件中
dependencies:
flutter:
sdk: flutter
//.....
cloud_firestore: ^0.16.0
firebase_auth: ^0.20.0+1
firebase_core: ^0.7.0
firebase_messaging: ^8.0.0-dev.14
firebase_storage: ^7.0.0
flutter_local_notifications: ^4.0.0
google_sign_in: ^4.5.9
//.....
在我添加的 app-level ***build.gradle***
文件中
dependencies {
//.....
implementation 'com.android.support:multidex:1.0.3'
implementation platform('com.google.firebase:firebase-bom:26.5.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-inappmessaging-display:19.1.4'
//....
}
在我添加的 android-level ***build.gradle***
文件中
dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
}
我在我的 Application.kt
目录中添加了一个名为 android\app\src\main\kotlin\<package name>\
的文件。
Application.kt 文件
package com.sabikrahat.chitchat
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService
class Application: FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
// ...
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingBackgroundService.setPluginRegistrant(this)
}
override fun registerWith(registry:PluginRegistry) {
FlutterFirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
}
// ...
}
每当我添加这个 Application.kt
文件时,它都会给我一个错误
未解决的参考:FlutterFirebaseMessagingPlugin
我还更改了 android:name=".Application"
文件中的 manifest