Firebase“ .MyFirebaseInstanceIDService”和“ .java.MyFirebaseMessagingService”的未解析类

时间:2018-11-29 14:12:43

标签: android xml firebase firebase-cloud-messaging

我正在尝试将Firebase和FCM导入到我的android应用程序中,但是我得到

  

firebase“ .MyFirebaseInstanceIDService”的未解析类   尚未解决的firebase“ .java.MyFirebaseMessagingService”包

作为“错误”。当然,这不会阻止我的应用程序运行或构建,但是我根本无法在任何类中调用onTokenRefresh。因此,我认为这个问题使我无法使用Firebase。

这是我的应用程序版本;

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.northlandcaps.crisis_response"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            android {
                lintOptions {
                    checkReleaseBuilds false
                    // Or, if you prefer, you can continue to check for errors in release builds,
                    // but continue the build even when errors are found:
                    abortOnError false
                }
            }
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:mediarouter-v7:28.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
}
apply plugin: 'com.google.gms.google-services'

Screenshot of problem

1 个答案:

答案 0 :(得分:1)

这两个班级的样子:

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG = "MyFirebaseIIDService";

    @Override
    public void onTokenRefresh() {
        super.onTokenRefresh();

        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        sendRegistrationToServer(refreshedToken);
    }

    private void sendRegistrationToServer(String token) {
        // Add custom implementation, as needed.
    }
}

并且:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        RemoteMessage.Notification notification = remoteMessage.getNotification();
        Map<String, String> data = remoteMessage.getData();

        sendNotification(notification, data);
    }

    private void sendNotification(RemoteMessage.Notification notification, Map<String, String> data) {
        //Send notification
    }
}