This is the Cloud Firestore component of the Firebase Android SDK.
Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform. Like Firebase Realtime Database, it keeps your data in sync across client apps through realtime listeners and offers offline support for mobile and web so you can build responsive apps that work regardless of network latency or Internet connectivity. Cloud Firestore also offers seamless integration with other Firebase and Google Cloud Platform products, including Cloud Functions.
All Gradle commands should be run from the source root (which is one level up from this folder). See the README.md in the source root for instructions on publishing/testing Cloud Firestore.
To build Cloud Firestore, from the source root run:
./gradlew :firebase-firestore:assembleRelease
To run unit tests for Cloud Firestore, from the source root run:
./gradlew :firebase-firestore:check
Running integration tests requires a Firebase project because they would try to connect to the Firestore backends.
See here for how to setup a project.
Once you setup the project, download google-services.json
and place it in
the source root.
Make sure you have created a Firestore instance for your project, before you proceed.
By default, integration tests run against the Firestore emulator.
The integration tests require that the Firestore emulator is running on port 8080, which is default when running it via CLI.
- Install the Firebase CLI.
npm install -g firebase-tools
- Install the Firestore
emulator.
firebase setup:emulators:firestore
- Run the emulator
firebase emulators:start --only firestore
- Select the
Firestore Integration Tests (Firestore Emulator)
run configuration to run all integration tests.
To run the integration tests against prod, select FirestoreProdIntegrationTest
run configuration.
Then simply run:
./gradlew :firebase-firestore:connectedCheck
You can also test on Firebase Test Lab, which allow you to run the integration tests on devices hosted in Google data center.
See here for instructions of how to setup Firebase Test Lab for your project.
Run:
./gradlew :firebase-firestore:deviceCheck
- Create a
google-services.json
file in the root directory. This file should contain your target Firebase project's configuration. - If not already logged in, authenticate with your Google Cloud Platform (GCP) account using
gcloud auth application-default login
. You can check your logged-in accounts by runninggcloud auth list
. - Navigate to the
firebase-firestore
directory, create composite indexes by running:
terraform init
terraform apply -var-file=../google-services.json -auto-approve
Note: If the index creation encounters issues, such as concurrent operations, consider running the index creation process again. Error messages indicating that indexes have already been created can be safely disregarded.
- To create a new composite index for local development, click on the provided link in the test error message, which will direct you to the Firebase Console.
- Add the newly created composite index to the
firestore_index_config.tf
file. The "name" field is not required to be explicitly added to the file, as the index creation will auto complete it on behalf.
Run below to format Java code:
./gradlew :firebase-firestore:spotlessApply
See here if you want to be able to format code from within Android Studio.
./gradlew -PprojectsToPublish="firebase-firestore" publishReleasingLibrariesToMavenLocal
Developers may then take a dependency on these locally published versions by adding
the mavenLocal()
repository to your repositories
block in
your app module's build.gradle.
After importing the project into Android Studio and building successfully
for the first time, Android Studio will delete the run configuration xml files
in ./idea/runConfigurations
. Undo these changes with the command:
$ git checkout .idea/runConfigurations