作者:摩羯参议院1314 | 来源:互联网 | 2023-07-05 11:00
我正在尝试将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