簡體   English   中英

Class 在 firebase 消息 flutter 上未發現異常

[英]Class not found exception on firebase messaging flutter

從 firebase 發送雲通知時,我不斷收到 classNotFoundException。錯誤記錄它找不到。java.MyFirebaseMessagingService 我已經按照文檔進行了所有操作,但仍然找不到修復程序。 這是錯誤日志。 該應用程序打開正常,只有當我從 firebase 控制台發送消息進行測試時才會崩潰。

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

清單文件是。

<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>

我知道這個問題得到了回答,但最近我也陷入了同樣的問題,你的評論救了我。 謝謝。 我想提高您的答案對其他人的可見度。
要解決這個問題。 我剛剛刪除了這個代碼段,應用程序開始按預期工作:

 <service android:name=".service.MyFirebaseMessagingService" > <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>

我認為沒有必要明確聲明 class .service.MyFirebaseMessagingService因為您不需要為項目提及它。


按照firebase_messaging |中提供的所有說明進行操作。 Flutter Package

您可能會收到一個錯誤error: incompatible types: PluginRegistry cannot be converted to FlutterEngine GeneratedPluginRegistrant.register with (registry); 在遵循指示的同時。 要解決此錯誤,請遵循此線程中提供的說明: PluginRegistry 無法轉換為 FlutterEngine ,您不會遇到任何問題。

如果你想在后台/前台收聽消息,你不需要:

<service android:name=".service.MyFirebaseMessagingService">

Flutter Package 為您提供了其他工具來實現這一目標。

如果您想使用 Flutter 來收聽 Firebase PushNotifications(而不是本機方式),請嘗試使用FirebaseMessaging.onMessage.listen(...) dart function。

請記住,對於 android:

如果應用程序當前在前台,則默認情況下不顯示可見通知(但您可以實現)。

您可以在 Firebase flutter 文檔中查看如何使用通知處理:

https://firebase.flutter.dev/docs/messaging/notifications/

✌️

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM