【问题标题】:NPE on FirebaseFunctions getInstanceFirebaseFunctions 上的 NPE
【发布时间】:2019-04-06 15:33:00
【问题描述】:

当调用FirebaseFunctions.getInstance(FirebaseApp.getInstance()) 时会抛出一个 NPE。 FirebaseApp.initializeApp(this); 在调用任何其他 Firebase 功能之前在扩展 App 类 onCreate 中调用。

这是堆栈跟踪:

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.** { *; }
...

我正在使用:

  • com.google.firebase:firebase-functions:12.0.1(所有其他 Firebase 库也使用相同的版本)
  • DexGuard 版本 8.1.15
  • 类路径“com.google.gms:google-services:4.0.1”

当使用调试配置时,一切都像魅力一样,知道如何解决这个问题吗?

已经检查过这个类似的问题,但它已经过时了:Error with Firebase callable functions

编辑 - 新配置

我尝试使用以下内容更新 DexGuard 依赖项和 Firebase 之一:

  • com.google.firebase:firebase-functions:16.1.1(所有其他 firebase 和 gms 依赖项都更新到最新的,除了 play-services-ads 是 16.0.0)
  • DexGuard 版本 8.2.20
  • 类路径“com.google.gms:google-services:4.0.1”

这是新的堆栈跟踪:

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)

【问题讨论】:

    标签: android firebase google-cloud-functions dexguard


    【解决方案1】:

    对于可能面临同样问题的人,这是由于 SDK 使用 FirebaseOptions.fromResource(Context) 初始化 FirebaseOptions 并使用 DexGuard 保护应用程序时,“projectId”字段为 null 引起的

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

    问题已通过在 DexGuard 配置文件中添加以下行来解决:

    -keepresources string/project_id 
    

    【讨论】:

      猜你喜欢
      • 2021-03-05
      • 2019-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多