Firebase Android SDK

repository·main·Indexed 25 days ago

https://github.com/firebase/firebase-android-sdk

Source code and development hub for Firebase Android SDKs, including the Firebase AI SDK and its KSP processor for structured object generation, Firebase Encoders for JSON and Protobuf serialization, and the Firebase App Distribution Gradle Plugin. Provides support for various modules such as Firestore, Functions, and Storage, with dedicated Kotlin Extensions (KTX) for idiomatic development.

Tokens
31.7K
Snippets
96
Records
183
Agent score
81%

What's inside firebase-android-sdk

  1. Overview of Firebase In-App Messaging SDK

    main

    Firebase In-App Messaging (FIAM) is designed to engage active users by sending targeted, contextual messages that encourage specific in-app actions (e.g., completing a level, making a purchase, or subscribing to content).

    The FIAM SDK handles the non-UI logic, which includes:

    • Fetching new eligible messages from the Firebase server.
    • Triggering the display of FIAM messages.
  2. Overview of Firebase In-App Messaging Display SDK

    main

    Firebase In-App Messaging helps engage active users by sending targeted, contextual messages to nudge them toward key actions (e.g., completing a level, making a purchase, or subscribing).

    The FIAM Display SDK provides enhanced control over the visual presentation of these messages, allowing developers to customize elements such as:

    • Typefaces
    • Colors
    • Transitions
    • Corner radii
  3. Overview of Cloud Storage for Firebase

    main
    Cloud Storage for Firebase is an object storage service designed for storing user-generated content such as images, audio, and video at Google scale. The Firebase Android SDK provides secure file uploads and downloads that are optimized for varying network qualities. Files stored via the SDK are also accessible on the server using Google Cloud Storage.
  4. Overview of Firebase Realtime Database

    main
    The Firebase Realtime Database is a cloud-hosted, NoSQL database that stores data as a JSON tree. It is designed for real-time synchronization, meaning that data changes are automatically pushed to all connected clients (Android, iOS, and JavaScript) simultaneously. This makes it ideal for building cross-platform applications that require instant data updates across different devices.
  5. Overview of Firebase Encoders

    main

    Firebase Encoders provides libraries and code generation infrastructure to encode Java classes into various serialization formats, specifically json and proto.

    Key components include:

    • firebase_encoders: The core API and Annotations library.
    • processor: A Java plugin that generates encoders for POJOs annotated with @Encodable.
    • firebase_encoders_json: Support for JSON serialization.
    • firebase_encoders_proto: Support for Protobuf serialization.
    • protoc_gen: A Protobuf compiler plugin for generating encoder-compliant classes.
    • reflective: A reflection-based encoder (not recommended for production use).
  6. What the Firebase Performance Gradle Plugin does

    main

    The Firebase Performance Gradle Plugin enables instrumentation in an Android app. This instrumentation provides two key capabilities:

    1. @AddTrace annotation processing: Allows developers to manually instrument code blocks to measure performance.
    2. Automatic HTTP/S network request monitoring: Automatically tracks network performance without manual code changes.
  7. What is a Firebase Component?

    main

    A Firebase Component is a blueprint used by the Firebase Component Model to discover, resolve dependencies, and instantiate SDK services via Dependency Injection.

    Key characteristics of a Component:

    • Interfaces: It implements one or more interfaces.
    • Dependencies: It declares required or optional dependencies on other components.
    • Initialization: It specifies whether it should be initialized eagerly (at app startup) or lazily (on demand).
    • Factory: It defines a factory that creates the component instance using its resolved dependencies.

    Components are singletons within a FirebaseApp container. For SDKs requiring multiple instances (like multiple databases in RTDB or Firestore), the component registers a 'MultiResource' singleton that manages and provides multiple instances per resource name.

    // Defines a component that is registered as both `FirebaseAuth` and `InternalAuthProvider`.
    Component<FirebaseAuth> auth = Component.builder(FirebaseAuth.class, InternalAuthProvider.class)
        // Declares dependencies
        .add(Dependency.required(FirebaseOptions.class))
        // Defines a factory
        .factory(container -> new FirebaseAuth(container.get(FirebaseOptions.class)))
        .eagerInDefaultApp() // alwaysEager() or lazy(), lazy is the default.
        .build()
  8. How Data Connect manages multiplexed subscriptions

    main

    The Data Connect SDK uses a two-level SharedFlow architecture to manage real-time query subscriptions over a single multiplexed bidirectional gRPC connection. This design replaces manual state management with standard Kotlin Coroutine operators to ensure connection lifecycle and query multiplexing are handled efficiently.

    The Two-Level Flow Architecture

    1. Upper Shared Flow (connectionFlow): This flow maintains the active bidirectional gRPC connection with the server. It uses replay = 0 and SharingStarted.WhileSubscribed(0) to ensure the connection opens when the first query is subscribed to and closes when the last one leaves.
    2. Lower Shared Flows: These are spawned per unique query (identified by operation name and variables) and are cached in the RealtimeQueryManager. They multiplex all local subscribers for that specific query. Like the upper flow, they use replay = 0 and WhileSubscribed(0).

    Key Mechanisms

    • Automatic Lifecycle: By using WhileSubscribed(0), the SDK leverages native coroutine reference-counting. The connection and query-specific resources automatically clean up when there are zero active collectors.
    • Late Subscriber Resumption: When a new subscriber joins an active query, the SDK triggers a resume request to the server via a ConflatedSignal. This ensures the late subscriber receives the most recent data immediately rather than waiting for the next server-side emission.
    • Reliability: The architecture allows the use of standard operators like retryWhen on the upper flow to implement features like exponential backoff and reconnection on network changes.