Search code examples
firebasekotlinbuild.gradlegradle-kotlin-dslkmm

Why do I get "Unresolved reference: platform" when using the firebase-bom dependency with KMM


When I attempt to add the Firebase-bom dependency using the following block in a Kotlin Multiplatform Mobile (KMM) project's shared module, the word platform appears in red error text and the Gradle build fails with "Unresolved reference: platform." How can I resolve this so it builds correctly?

        val androidMain by getting {
            dependencies {
                implementation(platform("com.google.firebase:firebase-bom:28.0.1"))
                implementation("com.google.firebase:firebase-analytics-ktx")
            }
        }

Solution

  • The answer lies in KT-40489.

    The platform() function used to import the Firebase Bill of Materials is not available in Kotlin Multiplatform plugin’s KotlinDependencyHandler but only in Gradle’s standard DependencyHandler. It also does not seem that a fix is coming soon. As a result, you need to specify Gradle's handler explicitly.

    Here are two workarounds:

    val androidMain by getting {
        dependencies {
            implementation(project.dependencies.platform("..."))
        }
    }
    

    OR

    val androidMain by getting {
        dependencies {
            "jvmMainImplementation"(platform("...))
        }
    }