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块中添加:
同时引入Firebase BOM管理依赖版本(示例版本可根据实际调整):id("com.google.gms.google-services")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>标签里添加:
替换为你实际的Application类名,否则系统不会触发你编写的onCreate方法。android:name=".YourCustomApplication" - 确认初始化代码无误:
在Application类的onCreate中,保证代码为:
此处override fun onCreate() { super.onCreate() FirebaseApp.initializeApp(this) }this为Application上下文,是初始化的正确参数。
内容的提问来源于stack exchange,提问作者Salil
相关产品推荐
相关产品推荐

