Android 无法扩展 Firebase 消息服务

Android can't extend Firebase Messaging Service

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

我已经添加了所有需要的代码: 我将此添加到应用 gradle

compile 'com.google.firebase:firebase-core:9.4.0' 
apply plugin: 'com.google.gms.google-services'

然后这个到模块 gradle:

classpath 'com.google.gms:google-services:3.0.0'

这是清单代码:

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

并且我将 google json 文件添加到应用程序。 所以如果有人能帮助我,请

如果你想使用消息,你必须添加消息模块。现在您只添加了核心模块。

所以继续添加

compile 'com.google.firebase:firebase-messaging:9.4.0'

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

的底部找到