1
1
# Firebase Android Open Source Development
2
2
3
- This repository contains the source code for all Android Firebase SDKs except
4
- Analytics and Auth.
3
+ This repository contains the source code for all Android Firebase SDKs except Analytics and Auth.
5
4
6
- Firebase is an app development platform with tools to help you build, grow and
7
- monetize your app. More information about Firebase can be found at
8
- https://firebase.google.com .
5
+ Firebase is an app development platform with tools to help you build, grow and monetize your app.
6
+ More information about Firebase can be found at https://firebase.google.com .
9
7
10
8
## Table of contents
11
9
@@ -15,10 +13,8 @@ https://firebase.google.com.
15
13
1 . [ Integration Testing] ( #integration-testing )
16
14
1 . [ Proguarding] ( #proguarding )
17
15
1 . [ APIs used via reflection] ( #APIs-used-via-reflection )
18
- 1 . [ APIs intended for developer
19
- consumption] ( #APIs-intended-for-developer-consumption )
20
- 1 . [ APIs intended for other Firebase
21
- SDKs] ( #APIs-intended-for-other-firebase-sdks )
16
+ 1 . [ APIs intended for developer consumption] ( #APIs-intended-for-developer-consumption )
17
+ 1 . [ APIs intended for other Firebase SDKs] ( #APIs-intended-for-other-firebase-sdks )
22
18
1 . [ Publishing] ( #publishing )
23
19
1 . [ Dependencies] ( #dependencies )
24
20
1 . [ Commands] ( #commands )
@@ -27,23 +23,22 @@ https://firebase.google.com.
27
23
28
24
## Getting Started
29
25
30
- * Install the latest Android Studio (should be Meerkat | 2024.3.1 or later)
31
- * Clone the repo (
` git clone --recurse-submodules [email protected] :firebase/firebase-android-sdk.git ` )
32
- * When cloning the repo, it is important to get the submodules as well. If
33
- you have already cloned the repo without the submodules, you can update the
34
- submodules by running ` git submodule update --init --recursive ` .
35
- * Import the firebase-android-sdk gradle project into Android Studio using the
36
- ** Import project(Gradle, Eclipse ADT, etc.)** option.
37
- * ` firebase-crashlytics-ndk ` must be built with NDK 21. See
38
- [ firebase-crashlytics-ndk] ( firebase-crashlytics-ndk/README.md ) for more
39
- details.
26
+ - Install the latest Android Studio (should be Meerkat | 2024.3.1 or later)
27
+ - Clone the repo (
` git clone --recurse-submodules [email protected] :firebase/firebase-android-sdk.git ` )
28
+ - When cloning the repo, it is important to get the submodules as well. If you have already cloned
29
+ the repo without the submodules, you can update the submodules by running
30
+ ` git submodule update --init --recursive ` .
31
+ - Import the firebase-android-sdk gradle project into Android Studio using the ** Import
32
+ project(Gradle, Eclipse ADT, etc.)** option.
33
+ - ` firebase-crashlytics-ndk ` must be built with NDK 21. See
34
+ [ firebase-crashlytics-ndk] ( firebase-crashlytics-ndk/README.md ) for more details.
40
35
41
36
## Testing
42
37
43
38
Firebase Android libraries exercise all three types of tests recommended by the
44
39
[ Android Testing Pyramid] ( https://developer.android.com/training/testing/fundamentals#testing-pyramid ) .
45
- Depending on the requirements of the specific project, some or all of these
46
- tests may be used to support changes.
40
+ Depending on the requirements of the specific project, some or all of these tests may be used to
41
+ support changes.
47
42
48
43
> :warning : ** Running tests with errorprone**
49
44
>
@@ -53,48 +48,46 @@ tests may be used to support changes.
53
48
54
49
### Unit Testing
55
50
56
- These are tests that run on your machine's local Java Virtual Machine (JVM). At
57
- runtime, these tests are executed against a modified version of android.jar
58
- where all final modifiers have been stripped off. This lets us sandbox behaviors
59
- at desired places and use popular mocking libraries.
51
+ These are tests that run on your machine's local Java Virtual Machine (JVM). At runtime, these tests
52
+ are executed against a modified version of android.jar where all final modifiers have been stripped
53
+ off. This lets us sandbox behaviors at desired places and use popular mocking libraries.
60
54
61
55
Unit tests can be executed on the command line by running
56
+
62
57
``` bash
63
58
./gradlew :< firebase-project> :check
64
59
```
65
60
66
61
### Integration Testing
67
62
68
- These are tests that run on a hardware device or emulator. These tests have
69
- access to Instrumentation APIs, give you access to information such as the
70
- [ Android Context] ( https://developer.android.com/reference/android/content/Context ) .
71
- In Firebase, instrumentation tests are used at different capacities by different
72
- projects. Some tests may exercise device capabilities, while stubbing any calls
73
- to the backend, while some others may call out to nightly backend builds to
74
- ensure distributed API compatibility.
63
+ These are tests that run on a hardware device or emulator. These tests have access to
64
+ Instrumentation APIs, give you access to information such as the
65
+ [ Android Context] ( https://developer.android.com/reference/android/content/Context ) . In Firebase,
66
+ instrumentation tests are used at different capacities by different projects. Some tests may
67
+ exercise device capabilities, while stubbing any calls to the backend, while some others may call
68
+ out to nightly backend builds to ensure distributed API compatibility.
75
69
76
- Along with Espresso, they are also used to test projects that have UI
77
- components.
70
+ Along with Espresso, they are also used to test projects that have UI components.
78
71
79
72
#### Project Setup
80
73
81
- Before you can run integration tests, you need to add a ` google-services.json `
82
- file to the root of your checkout. You can use the ` google-services.json ` from
83
- any project that includes an Android App, though you'll likely want one that's
84
- separate from any production data you have because our tests write random data.
74
+ Before you can run integration tests, you need to add a ` google-services.json ` file to the root of
75
+ your checkout. You can use the ` google-services.json ` from any project that includes an Android App,
76
+ though you'll likely want one that's separate from any production data you have because our tests
77
+ write random data.
85
78
86
79
If you don't have a suitable testing project already:
87
80
88
- * Open the [ Firebase console] ( https://console.firebase.google.com/ )
89
- * If you don't yet have a project you want to use for testing, create one.
90
- * Add an Android app to the project
91
- * Give the app any package name you like.
92
- * Download the resulting ` google-services.json ` file and put it in the root of
93
- your checkout.
81
+ - Open the [ Firebase console] ( https://console.firebase.google.com/ )
82
+ - If you don't yet have a project you want to use for testing, create one.
83
+ - Add an Android app to the project
84
+ - Give the app any package name you like.
85
+ - Download the resulting ` google-services.json ` file and put it in the root of your checkout.
94
86
95
87
#### Running Integration Tests on Local Emulator
96
88
97
89
Integration tests can be executed on the command line by running
90
+
98
91
``` bash
99
92
./gradlew :< firebase-project> :connectedCheck
100
93
```
@@ -103,11 +96,12 @@ Integration tests can be executed on the command line by running
103
96
104
97
> You need additional setup for this to work:
105
98
>
106
- > * ` gcloud ` needs to be [ installed] ( https://cloud.google.com/sdk/install ) on local machine
107
- > * ` gcloud ` needs to be configured with a project that has billing enabled
108
- > * ` gcloud ` needs to be authenticated with credentials that have 'Firebase Test Lab Admin' role
99
+ > - ` gcloud ` needs to be [ installed] ( https://cloud.google.com/sdk/install ) on local machine
100
+ > - ` gcloud ` needs to be configured with a project that has billing enabled
101
+ > - ` gcloud ` needs to be authenticated with credentials that have 'Firebase Test Lab Admin' role
109
102
110
103
Integration tests can be executed on the command line by running
104
+
111
105
``` bash
112
106
./gradlew :< firebase-project> :deviceCheck
113
107
```
@@ -134,92 +128,84 @@ Firebase SDKs use some special annotations for tooling purposes.
134
128
### @Keep
135
129
136
130
APIs that need to be preserved up until the app's runtime can be annotated with
137
- [ @Keep ] ( https://developer.android.com/reference/android/support/annotation/Keep ) .
138
- The
139
- [ @Keep ] ( https://developer.android.com/reference/android/support/annotation/Keep )
140
- annotation is * blessed* to be honored by android's [ default proguard
141
- configuration] ( https://developer.android.com/studio/write/annotations#keep ) . A common use for
142
- this annotation is because of reflection. These APIs should be generally ** discouraged** , because
143
- they can't be proguarded.
131
+ [ @Keep ] ( https://developer.android.com/reference/android/support/annotation/Keep ) . The
132
+ [ @Keep ] ( https://developer.android.com/reference/android/support/annotation/Keep ) annotation is
133
+ _ blessed_ to be honored by android's
134
+ [ default proguard configuration] ( https://developer.android.com/studio/write/annotations#keep ) . A
135
+ common use for this annotation is because of reflection. These APIs should be generally
136
+ ** discouraged** , because they can't be proguarded.
144
137
145
138
### @KeepForSdk
146
139
147
- APIs that are intended to be used by Firebase SDKs should be annotated with
148
- ` @KeepForSdk ` . The key benefit here is that the annotation is * blessed* to throw
149
- linter errors on Android Studio if used by the developer from a non firebase
150
- package, thereby providing a valuable guard rail.
151
-
140
+ APIs that are intended to be used by Firebase SDKs should be annotated with ` @KeepForSdk ` . The key
141
+ benefit here is that the annotation is _ blessed_ to throw linter errors on Android Studio if used by
142
+ the developer from a non firebase package, thereby providing a valuable guard rail.
152
143
153
144
### @PublicApi
154
145
155
146
We annotate APIs that meant to be used by developers with
156
- [ @PublicAPI ] ( firebase-common/src/main/java/com/google/firebase/annotations/PublicApi.java ) . This
147
+ [ @PublicAPI ] ( firebase-common/src/main/java/com/google/firebase/annotations/PublicApi.java ) . This
157
148
annotation will be used by tooling to help inform the version bump (major, minor, patch) that is
158
149
required for the next release.
159
150
160
151
## Proguarding
161
152
162
- Firebase SDKs do not proguard themselves, but support proguarding. Firebase SDKs themselves are
153
+ Firebase SDKs do not proguard themselves, but support proguarding. Firebase SDKs themselves are
163
154
proguard friendly, but the dependencies of Firebase SDKs may not be.
164
155
165
156
### Proguard config
166
157
167
- In addition to preguard.txt, projects declare an additional set of proguard
168
- rules in a proguard.txt that are honored by the developer's app while building
169
- the app's proguarded apk. This file typically contains the keep rules that need
170
- to be honored during the app' s proguarding phase.
158
+ In addition to preguard.txt, projects declare an additional set of proguard rules in a proguard.txt
159
+ that are honored by the developer's app while building the app's proguarded apk. This file typically
160
+ contains the keep rules that need to be honored during the app' s proguarding phase.
171
161
172
- As a best practice, these explicit rules should be scoped to only libraries
173
- whose source code is outside the firebase-android-sdk codebase making annotation
174
- based approaches insufficient.The combination of keep rules resulting from the
175
- annotations, the preguard.txt and the proguard.txt collectively determine the
176
- APIs that are preserved at ** runtime** .
162
+ As a best practice, these explicit rules should be scoped to only libraries whose source code is
163
+ outside the firebase-android-sdk codebase making annotation based approaches insufficient.The
164
+ combination of keep rules resulting from the annotations, the preguard.txt and the proguard.txt
165
+ collectively determine the APIs that are preserved at ** runtime** .
177
166
178
167
## Publishing
179
168
180
- Firebase is published as a collection of libraries each of which either
181
- represents a top level product, or contains shared functionality used by one or
182
- more projects. The projects are published as managed maven artifacts available
183
- at [ Google's Maven Repository] ( https://maven.google.com ) . This section helps
184
- reason about how developers may make changes to firebase projects and have their
185
- apps depend on the modified versions of Firebase.
169
+ Firebase is published as a collection of libraries each of which either represents a top level
170
+ product, or contains shared functionality used by one or more projects. The projects are published
171
+ as managed maven artifacts available at [ Google's Maven Repository] ( https://maven.google.com ) . This
172
+ section helps reason about how developers may make changes to firebase projects and have their apps
173
+ depend on the modified versions of Firebase.
186
174
187
175
### Dependencies
188
176
189
177
Any dependencies, within the projects, or outside of Firebase are encoded as
190
178
[ maven dependencies] ( https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html )
191
- into the ` pom ` file that accompanies the published artifact. This allows the
192
- developer's build system (typically Gradle) to build a dependency graph and
193
- select the dependencies using its own [ resolution
194
- strategy] ( https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html )
179
+ into the ` pom ` file that accompanies the published artifact. This allows the developer's build
180
+ system (typically Gradle) to build a dependency graph and select the dependencies using its own
181
+ [ resolution strategy] ( https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html )
195
182
196
183
### Commands
197
184
198
- For more advanced use cases where developers wish to make changes to a project,
199
- but have transitive dependencies point to publicly released versions, individual
200
- projects may be published as follows.
185
+ For more advanced use cases where developers wish to make changes to a project, but have transitive
186
+ dependencies point to publicly released versions, individual projects may be published as follows.
201
187
202
188
``` bash
203
189
# e.g. to publish Firestore and Functions
204
190
./gradlew -PprojectsToPublish=" firebase-firestore,firebase-functions" \
205
191
publishReleasingLibrariesToMavenLocal
206
192
```
207
193
208
- Developers may take a dependency on these locally published versions by adding
209
- the ` mavenLocal() ` repository to your [ repositories
210
- block] ( https://docs.gradle.org/current/userguide/declaring_repositories.html ) in
211
- your app module's build.gradle.
194
+ Developers may take a dependency on these locally published versions by adding the ` mavenLocal() `
195
+ repository to your
196
+ [ repositories block] ( https://docs.gradle.org/current/userguide/declaring_repositories.html ) in your
197
+ app module's build.gradle.
212
198
213
199
### Code Formatting
214
200
215
201
Java and Kotlin are both formatted using ` spotless ` .
216
202
217
203
To run formatting on a project, run
204
+
218
205
``` bash
219
206
./gradlew :< firebase-project> :spotlessApply
220
207
```
221
208
222
209
### Contributing
223
210
224
- We love contributions! Please read our
225
- [ contribution guidelines] ( /CONTRIBUTING.md ) to get started.
211
+ We love contributions! Please read our [ contribution guidelines] ( /CONTRIBUTING.md ) to get started.
0 commit comments