• Stars
    star
    2,244
  • Rank 20,522 (Top 0.5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Firebase Android SDK

Firebase Android Open Source Development

This repository contains a subset of the Firebase Android SDK source. It currently includes the following Firebase libraries, and some of their dependencies:

  • firebase-abt
  • firebase-appdistribution
  • firebase-common
  • firebase-common-ktx
  • firebase-crashlytics
  • firebase-crashlytics-ktx
  • firebase-crashlytics-ndk
  • firebase-database
  • firebase-database-ktx
  • firebase-database-collection
  • firebase-datatransport
  • firebase-firestore
  • firebase-firestore-ktx
  • firebase-functions
  • firebase-functions-ktx
  • firebase-inappmessaging
  • firebase-inappmessaging-ktx
  • firebase-inappmessaging-display
  • firebase-inappmessaging-display-ktx
  • firebase-messaging
  • firebase-messaging-directboot
  • firebase-perf
  • firebase-perf-ktx
  • firebase-remote-config
  • firebase-remote-config-ktx
  • firebase-storage
  • firebase-storage-ktx

Firebase is an app development platform with tools to help you build, grow and monetize your app. More information about Firebase can be found at https://firebase.google.com.

Table of contents

  1. Getting Started
  2. Testing
    1. Unit Testing
    2. Integration Testing
  3. Proguarding
    1. APIs used via reflection
    2. APIs intended for developer consumption
    3. APIs intended for other Firebase SDKs
  4. Publishing
    1. Dependencies
    2. Commands
  5. Code Formatting
  6. Contributing

Getting Started

  • Install the latest Android Studio (should be 3.0.1 or later)
  • Clone the repo (git clone --recurse-submodules [email protected]:firebase/firebase-android-sdk.git)
    • When cloning the repo, it is important to get the submodules as well. If you have already cloned the repo without the submodules, you can update the submodules by running git submodule update --init --recursive.
  • Import the firebase-android-sdk gradle project into Android Studio using the Import project(Gradle, Eclipse ADT, etc.) option.
  • firebase-crashlytics-ndk must be built with NDK 21. See firebase-crashlytics-ndk for more details.

Testing

Firebase Android libraries exercise all three types of tests recommended by the Android Testing Pyramid. Depending on the requirements of the specific project, some or all of these tests may be used to support changes.

⚠️ Running tests with errorprone

To run with errorprone add withErrorProne to the command line, e.g.

./gradlew :<firebase-project>:check withErrorProne.

Unit Testing

These are tests that run on your machine's local Java Virtual Machine (JVM). At runtime, these tests are executed against a modified version of android.jar where all final modifiers have been stripped off. This lets us sandbox behaviors at desired places and use popular mocking libraries.

Unit tests can be executed on the command line by running

./gradlew :<firebase-project>:check

Integration Testing

These are tests that run on a hardware device or emulator. These tests have access to Instrumentation APIs, give you access to information such as the Android Context. In Firebase, instrumentation tests are used at different capacities by different projects. Some tests may exercise device capabilities, while stubbing any calls to the backend, while some others may call out to nightly backend builds to ensure distributed API compatibility.

Along with Espresso, they are also used to test projects that have UI components.

Project Setup

Before you can run integration tests, you need to add a google-services.json file to the root of your checkout. You can use the google-services.json from any project that includes an Android App, though you'll likely want one that's separate from any production data you have because our tests write random data.

If you don't have a suitable testing project already:

  • Open the Firebase console
  • If you don't yet have a project you want to use for testing, create one.
  • Add an Android app to the project
  • Give the app any package name you like.
  • Download the resulting google-services.json file and put it in the root of your checkout.

Running Integration Tests on Local Emulator

Integration tests can be executed on the command line by running

./gradlew :<firebase-project>:connectedCheck

Running Integration Tests on Firebase Test Lab

You need additional setup for this to work:

  • gcloud needs to be installed on local machine
  • gcloud needs to be configured with a project that has billing enabled
  • gcloud needs to be authenticated with credentials that have 'Firebase Test Lab Admin' role

Integration tests can be executed on the command line by running

./gradlew :<firebase-project>:deviceCheck

This will execute tests on devices that are configured per project, if nothing is configured for the project, the tests will run on model=Pixel2,version=27,locale=en,orientation=portrait.

Projects can be configured in the following way:

firebaseTestLab {
  // to get a list of available devices execute `gcloud firebase test android models list`
  devices = [
    '<device1>',
    '<device2>',
  ]
}

Annotations

Firebase SDKs use some special annotations for tooling purposes.

@Keep

APIs that need to be preserved up until the app's runtime can be annotated with @Keep. The @Keep annotation is blessed to be honored by android's default proguard configuration. A common use for this annotation is because of reflection. These APIs should be generally discouraged, because they can't be proguarded.

@KeepForSdk

APIs that are intended to be used by Firebase SDKs should be annotated with @KeepForSdk. The key benefit here is that the annotation is blessed to throw linter errors on Android Studio if used by the developer from a non firebase package, thereby providing a valuable guard rail.

@PublicApi

We annotate APIs that meant to be used by developers with @PublicAPI. This annotation will be used by tooling to help inform the version bump (major, minor, patch) that is required for the next release.

Proguarding

Firebase SDKs do not proguard themselves, but support proguarding. Firebase SDKs themselves are proguard friendly, but the dependencies of Firebase SDKs may not be.

Proguard config

In addition to preguard.txt, projects declare an additional set of proguard rules in a proguard.txt that are honored by the developer's app while building the app's proguarded apk. This file typically contains the keep rules that need to be honored during the app' s proguarding phase.

As a best practice, these explicit rules should be scoped to only libraries whose source code is outside the firebase-android-sdk codebase making annotation based approaches insufficient.The combination of keep rules resulting from the annotations, the preguard.txt and the proguard.txt collectively determine the APIs that are preserved at runtime.

Publishing

Firebase is published as a collection of libraries each of which either represents a top level product, or contains shared functionality used by one or more projects. The projects are published as managed maven artifacts available at Google's Maven Repository. This section helps reason about how developers may make changes to firebase projects and have their apps depend on the modified versions of Firebase.

Dependencies

Any dependencies, within the projects, or outside of Firebase are encoded as maven dependencies into the pom file that accompanies the published artifact. This allows the developer's build system (typically Gradle) to build a dependency graph and select the dependencies using its own resolution strategy

Commands

The simplest way to publish a project and all its associated dependencies is to just publish all projects. The following command builds SNAPSHOT dependencies of all projects. All pom level dependencies within the published artifacts will also point to SNAPSHOT versions that are co-published.

./gradlew publishAllToLocal

Developers may take a dependency on these locally published versions by adding the mavenLocal() repository to your repositories block in your app module's build.gradle.

For more advanced use cases where developers wish to make changes to a project, but have transitive dependencies point to publicly released versions, individual projects may be published as follows.

# e.g. to publish Firestore and Functions
./gradlew -PprojectsToPublish=":firebase-firestore,:firebase-functions" \
    publishProjectsToMavenLocal

Code Formatting

Java

Java code in this repo is formatted with the google-java-format tool. You can enable this formatting in Android Studio by downloading and installing the google-java-format plugin. The plugin is disabled by default, but the repo contains configuration information and links to additional plugins.

To run formatting on your entire project you can run

./gradlew :<firebase-project>:googleJavaFormat

Kotlin

Kotlin code in this repo is formatted with the ktfmt tool. You can enable this formatting in Android Studio by downloading and installing the ktfmt plugin. Enable the plugin in Preferences | Editor | ktfmt Settings. and set code style to Google (internal).

To run formatting on your entire project you can run

./gradlew :<firebase-project>:ktfmtFormat

Contributing

We love contributions! Please read our contribution guidelines to get started.

More Repositories

1

functions-samples

Collection of sample apps showcasing popular use cases using Cloud Functions for Firebase
JavaScript
12,063
star
2

flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
Dart
8,671
star
3

quickstart-android

Firebase Quickstart Samples for Android
Java
8,563
star
4

firebase-js-sdk

Firebase Javascript SDK
TypeScript
4,830
star
5

quickstart-js

Firebase Quickstart Samples for Web
HTML
4,818
star
6

FirebaseUI-Android

Optimized UI components for Firebase
Java
4,628
star
7

firebaseui-web

FirebaseUI is an open-source JavaScript library for Web that provides simple, customizable UI bindings on top of Firebase SDKs to eliminate boilerplate code and promote best practices.
JavaScript
4,558
star
8

firebase-tools

The Firebase Command Line Tools
TypeScript
3,994
star
9

firebase-ios-sdk

Firebase iOS SDK
Objective-C
3,583
star
10

quickstart-ios

Firebase Quickstart Samples for iOS
Swift
2,773
star
11

codelab-friendlychat-web

The source for the Firebase codelab for building a cross-platform chat app
JavaScript
1,749
star
12

firebase-admin-node

Firebase Admin Node.js SDK
TypeScript
1,621
star
13

FirebaseUI-iOS

iOS UI bindings for Firebase.
Objective-C
1,507
star
14

geofire-js

GeoFire for JavaScript - Realtime location queries with Firebase
TypeScript
1,443
star
15

firebaseui-web-react

React Wrapper for firebaseUI Web
JavaScript
1,262
star
16

firebase-admin-go

Firebase Admin Go SDK
Go
1,142
star
17

superstatic

Superstatic: a static file server for fancy apps.
JavaScript
1,097
star
18

firebase-functions

Firebase SDK for Cloud Functions
TypeScript
1,024
star
19

firebase-admin-python

Firebase Admin Python SDK
Python
1,019
star
20

quickstart-nodejs

JavaScript
895
star
21

extensions

Source code for official Firebase extensions
TypeScript
892
star
22

quickstart-unity

Firebase Quickstart Samples for Unity
C#
775
star
23

snippets-android

Android snippets for firebase.google.com
Java
762
star
24

snippets-web

Web snippets for firebase.google.com
JavaScript
749
star
25

genkit

An open source framework for building AI-powered apps with familiar code-centric patterns. Genkit makes it easy to develop, integrate, and test AI features with observability and evaluations. Genkit works with various models and platforms.
TypeScript
701
star
26

geofire-java

GeoFire for Java - Realtime location queries with Firebase
Java
671
star
27

firebase-admin-java

Firebase Admin Java SDK
Java
527
star
28

friendlyeats-web

JavaScript
467
star
29

geofire-objc

GeoFire for Objective-C - Realtime location queries with Firebase
Objective-C
440
star
30

snippets-node

Node.js snippets for firebase.google.com
JavaScript
369
star
31

firebase-admin-dotnet

Firebase Admin .NET SDK
C#
367
star
32

quickstart-testing

Samples demonstrating how to test your Firebase app
TypeScript
335
star
33

firebase-tools-ui

A local-first UI for Firebase Emulator Suite.
TypeScript
269
star
34

friendlyeats-android

Cloud Firestore Android codelab
Kotlin
261
star
35

codelab-friendlychat-android

Firebase FriendlyChat codelab
Kotlin
243
star
36

firebase-cpp-sdk

Firebase C++ SDK
C++
230
star
37

quickstart-java

Quickstart samples for Firebase Java Admin SDK
Java
224
star
38

firebase-functions-test

TypeScript
211
star
39

quickstart-cpp

Firebase Quickstart Samples for C++
C++
190
star
40

fastlane-plugin-firebase_app_distribution

fastlane plugin for Firebase App Distribution. https://firebase.google.com/docs/app-distribution
Ruby
166
star
41

friendlypix-ios

Friendly Pix iOS is a sample app demonstrating how to build an iOS app with the Firebase Platform.
Swift
166
star
42

quickstart-flutter

Dart
138
star
43

firebase-functions-python

Python
136
star
44

geofire-android

GeoFire for Android apps
Java
133
star
45

firebase-unity-sdk

The Firebase SDK for Unity
C#
128
star
46

friendlyeats-ios

Swift
127
star
47

snippets-ios

iOS snippets used in firebase.google.com
Objective-C
121
star
48

firebaseopensource.com

Source for firebase open source site
TypeScript
118
star
49

quickstart-python

Jupyter Notebook
115
star
50

FirebaseUI-Flutter

Dart
102
star
51

codelab-friendlychat-ios

Swift
68
star
52

snippets-rules

Snippets for security rules on firebase.google.com
TypeScript
45
star
53

emulators-codelab

JavaScript
44
star
54

oss-bot

Robot friend for open source repositories
TypeScript
36
star
55

firebase-bower

Firebase Web Client
JavaScript
35
star
56

snippets-flutter

Dart
30
star
57

snippets-go

Golang snippets for firebase docs
Go
24
star
58

snippets-java

Java snippets for firebase.google.com
Java
17
star
59

firebase-docs

TypeScript
16
star
60

abseil-cpp-SwiftPM

C++
13
star
61

firebase-testlab-instr-lib

Java
13
star
62

snippets-cpp

C++ snippets for firebase.google.com
C++
12
star
63

SpecsStaging

SpecsStaging
11
star
64

SpecsTesting

Ruby
11
star
65

rtdb-to-csv

JavaScript
11
star
66

appquality-codelab-ios

Firebase iOS App Quality Codelab
Objective-C
11
star
67

level-up-with-firebase

C#
9
star
68

boringSSL-SwiftPM

C++
8
star
69

firestore-bundle-builder

TypeScript
7
star
70

.github

Default configuration for Firebase repos
6
star
71

nginx

This repo is a PUBLIC FORK
C
6
star
72

SpecsDev

6
star
73

snippets-python

Python snippets for firebase.google.com
4
star
74

firebase-release-dashboard

JavaScript
4
star
75

ok

HTTPS CDN Proxy Healthy Check
4
star
76

grpc-SwiftPM

C++
3
star
77

crashlytics-testapps

Java
2
star
78

data-connect-ios-sdk

Swift
2
star
79

.allstar

1
star