Skip to content

Commit 27e2cdc

Browse files
committed
firestore: Improve instructions in README.md for rolling your own build of the firebase-firestore Gradle artifact
1 parent 8b3b9ab commit 27e2cdc

File tree

1 file changed

+125
-6
lines changed

1 file changed

+125
-6
lines changed

firebase-firestore/README.md

Lines changed: 125 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,135 @@ Run below to format Java code:
124124
See [here](../README.md#code-formatting) if you want to be able to format code from within Android
125125
Studio.
126126

127-
## Build Local Jar of Firestore SDK
127+
## Build firebase-firestore for use in your application.
128+
129+
It is possible, and, indeed, quite easy, to compile the `firebase-firestore` Gradle artifact from
130+
source and then use that self-compiled artifact in your Android application.
131+
132+
### Update gradle.properties with a custom version number
133+
134+
First, edit `firebase-firestore/gradle.properties` and change the "version" to something unique. It
135+
can be especially helpful to append a "-something" suffix to the version name, replacing "something"
136+
with some description of your change. Doing so will give you confidence that you are indeed using
137+
your self-compiled version in your application and not accidentally using an officially-published
138+
version.
139+
140+
For example, you can change the contents of `firebase-firestore/gradle.properties` from
141+
142+
```
143+
version=26.0.2
144+
latestReleasedVersion=26.0.1
145+
```
146+
147+
to
148+
149+
```
150+
version=99.99.99-MyFix1
151+
latestReleasedVersion=26.0.1
152+
```
153+
154+
### Build the `firebase-firestore` Gradle artifact
155+
156+
Then, build the `firebase-firestore` Gradle artifact by running:
128157

129158
```bash
130-
./gradlew -PprojectsToPublish="firebase-firestore" publishReleasingLibrariesToMavenLocal
159+
./gradlew :firebase-firestore:publishToMavenLocal
160+
```
161+
162+
### Add mavenLocal() repository to your Android app
163+
164+
In order to take a dependency on the self-compiled Gradle `firebase-firestore` artifact, first add
165+
`mavenLocal()` to the
166+
[`dependencyResolutionManagement.repositories`](https://docs.gradle.org/current/userguide/declaring_repositories.html)
167+
section of your Android application's `settings.gradle` or `settings.gradle.kts` file.
168+
169+
For example, you would change something like
170+
171+
```kotlin
172+
dependencyResolutionManagement {
173+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
174+
repositories {
175+
google()
176+
mavenCentral()
177+
}
178+
}
179+
```
180+
181+
to
182+
183+
```kotlin
184+
dependencyResolutionManagement {
185+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
186+
repositories {
187+
google()
188+
mavenCentral()
189+
mavenLocal() // Add this line to use the artifacts published by `publishToMavenLocal`
190+
}
191+
}
192+
```
193+
194+
### Change the firebase-firestore dependency in your Android app
195+
196+
Then, edit your Android application's `build.gradle` or `build.gradle.kts` to use the self-compiled
197+
Gradle `firebase-firestore` artifact.
198+
199+
For example, you would change something like
200+
201+
```kotlin
202+
dependencies {
203+
implementation(platform("com.google.firebase:firebase-bom:34.3.0"))
204+
implementation("com.google.firebase:firebase-firestore")
205+
// ... the rest of your application's dependencies
206+
}
131207
```
132208

133-
Developers may then take a dependency on these locally published versions by adding the
134-
`mavenLocal()` repository to your
135-
[repositories block](https://docs.gradle.org/current/userguide/declaring_repositories.html) in your
136-
app module's build.gradle.
209+
to
210+
211+
```kotlin
212+
dependencies {
213+
implementation(platform("com.google.firebase:firebase-bom:34.3.0"))
214+
// Use the custom version you set in gradle.properties in the next line.
215+
implementation("com.google.firebase:firebase-firestore:99.99.99-MyFix1")
216+
// ... the rest of your application's dependencies
217+
}
218+
```
219+
220+
### (Optional) Log the firebase-firestore version to logcat
221+
222+
It can be helpful to see in the logs which exact version of the `firebase-firestore` Gradle artifact
223+
your application is using. This increases the confidence that your application is indeed using the
224+
custom, self-compiled artifact rather than an official artifact.
225+
226+
To do this, simply add a line like the following somewhere in your Android application:
227+
228+
```kotlin
229+
android.util.Log.i("FirestoreVersion", com.google.firebase.firestore.BuildConfig.VERSION_NAME)
230+
```
231+
232+
### (Rarely required) Self-compile dependencies of firebase-firestore
233+
234+
The `firebase-firestore` Gradle artifact includes dependencies on a few peer modules in the
235+
`firebase-android-sdk` repository. Although rare, sometimes you want, or need, to include local
236+
changes to these dependencies in your self-compiled build.
237+
238+
At the time of writing, the peer dependencies of `firebase-firestore` include:
239+
240+
- `firebase-common`
241+
- `firebase-components`
242+
- `firebase-database-collection`
243+
- `protolite-well-known-types`
244+
245+
For purposes of example, suppose there is a local change to `firebase-common` that you want your
246+
self-compiled `firebase-firestore` artifact to pick up. Follow the steps below to do this, adapting
247+
the steps as appropriate if your specific case uses a _different_ dependency.
248+
249+
1. Edit `firebase-common/gradle.properties`, changing the verson to something like `99.99.99`.
250+
2. Compile and publish the `firebase-common` Gradle artifact by running:
251+
`./gradlew :firebase-common:publishToMavenLocal`
252+
3. Edit `firebase-firestore/firebase-firestore.gradle` to use a _project_ dependency on the
253+
artifact. For example, change `api(libs.firebase.common)` to `api(project(":firebase-common"))`
254+
4. Compile and publish the `firebase-firestore` Gradle artifact as documented above, namely, by
255+
running `./gradlew :firebase-firestore:publishToMavenLocal`
137256

138257
## Misc
139258

0 commit comments

Comments
 (0)