Android无法扩展Firebase Messaging Service

Sal*_*aai 17 java android firebase-cloud-messaging

我正在尝试在我的应用程序中实现Firebase云消息传递,我已经实现了所有设置以使用此服务,但是当我尝试FirebaseMessagingService在我的课程中进行扩展时,它给了我错误,它根本找不到它,我甚至无法import com.google.firebase.messaging.FirebaseMessagingService如图所示:

在此输入图像描述

我添加了所有必需的代码:我将其添加到app gradle

compile 'com.google.firebase:firebase-core:9.4.0' 
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

这对模块gradle:

classpath 'com.google.gms:google-services:3.0.0'
Run Code Online (Sandbox Code Playgroud)

这是清单代码:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service
        android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
    </service>
    <service
        android:name=".MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>
</application>
Run Code Online (Sandbox Code Playgroud)

我将谷歌json文件添加到应用程序.所以,如果有人能帮助我,请

ElD*_*ino 35

如果要使用消息传递,则必须添加消息传递模块.现在你只添加了核心模块.

所以继续并包括

compile 'com.google.firebase:firebase-messaging:9.4.0'
Run Code Online (Sandbox Code Playgroud)

所有可用的模块都可以在https://firebase.google.com/docs/android/setup的底部找到

  • 另请注意,无需手动包含核心依赖项.添加firebase-messaging时,它将被传递. (4认同)