首页 > android > FirebaseAuth.getInstance()为null

FirebaseAuth.getInstance()为null (FirebaseAuth.getInstance() is null)

问题

我更新了com.google.firebase:firebase-core:16.0.7com.google.firebase:firebase-auth:16.1.0但我的代码中没有更改任何内容,现在FirebaseAuth.getInstance()为null。

java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.auth.FirebaseUser com.google.firebase.auth.FirebaseAuth.getCurrentUser()' on a null object reference

我想检查用户是否已登录 FirebaseAuth.getInstance().getCurrentUser()

我在gradle sync时遇到这些错误(但它已成功完成): 在此输入图像描述

解决方法

我发现了这个错误的原因。tools:node="replace"由于依赖性,我添加到了我的AndroidManifest.xml。当我删除它一切都工作正常。

问题

I updated com.google.firebase:firebase-core:16.0.7 and com.google.firebase:firebase-auth:16.1.0 but I didn't changed anything in my code and now FirebaseAuth.getInstance() is null.

java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.auth.FirebaseUser com.google.firebase.auth.FirebaseAuth.getCurrentUser()' on a null object reference

I want to check if the user is signed in or not with FirebaseAuth.getInstance().getCurrentUser()

And I get these errors while gradle sync(but it was completed successfully): enter image description here

解决方法

I found out the reason for this error. I added tools:node="replace" to my AndroidManifest.xml because of a dependency. As I removed it all worked fine again.

相似信息