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

Godot 4.5中Godotx-Firebase无法读取google-services.json求助

解决Godot 4.5 + Godotx-Firebase插件中google-services.json读取失败与Firebase初始化错误

针对你遇到的Default FirebaseApp is not initialized错误,以下是具体的修复步骤:

1. 确认google-services.json的路径与导出配置

  • 确保google-services.json文件放置在项目根目录(res://),文件名完全正确(小写、无拼写错误)
  • 打开Godot的Project > Export > Android配置,在Custom Build区域:
    • 勾选Use Custom Build
    • 将google-services.json的路径设置为res://google-services.json,不要同时设置多个路径

2. 验证插件的Android依赖配置

打开Godotx-Firebase插件的Android相关配置文件,确认以下内容:

  • 插件根目录的android/build.gradle中,已添加Google Services插件依赖:
    buildscript {
        dependencies {
            classpath 'com.google.gms:google-services:4.4.1'
        }
    }
    
  • 模块级android/app/build.gradle文件末尾,已添加Google Services插件应用:
    apply plugin: 'com.google.gms.google-services'
    

3. 调整代码初始化顺序

虽然Core初始化信号返回成功,但可能存在异步延迟问题,修改_on_core_initialized函数,添加短暂延迟后再初始化Messaging:

func _on_core_initialized(success: bool):
    if success:
        print("Firebase Core initialized!")
        # 等待0.5秒确保FirebaseApp完全初始化
        await get_tree().create_timer(0.5).timeout
        
        #messaging
        if(Engine.has_singleton("GodotxFirebaseMessaging")):
            messaging = Engine.get_singleton("GodotxFirebaseMessaging")
            # Connect to signals
            messaging.messaging_permission_granted.connect(_on_permission_granted)
            messaging.messaging_token_received.connect(_on_token_received)
#           messaging.messaging_apn_token_received.connect(_on_apn_token_received)  # iOS only
            messaging.messaging_message_received.connect(_on_message_received)
            messaging.messaging_error.connect(_on_error)
            # Request notification permission (this also registers for APNs on iOS)
            messaging.request_permission()
            # Get FCM token
            messaging.get_token()
            # Get APNs token (iOS only - call after request_permission)
            #if OS.get_name() == "iOS":
            #   messaging.get_apns_token()
    else:
        print("Firebase Core initialization failed")

4. 清理缓存并重新导出

  • 删除项目目录下的.godot/export/android缓存文件夹
  • 重新导出Android APK包,安装到设备上测试

5. 检查包名一致性

确认google-services.json文件中的client > client_info > android_client_info > package_name值,与Godot导出设置中的Application ID完全一致,包括大小写和域名结构


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.11 18:42:35