Skip to content

Add no-op Analytics, unsupported Cloud Messaging and in-memory Performance Monitoring for the JVM - #88

Merged
nbransby merged 1 commit into
masterfrom
analytics-messaging-perf
Nov 29, 2026
Merged

nbransby merged 1 commit into
masterfrom
analytics-messaging-perf

Conversation

@nbransby

@nbransby nbransby commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

The Firebase Kotlin SDK has so far filled the gap of the three Firebase products this SDK did not port with JVM-only code of its own. This PR moves that code here as three new hand-written packages, so that firebase-kotlin-sdk can treat Analytics, Cloud Messaging and Performance Monitoring like every other module on the JVM: its com.google.firebase sources become header stubs that are compiled against this jar, verified against it member by member and stripped. None of the Android AARs is added: firebase-analytics would drag in play-services-measurement, and firebase-messaging and firebase-perf need Android runtime pieces.

com.google.firebase.analytics is a no-op, as Google Analytics has no client for the JVM. FirebaseAnalytics.getInstance(Context) returns a singleton that accepts and drops events, default parameters, user properties, the user ID, the session timeout and consent; getAppInstanceId() and getSessionId() complete with null and getFirebaseInstanceId() is null. The Event, Param and UserProperty constants, the ConsentType and ConsentStatus enums, the deprecated setCurrentScreen(Activity, ...) and the AnalyticsKt facade of the Android SDK (Firebase.analytics, logEvent(name) { param(...) } with ParametersBuilder, setConsent { } with ConsentBuilder) are included. Firebase.analytics needs the default app, as on Android. Only GoogleAnalyticsServerPreviewActivity and the facade's hidden ANALYTICS/LOCK internals are left out.

com.google.firebase.messaging has the FirebaseMessaging singleton and the MessagingKt facade (Firebase.messaging, remoteMessage(to) { }), but messages are received through a device registration a desktop or server JVM does not have, so every operation other than isAutoInitEnabled (kept in memory) throws an UnsupportedOperationException saying so: getToken, deleteToken, subscribeToTopic, unsubscribeFromTopic, send, the delivery metrics and notification delegation setters and register/unregister. RemoteMessage, its Builder and Notification are a real in-memory data holder: the message is backed by a Bundle and read through the keys the Android SDK uses (google.to, google.message_id, google.ttl, the gcm.n.* notification entries, the priorities), getData() leaves out the reserved keys like the Android class does, and the message is Parcelable. SendException carries its ERROR_* codes and FirebaseMessagingService is a Service subclass whose callbacks are never invoked.

com.google.firebase.perf keeps traces and HTTP metrics in memory and reports nothing. Trace records its metrics only while running and atomically, as the Android class does, and its attributes at any time; HttpMetric records the response code, payload sizes, content type and attributes; both expose the MAX_* constants and Trace is Parcelable. FirebasePerformance is a process singleton with newTrace, both newHttpMetric overloads, startTrace, the in-memory isPerformanceCollectionEnabled and the HttpMethod constants, and a FirebasePerfRegistrar registers it as a Firebase component so that app.get(FirebasePerformance.class), which the Kotlin SDK's Firebase.performance(app) relies on, works as on Android. The PerformanceKt facade (Firebase.performance, the three trace { } forms) and the AddTrace annotation complete the package.

Two Android shims grow for this: android.os.Bundle becomes Parcelable (with a CREATOR) and stores parcelables and parcelable arrays, which the Analytics items parameter is, and android.os.Parcel writes and reads parcelable arrays as values. Application.getProcessName() is added because firebase-common calls it when it reports that no default app is initialized, which surfaced as a NoSuchMethodError instead of the IllegalStateException.

The signatures were verified against the Android SDK's api.txt through firebase-kotlin-sdk's header-stub verifier: in a worktree of its v3.0.0 branch pointing at this build published to mavenLocal as 0.8.3, the three modules were switched to ordinary header stubs on the JVM (the Android stubs shared with jvmMain, the JVM-only implementations deleted), and compileKotlinJvm, jvmTest and apiCheck of firebase-analytics, firebase-messaging and firebase-perf pass, every stub member found on this jar with the same JVM signature and static-ness. Here, ./gradlew build passes with the Firebase emulator running (144 tests, including new tests for the three packages, Bundle and Parcel), and the README lists the three products and their behaviour. The version becomes 0.8.3.

…mance Monitoring for the JVM

The Firebase Kotlin SDK has so far filled the gap of the three Firebase products this SDK did not port with JVM-only
code of its own. This moves that code here, so that firebase-kotlin-sdk can treat Analytics, Cloud Messaging and
Performance Monitoring like every other module on the JVM: its com.google.firebase sources become header stubs that
are compiled against this jar, verified against it member by member and stripped.

com.google.firebase.analytics is a no-op, as Google Analytics has no client for the JVM: FirebaseAnalytics accepts
and drops events, user properties, the user ID and consent, and its instance and session IDs are null. It comes with
the Event, Param and UserProperty constants, the ConsentType and ConsentStatus enums and the AnalyticsKt facade
(Firebase.analytics, logEvent { } with ParametersBuilder, setConsent { } with ConsentBuilder) of the Android SDK.

com.google.firebase.messaging has the FirebaseMessaging singleton and the MessagingKt facade, but messages are
received through a device registration the JVM does not have, so every operation but isAutoInitEnabled throws an
UnsupportedOperationException saying so. RemoteMessage, its Builder and Notification are an in-memory data holder
backed by a Bundle and read through the keys the Android SDK uses, SendException carries its error codes and
FirebaseMessagingService is a Service subclass whose callbacks are never invoked.

com.google.firebase.perf keeps traces and HTTP metrics in memory: Trace records its metrics (while running, and
atomically) and attributes, HttpMetric its response code, payload sizes, content type and attributes, and nothing is
reported. FirebasePerformance is a process singleton that FirebasePerfRegistrar also registers as a Firebase
component, so FirebaseApp.get(FirebasePerformance.class) works as on Android, and the PerformanceKt facade
(Firebase.performance, trace { }) is included. Trace and RemoteMessage are Parcelable like the Android classes.

For the Analytics items array, android.os.Bundle becomes Parcelable and stores parcelables and parcelable arrays,
which android.os.Parcel now writes and reads as values. Application.getProcessName() is added, as firebase-common
calls it when it reports that no default app is initialized. The version becomes 0.8.3.
Copilot AI balanced review requested due to automatic review settings November 29, 2026 07:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@nbransby
nbransby merged commit 22fdbd2 into master Nov 29, 2026
1 of 2 checks passed
@nbransby
nbransby deleted the analytics-messaging-perf branch November 29, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants