gpt4 book ai didi

android - 在 flutter 中创建 Application.kt 的最佳方法是什么

转载 作者:行者123 更新时间:2023-12-05 00:02:06 24 4
gpt4 key购买 nike

我的 Application.kt 文件是这样的。找不到更改 PluginRegistrantCallback 和 FlutterFirebaseMessagingService 的方法

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?) {
io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(
registry?.registrarFor(
"io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
ext.kotlin_version = '1.5.10'
当我构建项目时,我得到了这种类型的错误
e: /-/Application.kt: (6, 27): Unresolved reference: firebasemessaging
e: /-/Application.kt: (12, 9): Unresolved reference: FlutterFirebaseMessagingService
e: /-/Application.kt: (16, 28): Unresolved reference: firebasemessaging

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 13s
Exception: Gradle task assembleDebug failed with exit code 1

最佳答案

尝试这个,

package your_package_name

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry

import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin

class Application() : FlutterApplication(), PluginRegistry.PluginRegistrantCallback {
override fun registerWith(registry: PluginRegistry?) {
val key: String? = FlutterFirebaseMessagingPlugin::class.java.canonicalName
if (!registry?.hasPlugin(key)!!) {
FlutterFirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin"));
}
}
}

关于android - 在 flutter 中创建 Application.kt 的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70848688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com