Godot Version
4.5
Question
I’m developing a game and need to implement Firebase push notifications using the Godotx-Firebase plugin. However, I’m running into an issue where the plugin fails to read my google-services.json file. I’ve already configured the file path in Project > Export to both res:// and res://android/build/, but it still won’t work. Does anyone know how to properly link this file or fix this initialization error?
I’m following these steps: GitHub - godot-x/firebase: Modular Firebase integration for Godot with support for iOS and Android
#FirebaseService.gd
extends Node
var firebase_core
var messaging
func _ready() -> void:
print("Init firebase service...")
# Get all singletons
if Engine.has_singleton("GodotxFirebaseCore"):
print("Found GodotxFirebaseCore")
firebase_core = Engine.get_singleton("GodotxFirebaseCore")
firebase_core.core_initialized.connect(_on_core_initialized)
# Initialize Core first
if firebase_core:
firebase_core.initialize()
func _on_core_initialized(success: bool):
if success:
print("Firebase Core initialized!")
#messaging
if(Engine.get_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")
func _on_permission_granted():
print("Permission granted!")
func _on_token_received(token: String):
print("FCM Token: ", token)
func _on_apn_token_received(token: String):
# iOS only - Apple Push Notification device token
print("APN Token: ", token)
func _on_message_received(title: String, body: String):
print("Message: ", title, " - ", body)
func _on_error(message: String):
print("Error: ", message)
**Output
**
Init firebase service…
Found GodotxFirebaseCore
Firebase Core initialized!
Permission granted!
Error: Default FirebaseApp is not initialized in this process com.package.mygame. Make sure to call FirebaseApp.initializeApp(Context) first.
