我在应用启动时就将NPE用于生产环境,并且仅在使用adb重新安装后才得到一次。
Caused by java.lang.NullPointerException
Attempt to invoke interface method 'void com.google.firebase.database.obfuscated.f.a(java.lang.Runnable)' on a null object reference
com.google.firebase.database.obfuscated.zzab.zza (SourceFile:276)
com.google.firebase.database.obfuscated.zzab. (SourceFile:90)
com.google.firebase.database.obfuscated.zzad.zzb (SourceFile:101)
com.google.firebase.database.obfuscated.zzad.zza (SourceFile:42)
com.google.firebase.database.FirebaseDatabase.zza (SourceFile:357)
com.google.firebase.database.FirebaseDatabase.getReference(SourceFile:201)
我想无论将什么引用传递给getReference()方法,我都不应获取NPE-尽管我传递的是正确的引用。
以下Firebase版本似乎会发生这种情况:
firebase_core_version = "16.0.3"
firebase_auth_version = "16.0.3"
firebase_database_version = "16.0.2"
我无法使用以下方式复制它:
firebase_core_version = "16.0.0"
firebase_auth_version = "16.0.1"
firebase_database_version = "16.0.1"
答案 0 :(得分:1)
我将firebase-ui-database从4.2.0降级到4.1.0,问题消失了
答案 1 :(得分:1)
将其添加到ProGuard配置中,以便将这些类排除在混淆之外:
-keep,includedescriptorclasses class com.google.firebase.** { *; }
事实上,只有发行版本受到影响的提示-
不同的库版本可能提供不同的(库)使用者规则。
答案 2 :(得分:0)
FirebaseMessagingService导致了我的问题。因此,要复制,请添加:
清单:
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
MyFirebaseMessagingService.class
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String token) {
try{
DatabaseReference fRef = FirebaseDatabase.getInstance().getReference();
// I am getting the reference to write the token in firebase database like:
// fRef.child("token").setValue(token);
} catch (Exception e) {
Log.d("MyFirebaseMsgService", e.getStackTrace().toString());
}
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
}
}
在firebase-database 16.0.2中,行DatabaseReference fRef = FirebaseDatabase.getInstance().getReference();
引发异常:
无法在未调用的线程内创建处理程序 Looper.prepare()
而在16.0.1中则不是。
触发此异常后,下一个firebaseDatabase.getReference()
会崩溃,并带有最初描述的异常。
依赖项:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-messaging:17.3.1'
implementation 'com.google.firebase:firebase-invites:16.0.3'
implementation 'com.firebaseui:firebase-ui-auth:4.2.0'
implementation 'com.firebaseui:firebase-ui-database:4.2.0'
// implementation('com.firebaseui:firebase-ui-database:4.2.0') {
// exclude group: 'com.google.firebase', module: 'firebase-database'
// }
// implementation 'com.google.firebase:firebase-database:16.0.1'
}