1

I have an app that I want to add Firebase Cloud Messaging. Now, when configuring the services, I am getting this error in my Kotlin file:

Cannot resolve symbol 'FirebaseMessagingService'

When I try to add dependency on com.google.firbase:firebase-messaging and import, the dependency is being added into the project level and that is giving an error. Mind the dependency has already been downloaded in the app level, but its not being recognised by the Kotlin code.

I'm integrating Firebase Cloud Messaging into my Flutter project (Android part) and trying to extend FirebaseMessagingService in Kotlin.

However, I keep getting this error:

Unresolved reference: FirebaseMessagingService

Here’s my service class:

package com.swiftdrop.app;

import com.google.firebase.messaging.FirebaseMessagingService;

class NotificationService:FirebaseMessagingService() {
}

Here is my app level gradle:

plugins {
    id("com.android.application")
    id("com.google.gms.google-services")
    id("org.jetbrains.kotlin.android")
    id("dev.flutter.flutter-gradle-plugin")
}

android {
    namespace = "com.swiftdrop.app"
    compileSdk = 36
    ndkVersion = "27.2.12479018"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
        isCoreLibraryDesugaringEnabled = true
    }

    kotlinOptions {
        jvmTarget = "17"
    }

    defaultConfig {
        applicationId = "com.swiftdrop.app"
        minSdk = 23
        targetSdk = 36
        versionCode = flutter.versionCode
        versionName = flutter.versionName
        multiDexEnabled = true
    }

    buildTypes {
        release {
            signingConfig = signingConfigs.getByName("debug")
        }
    }

    buildFeatures {
        viewBinding = true
    }
}

dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")

    implementation(platform("com.google.firebase:firebase-bom:34.5.0"))
    implementation("com.google.firebase:firebase-messaging-ktx")
    implementation("com.google.firebase:firebase-appcheck-playintegrity")
    implementation("com.google.firebase:firebase-appcheck-debug")
    implementation("com.google.android.gms:play-services-recaptcha:17.1.0")

    implementation("com.squareup.retrofit2:retrofit:2.11.0")
    implementation("com.squareup.retrofit2:converter-moshi:2.11.0")
    implementation(kotlin("stdlib"))
}

flutter {
    source = "../.."
}

project level

// android/build.gradle.kts

plugins {
    id("com.android.application") version "8.11.0" apply false
    id("com.android.library") version "8.11.2" apply false
    id("org.jetbrains.kotlin.android") version "1.9.23" apply false
    id("com.google.gms.google-services") version "4.4.4" apply false
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
rootProject.layout.buildDirectory.value(newBuildDir)

subprojects {
    val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
    project.layout.buildDirectory.value(newSubprojectBuildDir)
    project.evaluationDependsOn(":app")
}

tasks.register<Delete>("clean") {
    delete(rootProject.layout.buildDirectory)
}

1 Answer 1

3

FirebaseMessagingService reads:

IMPORTANT: In July 2025, we stopped releasing new versions of KTX modules, and we removed the KTX libraries from the Firebase Android BoM (v34.0.0). If you use KTX APIs from the previously released KTX modules, we recommend that you migrate your app to use KTX APIs from the main modules instead.

Which leads to: How to migrate to use KTX APIs from the main modules

Which means, one has to remove the -ktx from the dependency notation:

implementation("com.google.firebase:firebase-messaging")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.