firebase / firebase/firebase-android-sdk

firebase-messaging: NoClassDefFoundError for AnalyticsConnector when firebase-measurement-connector is excluded

Open
#8,281 4 comments 0 reactions 0 assignees View on GitHub
api: analytics api: messaging
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

### [READ] Step 1: Are you in the right place? ✅

### [REQUIRED] Step 2: Describe your environment

- Android Studio version: N/A
- Firebase Component: `firebase-messaging`
- Component version: `25.0.2`

### [REQUIRED] Step 3: Describe the problem

firebase-messaging calls `MessagingAnalytics.logToScion()` when the intent carries the "google.c.a.e=1" extra (`Constants.AnalyticsKeys.ENABLED`). `logToScion()` references `AnalyticsConnector` as a local variable type (despite the nearby TODO `b/78465387`) which causes a `NoClassDefFoundError` at method-invocation time on any build that excludes firebase-analytics. The SDK comment claims missing analytics is handled gracefully, but the class-load crash happens before any null-check can run.

[Culprit code](https://github.com/firebase/firebase-android-sdk/blob/6161b2904cf96ec8be50b77170906aa7422f9f86/firebase-messaging/src/main/java/com/google/firebase/messaging/MessagingAnalytics.java#L311-L320)

#### Steps to reproduce:

1. Fully disable Firebase Measurement Connector as per [this Stack Overflow answer](https://stackoverflow.com/a/56853571). Most notably: `exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'` _\[edit: corrected from Firebase Analytics -> Firebase Measurement Connector\]_
2. Send a test Firebase message whilst target app is open
3. Observe crash:
```
FATAL EXCEPTION: Firebase-Messaging-Intent-Handle
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/analytics/connector/AnalyticsConnector;
at com.google.firebase.messaging.MessagingAnalytics.logToScion(MessagingAnalytics.java:313)
at com.google.firebase.messaging.MessagingAnalytics.logNotificationReceived(MessagingAnalytics.java:80)
at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(FirebaseMessagingService.java:202)
at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(FirebaseMessagingService.java:190)
at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(FirebaseMessagingService.java:179)
at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$com-google-firebase-messaging-EnhancedIntentService(EnhancedIntentService.java:82)
at com.google.firebase.messaging.EnhancedIntentService$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1100)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.3.0:2)
```

#### Workaround

Stripping the extra by overriding `handleIntent` in a custom `FirebaseMessagingService` prevents `shouldUploadScionMetrics()` from returning true, so `logToScion()` is never entered and AnalyticsConnector is never loaded.

```kt
class MyFcmService : FirebaseMessagingService() {
override fun handleIntent(intent: Intent) {
intent.removeExtra("google.c.a.e")
super.handleIntent(intent)
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.