Skip to content

Latest commit

 

History

History

firebase-firestore

firebase-firestore

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.

Building

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

Unit Testing

To run unit tests for Cloud Firestore, from the source root run:

./gradlew :firebase-firestore:check

Integration Testing

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.

Setting up 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.

Run on Local Android Emulator

Then simply run:

./gradlew :firebase-firestore:connectedCheck

Run on Firebase Test Lab

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

Testing composite index query against production

Setting Up the Environment:

  1. Create a google-services.json file in the root directory. This file should contain your target Firebase project's configuration.
  2. 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 running gcloud auth list.
  3. 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.

Adding new composite index query tests

  1. 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.
  2. 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.

Code Formatting

Run below to format Java code:

./gradlew :firebase-firestore:googleJavaFormat

See here if you want to be able to format code from within Android Studio.

Build Local Jar of Firestore SDK

./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.

Misc

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