java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.NullPointerException

1.9k views Asked by At

Hi I am trying to build our app for its release variant but it triggers the following error when running the app for the first time.

Steps to replicate:

  1. Build a signed apk
  2. Install the apk on the emulator
  3. App Crash
FATAL EXCEPTION: main
Process: silicon.android.app.alpha, PID: 7837
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
         at android.app.ActivityThread.installProvider(ActivityThread.java:7493)
         at android.app.ActivityThread.installContentProviders(ActivityThread.java:6999)
         at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6770)
         at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134)
         at android.os.Handler.dispatchMessage(Handler.java:106)
         at android.os.Looper.loopOnce(Looper.java:201)
         at android.os.Looper.loop(Looper.java:288)
         at android.app.ActivityThread.main(ActivityThread.java:7898)
         at java.lang.reflect.Method.invoke(Native Method)
         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
      Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
         at com.google.firebase.components.AbstractComponentContainer.setOf(Unknown Source:220)
         at com.google.firebase.components.ComponentRuntime.setOf(ComponentRuntime.java:46)
         at com.google.firebase.components.RestrictedComponentContainer.setOf(RestrictedComponentContainer.java:150)
         at com.google.firebase.heartbeatinfo.DefaultHeartBeatController.lambda$component$4(DefaultHeartBeatController.java:157)
         at com.google.firebase.heartbeatinfo.DefaultHeartBeatController$$ExternalSyntheticLambda3.create(Unknown Source:0)
         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.FirebaseApp.initializeAllApis(FirebaseApp.java:606)
         at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:307)
         at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:271)
         at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:256)
         at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
         at android.content.ContentProvider.attachInfo(ContentProvider.java:2451)
         at android.content.ContentProvider.attachInfo(ContentProvider.java:2421)
         at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
         at android.app.ActivityThread.installProvider(ActivityThread.java:7488)
         at android.app.ActivityThread.installContentProviders(ActivityThread.java:6999) 
         at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6770) 
         at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2134) 
         at android.os.Handler.dispatchMessage(Handler.java:106) 
         at android.os.Looper.loopOnce(Looper.java:201) 
         at android.os.Looper.loop(Looper.java:288) 
         at android.app.ActivityThread.main(ActivityThread.java:7898) 
         at java.lang.reflect.Method.invoke(Native Method) 
         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Coincidentally, this only runs on release, but on debug it works fine. I have added -dontshrink, -dontoptimize, -dontobfuscate to my proguard rules which is why I could generate the stack trace.

Build Gradle Values

android {
    compileSdkVersion 33
    buildToolsVersion "33.0.0"
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 33
        versionCode 1
        versionName '0.1.0'
        consumerProguardFiles "consumer-rules.pro"
}

minifyEnabled, textCoverageEnabled, shrinkResources all turned to false

Firebase Libraries

"analytics"  : "com.google.firebase:firebase-analytics-ktx",
"crashlytics": "com.google.firebase:firebase-crashlytics-ktx",
"config"     : "com.google.firebase:firebase-config-ktx",
1

There are 1 answers

1
Android Noob On

To everyone who may have encountered this issue, it's because Dexguard obfuscation conflicts with some libraries I am using. In this case, the firebase libraries, crashlytics, and the desugaring SDK are notable.

Bringing down firebase and the desugaring SDK to older versions solved my issue.

If you encounter this next time, double-check your commits and look for SDK dependency updates. Start from there because the logs will not be helpful in any way.

GOODLUCK!