当调用FirebaseFunctions.getInstance(FirebaseApp.getInstance())
时,抛出一个npe。FirebaseApp.initializeApp(this);
在调用任何其他firebase功能之前在扩展应用程序类中调用。
这是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)
只有在使用发布配置构建应用程序时才会引发异常,这意味着代码会被dexguard混淆,但所有firebase类都已从混淆中排除,在我的dexguard配置下面:
...
-keep class com.google.** { *; }
-keep class android.** { *; }
-keep class com.firebase.** { *; }
-keep class com.android.** { *; }
...
我用的是:
firebase:firebase函数:12.0.1(其他所有firebase库也使用相同的版本)
DexGuard版本8.1.15
类路径“com.google.gms:google服务:4.0.1”
当使用调试配置时,一切工作都很有魅力,知道如何解决这个问题吗?
已经检查过类似的问题,但已经过时:Error with Firebase callable functions
编辑-新配置
我尝试用下面的更新dexguard依赖项和firebase one:
firebase:firebase函数:16.1.1(所有其他firebase和gms依赖项都更新为最新的,除了16.0.0的play services广告)
DexGuard版本8.2.20
类路径“com.google.gms:google服务:4.0.1”
这是新的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)
最佳答案
对于那些可能面临同样问题的人来说,这是由于sdk使用null
初始化firebaseoptions时projectd字段被FirebaseOptions.fromResource(Context)
引起的,并且应用程序受到dexguard的保护。
FirebaseOptions {
applicationId = ***********************,
apiKeyapiKey = ***********************,
databaseUrl = ***********************,
gcmSenderId = ***********************,
storageBucket = ***********************,
projectId = null
}
通过将以下行添加到dexguard配置文件中,解决了该问题:
-keepresources string/project_id