【问题标题】:java.lang.RuntimeException: Unable to instantiate service com.samriddh.partner.java.MyFirebaseMessagingServicejava.lang.RuntimeException:无法实例化服务 com.samriddh.partner.java.MyFirebaseMessagingService
【发布时间】:2020-09-20 13:36:04
【问题描述】:

我正在使用 Firebase 消息传递,当我收到来自 firebase 控制台的通知时,我的应用程序因此异常而关闭 任何人都可以请建议我该怎么做我正在与这个问题作斗争超过 2 小时

我的 firebase 消息版本是 firebase_messaging: ^6.0.16

我对 firebaseMessaging 的依赖是 implementation 'com.google.firebase:firebase-messaging:20.2.3'

java.lang.RuntimeException:无法实例化服务 com.samriddh.partner.java.MyFirebaseMessagingService:java.lang.ClassNotFoundException:在路径上找不到类“com.samriddh.partner.java.MyFirebaseMessagingService”:DexPathList [ [压缩文件“/system/framework/org.apache.http.legacy.boot.jar”,压缩文件“/data/app/com.samriddh.partner-ameKbTimiGALFObiP3aUeg==/base.apk”],nativeLibraryDirectories=[/ data/app/com.samriddh.partner-ameKbTimiGALFObiP3aUeg==/lib/arm64, /data/app/com.samriddh.partner-ameKbTimiGALFObiP3aUeg==/base.apk!/lib/arm64-v8a, /system/lib64]]

我的android Manifest.xml 文件是

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.samriddh.partner">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
         <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <application
        android:name=".Application"
        android:label="samriddh partner"
        android:icon="@mipmap/launcher_icon">
        <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: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"
              />
          <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
          <intent-filter>
              <action android:name="android.intent.action.MAIN"/>
              <category android:name="android.intent.category.LAUNCHER"/>
          </intent-filter>
        </activity>

        <meta-data android:name="com.google.android.geo.API_KEY"
          android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>

        <uses-library android:name="org.apache.http.legacy" android:required="false"/>
        
        <meta-data android:name="flutterEmbedding" android:value="2" />
        
        <service android:name=".service.MyFirebaseMessagingService"> </service>
        
        <service android:name=".java.MyFirebaseMessagingService" android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>    
        </service>    
    </application>
</manifest>

我的 Application.kt 文件是

package com.samriddh.partner

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService

class Application : FlutterApplication(), PluginRegistrantCallback {

    override fun onCreate() {
        super.onCreate()
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    override fun registerWith(registry: PluginRegistry?) {
        io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
    }
}

【问题讨论】:

    标签: android firebase firebase-cloud-messaging


    【解决方案1】:

    公开课程为我解决了问题。

    【讨论】:

      【解决方案2】:

      错误告诉您,Android 找不到您声明的完整类名“com.samriddh.partner.java.MyFirebaseMessagingService”的服务。要么您从未添加过此类,要么您在清单中告诉 Android 错误的名称。

      【讨论】:

      • 你能告诉我我现在要做什么吗?我是新手,我可以运行我的应用程序,但是当应用程序收到通知时,它会意外关闭
      • 听起来您没有完成将 FCM 集成到您的应用中的文档说明。
      【解决方案3】:

      检查顶部的包裹是否正确。 例如。

      package com.samriddh.partner
      

      如果你从一个例子中复制/粘贴(像我一样),它有一些其他的包。

      package com.google.firebase.quickstart.fcm.kotlin
      

      【讨论】:

        【解决方案4】:
            <!-- THIS IS CRASHING THE PUSH NOTIFICATION -->    
            <!-- <service
                android:name=".java.MyFirebaseMessagingService"
                android:exported="false">
                <intent-filter>
                    <action android:name="com.google.firebase.MESSAGING_EVENT" />
                </intent-filter>
            </service> -->
        

        【讨论】:

          猜你喜欢
          • 2012-08-04
          • 2014-05-07
          • 2013-05-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-08
          • 1970-01-01
          相关资源
          最近更新 更多