firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.28k stars 580 forks source link

NPE in sessions when packageInfo.versionName returns null #5195

Closed gerbiljames closed 1 year ago

gerbiljames commented 1 year ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

When the Firebase SDK is initialised in an environment where packageInfo.versionName returns null an NPE is thrown. This is specifically happening for instrumented tests when the testing target is an Android library and not an application.

Relevant Code:

Captured stack trace:

java.lang.NullPointerException: packageInfo.versionName must not be null
    at com.google.firebase.sessions.SessionEvents.getApplicationInfo(SessionEvents.kt:77)
    at com.google.firebase.sessions.FirebaseSessions.<init>(FirebaseSessions.kt:41)
    at com.google.firebase.sessions.FirebaseSessionsRegistrar.getComponents$lambda-0(FirebaseSessionsRegistrar.kt:48)
    at com.google.firebase.sessions.FirebaseSessionsRegistrar.$r8$lambda$JITndpZCWeA0w9BDlkcI3l22oGY(Unknown Source:0)
    at com.google.firebase.sessions.FirebaseSessionsRegistrar$$ExternalSyntheticLambda0.create(Unknown Source:0)
    at com.google.firebase.tracing.ComponentMonitor.lambda$processRegistrar$0(ComponentMonitor.java:38)
    at com.google.firebase.tracing.ComponentMonitor$$ExternalSyntheticLambda0.create(Unknown Source:4)
    at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0$com-google-firebase-components-ComponentRuntime(ComponentRuntime.java:140)
    at com.google.firebase.components.ComponentRuntime$$ExternalSyntheticLambda1.get(Unknown Source:4)
    at com.google.firebase.components.Lazy.get(Lazy.java:53)
    at com.google.firebase.components.ComponentContainer$-CC.$default$get(ComponentContainer.java:48)
    at com.google.firebase.components.ComponentRuntime.get(Unknown Source:0)
    at com.google.firebase.components.ComponentContainer$-CC.$default$get(ComponentContainer.java:24)
    at com.google.firebase.components.ComponentRuntime.get(Unknown Source:0)
    at com.google.firebase.components.RestrictedComponentContainer.get(RestrictedComponentContainer.java:89)
    at com.google.firebase.crashlytics.CrashlyticsRegistrar.buildCrashlytics(CrashlyticsRegistrar.java:69)
    at com.google.firebase.crashlytics.CrashlyticsRegistrar.$r8$lambda$Pfd5XmDCFzNyAT9o9H6rDnTBQE4(Unknown Source:0)
    at com.google.firebase.crashlytics.CrashlyticsRegistrar$$ExternalSyntheticLambda0.create(Unknown Source:2)
    at com.google.firebase.tracing.ComponentMonitor.lambda$processRegistrar$0(ComponentMonitor.java:38)
    at com.google.firebase.tracing.ComponentMonitor$$ExternalSyntheticLambda0.create(Unknown Source:4)
    at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0$com-google-firebase-components-ComponentRuntime(ComponentRuntime.java:140)
    at com.google.firebase.components.ComponentRuntime$$ExternalSyntheticLambda1.get(Unknown Source:4)
    at com.google.firebase.components.Lazy.get(Lazy.java:53)
    at com.google.firebase.components.ComponentRuntime.doInitializeEagerComponents(ComponentRuntime.java:302)
    at com.google.firebase.components.ComponentRuntime.initializeEagerComponents(ComponentRuntime.java:292)
    at com.google.firebase.FirebaseApp.initializeAllApis(FirebaseApp.java:607)
    at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:300)
    at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:264)
google-oss-bot commented 1 year ago

I found a few problems with this issue:

mrober commented 1 year ago

@gerbiljames the easiest way to resolve this would be to add a android:versionName to the AndroidManifest file in your instrumented tests. See https://github.com/firebase/firebase-android-sdk/blob/master/firebase-sessions/src/androidTest/AndroidManifest.xml for an example. We will make a change in Firebase to mitigate this to make testing easier.

gerbiljames commented 1 year ago

@mrober That fixed it thanks. I originally tried to specify it in build.gradle for the library but it wasn't being populated in the manifest for some reason.

mrober commented 1 year ago

This is fixed in the latest versions of Sessions and Crashlytics.