Firebase Android Auth对象没有回调触发

时间:2021-01-17 23:13:20

I've been going through the Firebase docs to set up a user authentication system in my android app. For some reason however, it doesn't look like any of the callbacks are running on my FirebaseAuth object!

我一直在浏览Firebase文档,在我的Android应用程序中设置用户身份验证系统。但是出于某种原因,它看起来不像我的FirebaseAuth对象上运行的任何回调!

For example with setting up the Facebook authentication as instructed here

例如,按照此处的说明设置Facebook身份验证

private void handleFacebookAccessToken(AccessToken token) {
    Log.d("AUTH", "handleFacebookAccessToken:" + token.getToken());
    // ...
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    Log.d("AUTH", "Credential: "+credential);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d("AUTH", "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w("AUTH", "signInWithCredential", task.getException());
                        Toast.makeText(LoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // ...
                }
            });
}

Everything fine on the part of Facebook but when it comes to signing in with the retrieved fb credentials, the signInWithCredential function doesn't run any callbacks and nothing seems to happen in my user database.

Facebook的一切都很好,但是当使用检索到的fb凭证登录时,signInWithCredential函数不会运行任何回调,并且我的用户数据库中似乎没有发生任何事情。

Furthermore I've tried the much more simpler

此外,我尝试了更简单

mAuth.createUserWithEmailAndPassword(etUserID.getText().toString(), etPassword.getText().toString());

and nothing happens as well. I've enabled both providers in my Firebase console and downloaded the latest google-services.json file for the project. Am I missing something?

也没有任何事情发生。我在Firebase控制台中启用了两个提供程序,并下载了该项目的最新google-services.json文件。我错过了什么吗?

EDIT: Just tried running the quick-start authentication demo and it doesn't work as well. I do see on my emulator that this app won't run unless I update google services. Is this the cause of this error? I tried updating google services on various emulators and that just returns an error.

编辑:刚尝试运行快速启动身份验证演示,它也不起作用。我确实在我的模拟器上看到,除非我更新谷歌服务,否则此应用程序将无法运行。这是导致此错误的原因吗?我尝试在各种模拟器上更新谷歌服务,只是返回错误。

6 个解决方案

#1


5  

Got it working only on a real android device, but had no lucky with the emulator.

它只在一个真正的Android设备上工作,但没有幸运的模拟器。

For the device, you'll need to add the following dependency in your app gradle file:

对于设备,您需要在app gradle文件中添加以下依赖项:

compile 'com.google.android.gms:play-services-auth:9.0.2'

I haven't tested, but it seems that if you update the emulator image with a newer google play services, it also should work.

我还没有测试,但似乎如果你用更新的谷歌播放服务更新模拟器图像,它也应该工作。

Hope it helps.

希望能帮助到你。

#2


3  

It seems like the issue is caused by certain emulators not supporting the latest versions of Google Play Services! (You will see an error in logcat) Galaxy Nexus 5x API 23 w/ Google APIs seem to work with logins.

似乎问题是某些模拟器不支持最新版本的Google Play服务! (您将在logcat中看到错误)带有Google API的Galaxy Nexus 5x API 23似乎可以与登录一起使用。

#3


3  

Solved it thanks to @feroult post and other resources. In my case OnCompleteListener was never called after I updated the build.gradle with the new version of Play Services Library and Firebase libraries. The solution is to update the Play Services App installed on the Emulator.

In my case it started working with 11.0.4 version of Play services library and 11.3.02 version of Play Services app installed on Emulator.

由于@feroult帖子和其他资源解决了它。在我的情况下,在使用新版本的Play Services Library和Firebase库更新build.gradle之后,从未调用过OnCompleteListener。解决方案是更新模拟器上安装的Play服务应用程序。在我的情况下,它开始使用11.0.4版本的Play服务库和安装在模拟器上的11.3.02版本的Play服务应用程序。

Firebase Android Auth对象没有回调触发 Firebase Android Auth对象没有回调触发

#4


0  

I had the same issue and eventually in my case i forgot enable it in firebase console

我有同样的问题,最终在我的情况下,我忘了在firebase控制台中启用它

Firebase Android Auth对象没有回调触发

#5


0  

On a physical device, I did need to update Google Play Services in order to get the callback to work

在物理设备上,我确实需要更新Google Play服务才能使回调正常工作

#6


0  

I had the same problem here, and the solution was very simple: stop using the emulator and start using a physical device to test the application. I don't know why, but it seems like the emulator has some problems dealing with firebase :/

我在这里遇到了同样的问题,解决方案非常简单:停止使用模拟器并开始使用物理设备来测试应用程序。我不知道为什么,但似乎模拟器在处理firebase时遇到了一些问题:/

#1


5  

Got it working only on a real android device, but had no lucky with the emulator.

它只在一个真正的Android设备上工作,但没有幸运的模拟器。

For the device, you'll need to add the following dependency in your app gradle file:

对于设备,您需要在app gradle文件中添加以下依赖项:

compile 'com.google.android.gms:play-services-auth:9.0.2'

I haven't tested, but it seems that if you update the emulator image with a newer google play services, it also should work.

我还没有测试,但似乎如果你用更新的谷歌播放服务更新模拟器图像,它也应该工作。

Hope it helps.

希望能帮助到你。

#2


3  

It seems like the issue is caused by certain emulators not supporting the latest versions of Google Play Services! (You will see an error in logcat) Galaxy Nexus 5x API 23 w/ Google APIs seem to work with logins.

似乎问题是某些模拟器不支持最新版本的Google Play服务! (您将在logcat中看到错误)带有Google API的Galaxy Nexus 5x API 23似乎可以与登录一起使用。

#3


3  

Solved it thanks to @feroult post and other resources. In my case OnCompleteListener was never called after I updated the build.gradle with the new version of Play Services Library and Firebase libraries. The solution is to update the Play Services App installed on the Emulator.

In my case it started working with 11.0.4 version of Play services library and 11.3.02 version of Play Services app installed on Emulator.

由于@feroult帖子和其他资源解决了它。在我的情况下,在使用新版本的Play Services Library和Firebase库更新build.gradle之后,从未调用过OnCompleteListener。解决方案是更新模拟器上安装的Play服务应用程序。在我的情况下,它开始使用11.0.4版本的Play服务库和安装在模拟器上的11.3.02版本的Play服务应用程序。

Firebase Android Auth对象没有回调触发 Firebase Android Auth对象没有回调触发

#4


0  

I had the same issue and eventually in my case i forgot enable it in firebase console

我有同样的问题,最终在我的情况下,我忘了在firebase控制台中启用它

Firebase Android Auth对象没有回调触发

#5


0  

On a physical device, I did need to update Google Play Services in order to get the callback to work

在物理设备上,我确实需要更新Google Play服务才能使回调正常工作

#6


0  

I had the same problem here, and the solution was very simple: stop using the emulator and start using a physical device to test the application. I don't know why, but it seems like the emulator has some problems dealing with firebase :/

我在这里遇到了同样的问题,解决方案非常简单:停止使用模拟器并开始使用物理设备来测试应用程序。我不知道为什么,但似乎模拟器在处理firebase时遇到了一些问题:/