类在firebase消息颤动上找不到异常
Posted
技术标签:
【中文标题】类在firebase消息颤动上找不到异常【英文标题】:Class not found exception on firebase messaging flutter 【发布时间】:2021-03-10 01:37:51 【问题描述】:从 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>
【问题讨论】:
尝试在app/build.gradle中添加implementation 'com.google.firebase:firebase-messaging:20.2.4'
谢谢,但我发现问题在于 Class 本身本来就不应该存在。
【参考方案1】:
我知道这个问题已经得到解答,但最近我也陷入了同样的问题,你的评论救了我。谢谢!我想提高您的答案对其他人的可见度。
要解决这个问题。我刚刚删除了这个代码段,应用程序开始按预期工作:<service
android:name=".service.MyFirebaseMessagingService"
>
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
我认为没有必要明确声明 .service.MyFirebaseMessagingService
类,因为您不需要在项目中提及它。
按照firebase_messaging | Flutter Package 中提供的所有说明进行操作。 在按照说明进行操作时,您可能会收到一个错误error: incompatible types: PluginRegistry cannot be converted to FlutterEngine GeneratedPluginRegistrant.register with (registry);
。要解决此错误,请遵循此线程中提供的说明:PluginRegistry cannot be converted to FlutterEngine
,您不会遇到任何问题。
【讨论】:
以上是关于类在firebase消息颤动上找不到异常的主要内容,如果未能解决你的问题,请参考以下文章
未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_core 上找不到方法 Firebase#initializeCore 的实
未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_messaging 上找不到方法 getToken 的实现)
.ClassNotFoundException:在路径上找不到类“com.google.firebase.provider.FirebaseInitProvider”:DexPathList
MissingPluginException(在通道 plugins.flutter.io/firebase_core 上找不到方法 Firebase#initializeCore 的实现)在测试中