This extension allows you to interact with Firebase in a uniform way for games on iOS and Android. The extension contains the core functionality to create and initialise a Firebase application. The various Firebase products are available in individual extensions:
The steps below taken from the official Google Firebase Guides.
google-services.json
file. You can download this file again at any time.GoogleService-Info.plist
file. You can download this file again at any time.You can use the extension in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:
https://github.com/defold/extension-firebase/archive/master.zip
Or point to the ZIP file of a specific release (recommended!).
generate_xml_from_google_services_json.py
or generate_xml_from_google_services_json.exe
(both from Firebase C++ SDK) to convert the previously downloaded google-services.json
to an Android resource XML:$ ./generate_xml_from_google_services_json.py -i google-services.json -o google-services.xml
google-services.xml
file to a folder structure like this:<project_root>
|
+-bundle
|
+-android
|
+-res
|
+-values
|
+-google-services.xml
game.project
and set the Bundle Resources
entry under the Project
section to /bundle
to match the folder created in the step above. Read more about the Bundle Resources
setting in the Defold manual.GoogleService-Info.plist
file to a folder structure like this:<project_root>
|
+-bundle
|
+-ios
|
+-GoogleService-Info.plist
game.project
and set the Bundle Resources
entry under the Project
section to /bundle
to match the folder created in the step above. Read more about the Bundle Resources
setting in the Defold manual.function init(self)
-- use firebase only if it is supported on the current platform
if firebase then
local ok, err = firebase.init()
if not ok then
print(err)
return
end
-- firebase is ready to use!
-- installation auth token can be used for configuring test devices for A/B tests
firebase.get_installation_auth_token(function(self, token)
print("installation auth token is " .. token)
end)
end
end
It is possible to override the values within GoogleService-Info.plist/google-services.xml by passing an optional table of options to init(). See the Defold manual for details but be aware of implications for analytics as described in Google’s Firebase documentation
The source code is available on GitHub
Did you spot an error or do you have a suggestion? Please let us know on GitHub!
GITHUB