2

When invoking FirebaseFunctions.getInstance(FirebaseApp.getInstance()) an NPE is thrown. FirebaseApp.initializeApp(this); is called inside extended App class onCreate before calling any other firebase functionality.

This is the stacktrace:

Fatal Exception: java.lang.NullPointerException
       at com.google.firebase.functions.internal.Preconditions.checkNotNull(Unknown Source:876)
       at com.google.firebase.functions.FirebaseFunctions.<init>(Unknown Source:77)
       at com.google.firebase.functions.FirebaseFunctions.getInstance(Unknown Source:141)
       at com.google.firebase.functions.FirebaseFunctions.getInstance(Unknown Source:159)

The exception is thrown only when building the application with release configuration, this means the code gets obfuscated with DexGuard but all firebase classes have been excluded from the obfuscation, below my dexguard config:

...
-keep class com.google.** { *; }
-keep class android.** { *; }
-keep class com.firebase.** { *; }
-keep class com.android.** { *; }
...

I'm using:

  • com.google.firebase:firebase-functions:12.0.1 (also all other firebase libraries use the same version)
  • DexGuard version 8.1.15
  • classpath 'com.google.gms:google-services:4.0.1'

When using debug configuration everything works like charm, any idea how to solve this?

Already checked this similar question but it's outdated: Error with Firebase callable functions

EDIT - New configuration

I tried updating both DexGuard dependency and Firebase one with the ones below:

  • com.google.firebase:firebase-functions:16.1.1 (all other firebase and gms dependencies are updated to the latest one, except for play-services-ads that is 16.0.0)
  • DexGuard version 8.2.20
  • classpath 'com.google.gms:google-services:4.0.1'

This is the new stacktrace:

Fatal Exception: java.lang.NullPointerException: null reference
       at com.google.firebase.functions.a.a.a(Unknown Source:30)
       at com.google.firebase.functions.FirebaseFunctions.(Unknown Source:77)
       at com.google.firebase.functions.FirebaseFunctions.getInstance(Unknown Source:141)
       at com.google.firebase.functions.FirebaseFunctions.getInstance(Unknown Source:154)
Jameido
  • 1,344
  • 1
  • 11
  • 21

1 Answers1

3

For the ones who may face the same problem, it was caused by the "projectId" field being null when the FirebaseOptions were initialised by the sdk using FirebaseOptions.fromResource(Context) and the app was protected with DexGuard

FirebaseOptions {
    applicationId = ***********************, 
    apiKeyapiKey = ***********************, 
    databaseUrl = ***********************, 
    gcmSenderId = ***********************, 
    storageBucket = ***********************, 
    projectId = null
} 

The problem has been solved by adding the following line to the DexGuard config file:

-keepresources string/project_id 
Jameido
  • 1,344
  • 1
  • 11
  • 21