You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Compose Multiplatform项目中google-services.json应放置在何处?

KMM项目中google-services.json的正确放置位置及初始化异常解决

正确位置

google-services.json必须放在androidApp模块的src/main目录下——这是Android专属模块的主资源目录,composeApp作为跨平台共享模块,无法识别该配置文件。

初始化异常排查(已添加initializeApp仍报错)

  • 确保androidApp模块的build.gradle.kts中应用了Google Services插件:
    在plugins块中添加:
    id("com.google.gms.google-services")
    
    同时引入Firebase BOM管理依赖版本(示例版本可根据实际调整):
    dependencies {
        implementation(platform("com.google.firebase:firebase-bom:32.7.0"))
        // 根据需求添加具体Firebase库,比如Analytics
        implementation("com.google.firebase:firebase-analytics-ktx")
    }
    
  • 检查自定义Application类是否在AndroidManifest中注册:
    在androidApp/src/main/AndroidManifest.xml的<application>标签里添加:
    android:name=".YourCustomApplication"
    
    替换为你实际的Application类名,否则系统不会触发你编写的onCreate方法。
  • 确认初始化代码无误:
    在Application类的onCreate中,保证代码为:
    override fun onCreate() {
        super.onCreate()
        FirebaseApp.initializeApp(this)
    }
    
    此处this为Application上下文,是初始化的正确参数。

内容的提问来源于stack exchange,提问作者Salil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 14:55:55