|
1 | | ---- |
2 | | -title: Defold Firebase documentation |
3 | | -brief: This manual covers how to setup and use Firebase products in Defold. |
4 | | ---- |
5 | | - |
6 | | -# Defold Firebase documentation |
7 | | - |
8 | | -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: |
9 | | - |
10 | | -* [Firebase Analytics](https://github.com/defold/extension-firebase-analytics) |
11 | | -* [Firebase Remote Config](https://github.com/defold/extension-firebase-remoteconfig) |
12 | | - |
13 | | - |
14 | | -## Setup |
15 | | -### 1. Firebase setup |
16 | | -The steps below taken from the [official Google Firebase Guides](https://firebase.google.com/docs/cpp/setup). |
17 | | - |
18 | | -#### 1.1 Create a Firebase project |
19 | | -* Create a Firebase project in the [Firebase console](https://console.firebase.google.com/), if you don't already have one. Click Add project. If you already have an existing Google project associated with your mobile app, select it from the Project name drop down menu. Otherwise, enter a project name to create a new project. |
20 | | -* Optional: Edit your Project ID. Your project is given a unique ID automatically, and it's used in publicly visible Firebase features such as database URLs and your Firebase Hosting subdomain. You can change it now if you want to use a specific subdomain. |
21 | | -* Follow the remaining setup steps and click Create project (or Add Firebase if you're using an existing project) to begin provisioning resources for your project. This typically takes a few minutes. When the process completes, you'll be taken to the project overview. |
22 | | - |
23 | | -#### 1.2 Setup for Android |
24 | | -* Click Add Firebase to your Android app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file. |
25 | | -* When prompted, enter your app's package name. It's important to enter the package name your app is using; this can only be set when you add an app to your Firebase project. |
26 | | -* During the process, you'll download a `google-services.json` file. You can download this file again at any time. |
27 | | - |
28 | | -#### 1.3 Setup for iOS |
29 | | -* Click Add Firebase to your iOS app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file. |
30 | | -* When prompted, enter your app's bundle ID. It's important to enter the bundle ID your app is using; this can only be set when you add an app to your Firebase project. |
31 | | -* During the process, you'll download a `GoogleService-Info.plist` file. You can download this file again at any time. |
32 | | - |
33 | | -### 2. Defold setup |
34 | | -#### 2.1 Add project dependencies |
35 | | -You can use the extension in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your game.project file and in the dependencies field under project add: |
36 | | - |
37 | | -[https://github.com/defold/extension-firebase/archive/master.zip](https://github.com/defold/extension-firebase/archive/master.zip) |
38 | | - |
39 | | -Or point to the ZIP file of a [specific release](https://github.com/defold/extension-firebase/releases) (recommended!). |
40 | | - |
41 | | -#### 2.2 Setup for Android |
42 | | - |
43 | | -* Run `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: |
44 | | - |
45 | | -``` |
46 | | -$ ./generate_xml_from_google_services_json.py -i google-services.json -o google-services.xml |
47 | | -``` |
48 | | - |
49 | | -* Copy the generated `google-services.xml` file to a folder structure like this: |
50 | | - |
51 | | -``` |
52 | | -<project_root> |
53 | | - | |
54 | | - +-bundle |
55 | | - | |
56 | | - +-android |
57 | | - | |
58 | | - +-res |
59 | | - | |
60 | | - +-values |
61 | | - | |
62 | | - +-google-services.xml |
63 | | -``` |
64 | | - |
65 | | -* Open `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](https://www.defold.com/manuals/project-settings/#_project). |
66 | | - |
67 | | - |
68 | | -#### 2.3 Setup for iOS |
69 | | -* Copy the generated `GoogleService-Info.plist` file to a folder structure like this: |
70 | | - |
71 | | -``` |
72 | | -<project_root> |
73 | | - | |
74 | | - +-bundle |
75 | | - | |
76 | | - +-ios |
77 | | - | |
78 | | - +-GoogleService-Info.plist |
79 | | -``` |
80 | | - |
81 | | -* Open `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](https://www.defold.com/manuals/project-settings/#_project). |
82 | | - |
83 | | - |
84 | | -## Usage |
85 | | - |
86 | | -```lua |
87 | | -function init(self) |
88 | | - -- use firebase only if it is supported on the current platform |
89 | | - if firebase then |
90 | | - local ok, err = firebase.init() |
91 | | - if not ok then |
92 | | - print(err) |
93 | | - return |
94 | | - end |
95 | | - |
96 | | - -- firebase is ready to use! |
97 | | - |
98 | | - -- installation auth token can be used for configuring test devices for A/B tests |
99 | | - firebase.get_installation_auth_token(function(self, token) |
100 | | - print("installation auth token is " .. token) |
101 | | - end) |
102 | | - end |
103 | | -end |
104 | | -``` |
105 | | - |
106 | | -## Source code |
107 | | - |
108 | | -The source code is available on [GitHub](https://github.com/defold/extension-firebase) |
109 | | - |
110 | | - |
111 | | - |
112 | | -## API reference |
| 1 | +--- |
| 2 | +title: Defold Firebase documentation |
| 3 | +brief: This manual covers how to setup and use Firebase products in Defold. |
| 4 | +--- |
| 5 | + |
| 6 | +# Defold Firebase documentation |
| 7 | + |
| 8 | +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: |
| 9 | + |
| 10 | +* [Firebase Analytics](https://github.com/defold/extension-firebase-analytics) |
| 11 | +* [Firebase Remote Config](https://github.com/defold/extension-firebase-remoteconfig) |
| 12 | + |
| 13 | + |
| 14 | +## Setup |
| 15 | +### 1. Firebase setup |
| 16 | +The steps below taken from the [official Google Firebase Guides](https://firebase.google.com/docs/cpp/setup). |
| 17 | + |
| 18 | +#### 1.1 Create a Firebase project |
| 19 | +* Create a Firebase project in the [Firebase console](https://console.firebase.google.com/), if you don't already have one. Click Add project. If you already have an existing Google project associated with your mobile app, select it from the Project name drop down menu. Otherwise, enter a project name to create a new project. |
| 20 | +* Optional: Edit your Project ID. Your project is given a unique ID automatically, and it's used in publicly visible Firebase features such as database URLs and your Firebase Hosting subdomain. You can change it now if you want to use a specific subdomain. |
| 21 | +* Follow the remaining setup steps and click Create project (or Add Firebase if you're using an existing project) to begin provisioning resources for your project. This typically takes a few minutes. When the process completes, you'll be taken to the project overview. |
| 22 | + |
| 23 | +#### 1.2 Setup for Android |
| 24 | +* Click Add Firebase to your Android app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file. |
| 25 | +* When prompted, enter your app's package name. It's important to enter the package name your app is using; this can only be set when you add an app to your Firebase project. |
| 26 | +* During the process, you'll download a `google-services.json` file. You can download this file again at any time. |
| 27 | + |
| 28 | +#### 1.3 Setup for iOS |
| 29 | +* Click Add Firebase to your iOS app and follow the setup steps. If you're importing an existing Google project, this may happen automatically and you can just download the config file. |
| 30 | +* When prompted, enter your app's bundle ID. It's important to enter the bundle ID your app is using; this can only be set when you add an app to your Firebase project. |
| 31 | +* During the process, you'll download a `GoogleService-Info.plist` file. You can download this file again at any time. |
| 32 | + |
| 33 | +### 2. Defold setup |
| 34 | +#### 2.1 Add project dependencies |
| 35 | +You can use the extension in your own project by adding this project as a [Defold library dependency](http://www.defold.com/manuals/libraries/). Open your game.project file and in the dependencies field under project add: |
| 36 | + |
| 37 | +[https://github.com/defold/extension-firebase/archive/master.zip](https://github.com/defold/extension-firebase/archive/master.zip) |
| 38 | + |
| 39 | +Or point to the ZIP file of a [specific release](https://github.com/defold/extension-firebase/releases) (recommended!). |
| 40 | + |
| 41 | +#### 2.2 Setup for Android |
| 42 | + |
| 43 | +* Run `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: |
| 44 | + |
| 45 | +``` |
| 46 | +$ ./generate_xml_from_google_services_json.py -i google-services.json -o google-services.xml |
| 47 | +``` |
| 48 | + |
| 49 | +* Copy the generated `google-services.xml` file to a folder structure like this: |
| 50 | + |
| 51 | +``` |
| 52 | +<project_root> |
| 53 | + | |
| 54 | + +-bundle |
| 55 | + | |
| 56 | + +-android |
| 57 | + | |
| 58 | + +-res |
| 59 | + | |
| 60 | + +-values |
| 61 | + | |
| 62 | + +-google-services.xml |
| 63 | +``` |
| 64 | + |
| 65 | +* Open `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](https://www.defold.com/manuals/project-settings/#_project). |
| 66 | + |
| 67 | + |
| 68 | +#### 2.3 Setup for iOS |
| 69 | +* Copy the generated `GoogleService-Info.plist` file to a folder structure like this: |
| 70 | + |
| 71 | +``` |
| 72 | +<project_root> |
| 73 | + | |
| 74 | + +-bundle |
| 75 | + | |
| 76 | + +-ios |
| 77 | + | |
| 78 | + +-GoogleService-Info.plist |
| 79 | +``` |
| 80 | + |
| 81 | +* Open `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](https://www.defold.com/manuals/project-settings/#_project). |
| 82 | + |
| 83 | + |
| 84 | +## Usage |
| 85 | + |
| 86 | +```lua |
| 87 | +function init(self) |
| 88 | + -- use firebase only if it is supported on the current platform |
| 89 | + if firebase then |
| 90 | + local ok, err = firebase.init() |
| 91 | + if not ok then |
| 92 | + print(err) |
| 93 | + return |
| 94 | + end |
| 95 | + |
| 96 | + -- firebase is ready to use! |
| 97 | + |
| 98 | + -- installation auth token can be used for configuring test devices for A/B tests |
| 99 | + firebase.get_installation_auth_token(function(self, token) |
| 100 | + print("installation auth token is " .. token) |
| 101 | + end) |
| 102 | + end |
| 103 | +end |
| 104 | +``` |
| 105 | + |
| 106 | +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](https://defold.com/extension-firebase/api/) for details but be aware of implications for analytics as described in Google's [Firebase documentation](https://firebase.google.com/docs/projects/multiprojects#reliable-analytics) |
| 107 | + |
| 108 | +## Source code |
| 109 | + |
| 110 | +The source code is available on [GitHub](https://github.com/defold/extension-firebase) |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +## API reference |
0 commit comments