Search code examples
androidparse-platformfirebase-cloud-messagingandroid-manifest

com.parse.fcm.ParseFirebaseInstanceIdService' is not assignable to 'android.app.Service'


To start off, I looked at this post and this post, asking similar questions, but both of them don't seem to solve the problem I am having.

What am I trying to do?

I am upgrading an application from Google Cloud Messaging to Firebase Cloud Messaging using a Parse server. There are a couple of tutorials on this (I'm using this one), all specifying that you need to add the following lines in your manifest:

<service
    android:name="com.parse.fcm.ParseFirebaseInstanceIdService"
    android:exported="true">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>

What is going wrong?

However, if I do so I get the error com.parse.fcm.ParseFirebaseInstanceIdService' is not assignable to 'android.app.Service. I cannot seem to find any resource on how to solve this, or whether it is an issue at all for receiving any messages.

My Project gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.3'  // Google Services plugin
    }
}
allprojects {
    repositories {
        google()
    }
}

And my Module gradle file:


android {
    compileSdkVersion 28
    lintOptions {
        abortOnError false
    }

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        multiDexEnabled true
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

buildscript {
    repositories {
        mavenCentral()
        google()
    }
}

repositories {
    mavenCentral()
    google()
    jcenter()
    maven {
        url "https://s3.amazonaws.com/repo.commonsware.com"
    }
    maven {
        url 'https://jitpack.io'
    }
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    maven {
        url 'https://jitpack.io'
    }
    google()
}

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.mcxiaoke.volley:library:1.0.19'
    implementation 'com.parse:parse-android:1.17.3'
    implementation 'com.parse:parse-fcm-android:1.17.3' // Firebase cloud messaging
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'com.google.firebase:firebase-messaging:20.0.1'
    implementation 'com.github.mtotschnig:stickylistheaders:2.7.1'
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
}

apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin 

Any ideas what is going wrong and how to fix it?


Solution

  • Md. Asaduzzaman's answer was helpful, thanks for that.

    Just to add to it, make sure to override the onNewToken() method in your custom FirebaseMessagingService, like in this tutorial. (I just found the tutorial and thought it would be nice to share it if others are stuck with the same problem).

    @Override
    public void onNewToken(String s) {
        super.onNewToken(s);
        Log.e("NEW_TOKEN",s);
    }
    

    We need to override it because:

    "Class FirebaseInstanceIdService: This class was deprecated. In favour of overriding onNewToken in FirebaseMessagingService.

    Once that has been implemented, this service can be safely removed."