1

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",
  • You have a NullPointerException. Now tell us which pointer == null? And post the relevant code. – blackapps Jan 08 '23 at 10:50
  • Does it crash at install? – blackapps Jan 08 '23 at 10:51
  • It crashes when the app starts after it installs. About your first question, that is the problem it doesn't link to any code and crashes. This is a full stack trace. I already tried updating google-services.json, checked app id, and updated the 3rd party libraries. – Android Noob Jan 08 '23 at 11:17
  • Then what has your app to do with Firebase? – blackapps Jan 08 '23 at 11:21
  • Comment all code in onCreate(). – blackapps Jan 08 '23 at 11:22
  • Tried these ? https://stackoverflow.com/questions/37312103/unable-to-get-provider-com-google-firebase-provider-firebaseinitprovider – Gowtham K K Jan 08 '23 at 11:24
  • 1. Okay, trying out to comment out all onCreate on the starting activity. -> Still crashed but now pointing to FirebaseCrashlytics uncaught exceptions. 2. We already have the applicationId on our defaultConfig 3. Our minimum SDK is 23 so it should be okay to not have a problem with MultiDex – Android Noob Jan 08 '23 at 11:38

1 Answers1

0

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!

  • I still struggling with same error you shared. but only difference is I have the apk not the source. so how can I desugure it and downgrade firebase? – hanan Jul 01 '23 at 17:47