热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Flutterfirebase_messagingandroid应用程序在.getToken()调用时崩溃

我正在尝试将firebase_messaging包与我的flutter应用程序集成。通常它可以正常工作(版本7.0.3)我正在使用的代码(见下文)但是自从发布了空安全版本我的代码不再

我正在尝试将firebase_messaging包与我的 flutter 应用程序集成。通常它可以正常工作(版本 7.0.3)我正在使用的代码(见下文)但是自从发布了空安全版本我的代码不再工作了。我想知道是否有人可以帮助我找出我做错了什么?

错误导致代码

try {
fcmToken = await _firebaseMessaging.getToken();
} catch (error) {
print(error);
}

错误输出

E/AndroidRuntime( 8942): java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/Metadata;
E/AndroidRuntime( 8942): at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.lambda$getToken$1$FlutterFirebaseMessagingPlugin(FlutterFirebaseMessagingPlugin.java:165)
E/AndroidRuntime( 8942): at io.flutter.plugins.firebase.messaging.-$$Lambda$FlutterFirebaseMessagingPlugin$p8YQXDuFBNIxl8PFaPCQJtYc3sw.call(Unknown Source:4)
E/AndroidRuntime( 8942): at com.google.android.gms.tasks.zzv.run(Unknown Source:2)
E/AndroidRuntime( 8942): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime( 8942): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime( 8942): at java.lang.Thread.run(Thread.java:923)
E/AndroidRuntime( 8942): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.Metadata" on path: DexPathList[[zip file "/data/app/~~uCa7QFzhvu5i_TZpnqat0w==/com.example.****-1cbY-LKuCoOsfZybV-Gq6g==/base.apk"],nativeLibraryDirectories=[/data/app/~~uCa7QFzhvu5i_TZpnqat0w==/com.example.****-1cbY-LKuCoOsfZybV-Gq6g==/lib/x86, /data/app/~~uCa7QFzhvu5i_TZpnqat0w==/com.example.****-1cbY-LKuCoOsfZybV-Gq6g==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]
E/AndroidRuntime( 8942): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
E/AndroidRuntime( 8942): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime( 8942): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime( 8942): ... 6 more

app -> src -> main -> kotlin -> Application.kt

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

应用程序 -> src -> main -> kotlin -> MainActivity.kt

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

回答

对我来说,它通过降级从

com.google.firebase:firebase-bom:28.0.1

com.google.firebase:firebase-bom:27.0.0

提示:这是这些版本的临时解决方案:

firebase_messaging: ^9.1.4

firebase_core: ^1.1.1






推荐阅读
author-avatar
摩羯参议院1314
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有