Reputation: 504
I keep getting classNotFoundException when sending cloud notifications from firebase. The error logs that it can not find .java.MyFirebaseMessagingService I have followed everything as per the documentation but still can not find the fix. Here's the error log. The app opens fine and only crashes when I send a message from the firebase console to test.
java.lang.RuntimeException: Unable to instantiate service com.myapp.MyApp.MyFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "com.myapp.MyApp.MyFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/lib/arm64, /data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
E/AndroidRuntime( 5956): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3577)
E/AndroidRuntime( 5956): at android.app.ActivityThread.-wrap4(Unknown Source:0)
E/AndroidRuntime( 5956): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1862)
E/AndroidRuntime( 5956): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 5956): at android.os.Looper.loop(Looper.java:198)
E/AndroidRuntime( 5956): at android.app.ActivityThread.main(ActivityThread.java:7055)
E/AndroidRuntime( 5956): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5956): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:523)
E/AndroidRuntime( 5956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836)
E/AndroidRuntime( 5956): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.MyAppMyFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/lib/arm64, /data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
E/AndroidRuntime( 5956): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
E/AndroidRuntime( 5956): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime( 5956): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime( 5956): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3574)
E/AndroidRuntime( 5956): ... 8 more
And the manifest file is.
<application
android:name=".Application"
android:label="MyApp"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_logo" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name=".service.MyFirebaseMessagingService"
>
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
Upvotes: 2
Views: 4937
Reputation: 1
This is old but anyone currently facing this issue: You don't need to add that to your manifest file at all for flutter apps. Other answers state this but not clearly enough. I had the same issue and decided to delete the service element and it didn't crash as it did when I had the service element in my manifest file.
Upvotes: 0
Reputation: 2607
At the time of writing I am using flutter firebase_messaging
package v14.2.3.
I have opened the project in Android Studio and looked for the FlutterFirebaseMessagingService class in imported packages.
The fix that worked for me was using this class name io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService
in android/app/src/main/AndroidManifest.xml
:
<service
android:name="io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Upvotes: 0
Reputation: 75
If you want to listen for messages on Background / Foreground , You don't need :
<service android:name=".service.MyFirebaseMessagingService">
The Flutter Package gives to you other tools to make this happen.
If you want to use Flutter for listening to Firebase PushNotifications (and not the native way), try to use the FirebaseMessaging.onMessage.listen( ... ) dart function.
And remember, for android:
If the application is currently in the foreground, the visible notification is not presented by default (but you can make it happen).
You can check how to use the notification handling in the Firebase flutter documentation:
https://firebase.flutter.dev/docs/messaging/notifications/
✌️
Upvotes: 0
Reputation: 51
I know that the question is answered but recently I too got stuck in the same issue and your comment saved me. Thanks! I want to increase the visibility of your answer for others.
To resolve this issue. I just removed this code segment and the application started working as intended:
<service
android:name=".service.MyFirebaseMessagingService"
>
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
I think there is no need to explicitly declare class .service.MyFirebaseMessagingService
as you don't need to mention it for the projects.
Follow all the instructions provided in the firebase_messaging | Flutter Package.
You may get one error error: incompatible types: PluginRegistry cannot be converted to FlutterEngine GeneratedPluginRegistrant.register with (registry);
while following the instruction. To solve this error, follow the instructions provided in this thread: PluginRegistry cannot be converted to FlutterEngine
and you won't face any issues.
Upvotes: 5