Skip to content

About

Firebase Telemetry Persistence

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

firebase-telemetry-persistence

Firebase Telemetry Persistence Library

Project Structure

This library is organized to facilitate local development and cross-platform interop for Android and iOS

  • include/: Public headers for interop. These define the interface consumed by the SDKs
  • src/: Implementation of the library, including private headers and source files
  • tests/: Unit tests designed to run on a developer's machine or an Android device
  • main.cpp: A scratchpad for local development and experimentation

Only the core logic in include/ and src/ is compiled into the final production library. Development artifacts like tests/ and main.cpp are used strictly for local verification and are never linked into the final binary


Local Development

Use these instructions to work on the library logic itself on your host machine

Prerequisites

  • A C++17 compliant compiler
  • CMake (version 3.22 or higher)

Building

To build the library, the local scratchpad, and the unit tests:

cmake -S . -B build
cmake --build build

Running Tests

Unit tests use GoogleTest:

ctest --test-dir build --output-on-failure

Alternatively, you can run the test executable directly:

./build/unit_tests

Running the Scratchpad

Use main.cpp for quick testing:

./build/main

Memory Leak Detection

ASan

Build the project with ENABLE_ASAN enabled and run it normally:

cmake -S . -B build-asan -DENABLE_ASAN=ON
cmake --build build-asan

./build-asan/unit_tests
./build-asan/main

Leaks (macOS)

On macOS, ASan detects memory errors but not leaks. Instead, build the project with ENABLE_FRAME_POINTER enabled and run it with leaks:

cmake -S . -B build-leaks -DENABLE_FRAME_POINTER=ON
cmake --build build-leaks

MallocScribble=1 leaks --atExit -- ./build-leaks/unit_tests
MallocScribble=1 leaks --atExit -- ./build-leaks/main

The "process is not debuggable" warning is expected and doesn't affect leak detection


Android Integration

Use these instructions to build and link the library for use in an Android application

Prerequisites

  • Android NDK (Version 28.2.13676358 or similar)

Building for Android

To build the shared library for Android using the NDK toolchain:

cmake -S . -B android-build \
  -DCMAKE_BUILD_TYPE=MinSizeRel \
  -DCMAKE_TOOLCHAIN_FILE=~/Library/Android/sdk/ndk/28.2.13676358/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=android-24

cmake --build android-build --target firebase-telemetry-persistence

Running Unit Tests on a Device

Build unit_tests with the NDK by enabling BUILD_ANDROID_TESTS, choosing the ABI (e.g. armeabi-v7a or arm64-v8a):

ABI=armeabi-v7a

cmake -S . -B android-test-$ABI \
  -DCMAKE_TOOLCHAIN_FILE=~/Library/Android/sdk/ndk/28.2.13676358/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=$ABI \
  -DANDROID_PLATFORM=android-24 \
  -DBUILD_ANDROID_TESTS=ON

cmake --build android-test-$ABI --target unit_tests

Push the resulting binary to a device and run it from a writable directory:

adb push android-test-$ABI/unit_tests /data/local/tmp/
adb shell "cd /data/local/tmp && ./unit_tests"

The device must support the chosen ABI. Check with adb shell getprop ro.product.cpu.abilist

ctest is not available for cross-compiled builds since test discovery would need to run the binary on the host

Integrating into an Android Project

To integrate this library in another Android project, add this to your app's build.gradle.kts:

android {
  ...
  externalNativeBuild {
    cmake {
      path = file("firebase-telemetry-persistence/CMakeLists.txt")
      version = "3.22.1"
    }
  }
}

Where firebase-telemetry-persistence/CMakeLists.txt is the local path to this library


iOS Integration

Verify building it:

swift build

Verify compatibility of C++ changes

swift test

Update Package.swift:

let package = Package(
  ...
  dependencies: [
    // Without local changes
    .package(
      url: "https://github.com/firebase/firebase-telemetry-persistence.git",
      branch: "main"),
    // With local changes
    .package(name: "firebase-telemetry-persistence", path: "../../../firebase-telemetry-persistence"),
  ],
  targets: [
    .target(
      dependencies: [
      ...
        .product(name: "FirebaseTelemetryPersistence", package: "firebase-telemetry-persistence"),
      ],
      swiftSettings: [
        .interoperabilityMode(.Cxx)
      ]
    ),
  ],
  cxxLanguageStandard: .cxx17
)

Source Code Headers

Every file containing source code (such as C++ .cpp/.h and Swift .swift files) must include copyright and license information.

Apache header:

Copyright 2026 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Firebase Telemetry Persistence

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Used by

Contributors

Languages