能否为Android版Chromium集成Firebase Crashlytics?
I’ve helped my team tackle this exact problem before—since Chromium uses Ninja instead of Gradle, you can’t rely on the standard Firebase setup flow. Here’s a step-by-step breakdown to make it work:
1. Fetch Firebase Crashlytics SDK Dependencies
First, you’ll need to manually grab the required resources:
- Download the latest
firebase-crashlyticsandfirebase-coreAARs from Firebase’s Maven repository. - For native C++ crash support, download prebuilt
.solibraries for all ABIs Chromium targets (armeabi-v7a, arm64-v8a, x86, x86_64). - Place all these files in a dedicated third-party directory in your Chromium checkout, e.g.,
third_party/firebase_crashlytics/.
2. Update GN Build Configurations
You need to tell Ninja how to include these dependencies in your build:
Add Prebuilt AARs
In your target’s GN file (e.g., chrome/android/BUILD.gn), define prebuilt AAR targets:
android_prebuilt_aar("firebase_crashlytics_aar") { aar_path = "//third_party/firebase_crashlytics/firebase-crashlytics-[version].aar" proguard_configs = [ "//third_party/firebase_crashlytics/crashlytics-proguard-rules.pro" ] } android_prebuilt_aar("firebase_core_aar") { aar_path = "//third_party/firebase_crashlytics/firebase-core-[version].aar" }
Link Native Libraries
For C++ crash support, add the native libraries to your GN target:
shared_library("firebase_crashlytics_native") { sources = [] deps = [] libs = [ "//third_party/firebase_crashlytics/libs/armeabi-v7a/libcrashlytics.so", "//third_party/firebase_crashlytics/libs/arm64-v8a/libcrashlytics.so", // Include other ABIs as needed ] }
Add Dependencies to Your Main Target
Include these targets in your Android app’s deps:
android_apk("chrome") { // ... existing config ... deps = [ ":firebase_crashlytics_aar", ":firebase_core_aar", ":firebase_crashlytics_native", // ... other deps ... ] }
3. Add Firebase Configuration
- Place your
google-services.jsonfile in Chromium’s Android assets directory (e.g.,chrome/android/assets/). Ensure GN includes this asset in the build:
android_resources = [ "//chrome/android/assets/google-services.json", ]
4. Initialize Crashlytics
Java Initialization
Chromium’s Android layer uses Java, so initialize Crashlytics in your application class (create one if you don’t have it):
import com.google.firebase.FirebaseApp; import com.google.firebase.crashlytics.FirebaseCrashlytics; public class ChromeApplication extends android.app.Application { @Override public void onCreate() { super.onCreate(); // Initialize Firebase App FirebaseApp.initializeApp(this); // Enable crash collection FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); crashlytics.setCrashlyticsCollectionEnabled(true); // Optional: Set user identifiers or custom attributes crashlytics.setUserId("unique_user_id"); } }
Don’t forget to update your AndroidManifest.xml to use this application class:
<application android:name=".ChromeApplication" // ... existing attributes ... >
Native (C++) Initialization
To capture Chromium’s C++ crashes, initialize the native Crashlytics SDK in your C++ code:
#include "firebase/crashlytics.h" void InitializeNativeCrashlytics() { firebase::App* firebase_app = firebase::App::GetInstance(); if (firebase_app != nullptr) { firebase::crashlytics::Initialize(*firebase_app); // Optional: Set user ID or custom keys firebase::crashlytics::SetUserId("native_user_id"); firebase::crashlytics::SetCustomKey("build_version", "99.0.4844.84"); } }
Call this function early in your Chromium startup flow (e.g., in chrome_main).
5. Handle ProGuard/R8 Obfuscation
If Chromium uses obfuscation, add these rules to your proguard config to preserve Crashlytics functionality:
-keep class com.google.firebase.crashlytics.** { *; } -keepattributes SourceFile,LineNumberTable -keepattributes *Annotation*
6. Test the Integration
- Trigger a Java crash:
FirebaseCrashlytics.getInstance().crash(); - Trigger a C++ crash:
*(int*)0 = 0; - After crashing, restart the app (Crashlytics sends logs on next launch) and check your Firebase console for the crash reports.
Key Notes
- Ensure Firebase SDK versions are compatible with Chromium’s minimum Android SDK version.
- Verify network permissions are present in
AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
内容的提问来源于stack exchange,提问作者Dmitriy Kryuchkov

