firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.74k stars 3.98k forks source link

firebase_messaging: including 15.0.2 in pubspec.yaml causes crash #13009

Closed wabash9000 closed 5 months ago

wabash9000 commented 5 months ago

Is there an existing issue for this?

Which plugins are affected?

Messaging

Which platforms are affected?

Android

Description

put 'firebase_messaging: ^15.0.2' into pubspec.yaml and app crashes shortly after launch. Connection to firebase works because crashlytics captured 2 errors from the app crashing.

Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/messaging/FirebaseMessaging; at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.lambda$getPluginConstantsForFirebaseApp$15(FlutterFirebaseMessagingPlugin.java:597) at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin$$ExternalSyntheticLambda0.run(:4) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012)

And

Caused by java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.messaging.FirebaseMessaging" on path: DexPathList[[zip file "/data/app/V0khmML6cCc3Vigtvpf8FQ==/com.dc.teststrip.h2ochk-joragzkGy-GPk2PXWDnbFg==/base.apk"],nativeLibraryDirectories=[/data/app/V0khmML6cCc3Vigtvpf8FQ==/com.dc.teststrip.h2ochk-joragzkGy-GPk2PXWDnbFg==/lib/arm64, /data/app/~~V0khmML6cCc3Vigtvpf8FQ==/com.dc.teststrip.h2ochk-joragzkGy-GPk2PXWDnbFg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.lambda$getPluginConstantsForFirebaseApp$15(FlutterFirebaseMessagingPlugin.java:597) at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin$$ExternalSyntheticLambda0.run(:4) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012)

I'm not calling anything from messaging yet, just including it in the pubspec file causes the crash. App runs without issue after I add a # to the start of the line to no longer include messaging.

Reproducing the issue

add the line firebase_messaging: ^15.0.2 to pubspec.yaml

Firebase Core version

3.1.1

Flutter Version

3.19.6

Relevant Log Output

Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/messaging/FirebaseMessaging;
at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.lambda$getPluginConstantsForFirebaseApp$15(FlutterFirebaseMessagingPlugin.java:597)
at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin$$ExternalSyntheticLambda0.run(:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)

And

  Caused by java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.messaging.FirebaseMessaging" on path: DexPathList[[zip file "/data/app/~~V0khmML6cCc3Vigtvpf8FQ==/com.dc.teststrip.h2ochk-joragzkGy-GPk2PXWDnbFg==/base.apk"],nativeLibraryDirectories=[/data/app/~~V0khmML6cCc3Vigtvpf8FQ==/com.dc.teststrip.h2ochk-joragzkGy-GPk2PXWDnbFg==/lib/arm64, /data/app/~~V0khmML6cCc3Vigtvpf8FQ==/com.dc.teststrip.h2ochk-joragzkGy-GPk2PXWDnbFg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.lambda$getPluginConstantsForFirebaseApp$15(FlutterFirebaseMessagingPlugin.java:597)
at io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin$$ExternalSyntheticLambda0.run(:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)

Flutter dependencies

camera: ^0.11.0+1 flutter_vision: ^1.1.4 cupertino_icons: ^1.0.6 google_ml_kit: ^0.18.0 opencv_dart: ^1.0.3+2 image: ^4.2.0
intl: ^0.19.0 flutter_pdfview: ^1.3.2 path_provider: ^2.1.3 dio: ^5.4.3+1 simple_database: ^2.0.1 restart_app: ^1.2.1

Firebase Packages

firebase_core: ^3.1.1 firebase_crashlytics: ^4.0.2 firebase_analytics: ^11.1.0 firebase_performance: ^0.10.0+2

firebase_messaging: ^15.0.2

Additional context and comments

No response

TarekkMA commented 5 months ago

@wabash9000 Thank you for reporting this issue. I've run the FlutterFire messaging example app found here, which uses firebase_messaging: ^15.0.2 in pubspec.yaml. The app ran without any crashes. Can you share a minimal reproducible example app where this issue occurs?

wabash9000 commented 5 months ago

Alright I made a brand new flutter app, made a new firebase project, put firebase_core and firebase_messager in the pubspec.yaml file, configured the flutter project from the Firebasse CLI. Ran the project and it ran just fine and was able to get a instance token from FirebaseMessaging.

I'm trying to add the dependencies from my test project one by one to the test app and see where it fails. I added all of them and ran into an error that is probably the cause of this issue. Execution failed for task ':app:checkDebugDuplicateClasses'.

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable Duplicate class com.google.firebase.iid.FirebaseInstanceIdReceiver found in modules jetified-firebase-iid-20.1.5-runtime (com.google.firebase:firebase-iid:20.1.5) and jetified-firebase-messaging-24.0.0-runtime (com.google.firebase:firebase-messaging:24.0.0)

I found a workaround for that issue by adding configurations { all*.exclude group: 'com.google.firebase', module: 'firebase-messaging' } to my app build.gradle, but that is likely the cause of this issue.

With a bit of trial and error, that issue is caused by including google_ml_kit in the pubspec.yaml, comment it out and the test project builds without issue. So there is a duplicate class conflict between google_ml_kit and firebase_messaging

wabash9000 commented 5 months ago

I was able to remove the Google_ml_kit from my app and after a clean/get and rebuild I was able to get it to run without crashing. The ml kit worked in my initial tests but it was no longer working because the data matrix codes I was using it to detect were too small to pick up in the camera feed. I'm going to be converting the app to use tensorflow so I don't need the google ml kit anymore. Still a valid issue that this library has conflicts with the Google ML Kit, I just don't need it anymore.

TarekkMA commented 5 months ago

@wabash9000 Glad that you were able to solve this issue. This might be a multidex issue, and you may need to enable it to fix the problem.

Closing this as I think it's a multidex issue. Please feel free to open a new issue if this is not the case.