在 KMM 中使用 firebase-bom 依赖项时,为什么会出现“未解析的引用:平台”

col*_*ots 9 kotlin firebase build.gradle gradle-kotlin-dsl kmm

当我尝试在 Kotlin Multiplatform Mobile (KMM) 项目的共享模块中使用以下块添加 Firebase-bom 依赖项时,该词platform出现在红色错误文本中,并且 Gradle 构建失败并显示“未解析的引用:平台”。我该如何解决这个问题以便正确构建?

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

col*_*ots 22

答案就在KT-40489中。

\n

platform()用于导入 Firebase 物料清单的函数在 Kotlin Multiplatform plugin\xe2\x80\x99s 中不可用,但KotlinDependencyHandler仅在 Gradle\xe2\x80\x99s standard 中可用DependencyHandler。修复似乎也不会很快到来。因此,您需要显式指定 Gradle 的处理程序。

\n

这里有两个解决方法:

\n
val androidMain by getting {\n    dependencies {\n        implementation(project.dependencies.platform("..."))\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

或者

\n
val androidMain by getting {\n    dependencies {\n        "jvmMainImplementation"(platform("...))\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n