Firebase Auth'createUserWithEmailAndPassword'失败”返回了Gms:com.google.firebase.auth.api.internal.zzam@290f989

时间:2019-04-14 10:17:20

标签: java android firebase-authentication

我可以登录通过Firebase(FB)控制台添加的用户,但不能在应用中添加用户。

我在解决的依赖项版本方面以及在API密钥方面都有错误,因此我添加了SHA1并将新的google-services.json下载到我的应用中。

我没有收到任何异常或错误,但是根本无法正常工作。

项目级别build.gradle依赖性->

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'com.google.gms:google-services:4.2.0'
    }

与FB相关的应用级build.gradle依赖关系->

dependencies {
...
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-auth:16.2.1'
    implementation 'com.google.android.gms:play-services-gcm:16.1.0'
    implementation 'com.google.firebase:firebase-firestore:18.2.0'
}

FB控制台设置->

Firebase Console App Config https://photos.app.goo.gl/HPBA5BjDMb2zV6gZ8

Firebase Console Project Info https://photos.app.goo.gl/fuzuGZrMTFXPQ2cx8

google-services.json->

{
  "project_info": {
    "project_number": "364******410",
    "firebase_url": "https://scrumpoker1.firebaseio.com",
    "project_id": "scrumpoker1",
    "storage_bucket": "scrumpoker1.appspot.com"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:364*****7410:android:a*********7e565a",
        "android_client_info": {
          "package_name": "com.example.scrumpoker"
        }
      },
      "oauth_client": [
        {
          "client_id": "364******410-***************3fqa18ar***8uejtr.apps.googleusercontent.com",
          "client_type": 1,
          "android_info": {
            "package_name": "com.example.scrumpoker",
            "certificate_hash": "4141********ce7744********521873****a7d0"
          }
        },
        {
          "client_id": "364******410-***************55aq16hp***lbjrm5.apps.googleusercontent.com",
          "client_type": 3
        }
      ],
      "api_key": [
        {
          "current_key": "AIza******sdR1ISugd70l9H1k**********pCo"
        }
      ],
      "services": {
        "appinvite_service": {
          "other_platform_oauth_client": [
            {
              "client_id": "364******410-***************55aq16hp***lbjrm5.apps.googleusercontent.com",
              "client_type": 3
            }
          ]
        }
      }
    }
  ],
  "configuration_version": "1"
}

MainActivity.java OnCreate方法->

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize Firebase Auth
       mAuth = FirebaseAuth.getInstance();

       emailEditText = findViewById(R.id.emailEditText);
       passwordEditText = findViewById(R.id.passwordEditText);


       if (mAuth.getCurrentUser() != null){
            try {
               showPokerActivity();
            } catch ( Exception e){
                e.printStackTrace();
                Log.i("Login", "*****FAILED AT firebaseAuth getCurrentUser*****");
            }
       }


    }

如下所示,registerModeActive为true,应用程序命中Log.i("Create User With Email","********START EXECUTE******** " + registerModeActive);。然后,它到达Firebase,然后跳到else并记录Log.i("Create User With Email", "********FAIL********");

MainActivity.java创建用户方法->

    public void registerClicked(View view) throws ParseException {

        } else {
            if(registerModeActive) {
                //Register
                Log.i("Create User With Email","********START EXECUTE******** " + registerModeActive);

                String email = emailEditText.toString();
                String password = passwordEditText.toString();

                mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
                            @Override
                            public void onComplete(@NonNull Task<AuthResult> task) {
                                if (task.isSuccessful()){
                                    Log.i("Create User With Email","********SUCCESS********");
                                    showPokerActivity();
                                } else {
                                    Log.i("Create User With Email", "********FAIL********");
                                    Toast.makeText(MainActivity.this,"Authentication Failed",Toast.LENGTH_SHORT).show();
                                }
                            }
                        });

            } else{
                //Login
...

Logcat输出->

2019-04-14 10:39:34.498 13543-13543/com.example.scrumpoker I/Create User With Email: ********START EXECUTE******** true
2019-04-14 10:39:34.504 13543-13543/com.example.scrumpoker W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzam@290f989
2019-04-14 10:39:35.126 13543-13543/com.example.scrumpoker I/Create User With Email: ********FAIL********
2019-04-14 10:39:35.206 13543-13580/com.example.scrumpoker D/EGL_emulation: eglMakeCurrent: 0xa7f86f00: ver 3 0 (tinfo 0xafd8df90)
2019-04-14 10:39:35.628 13543-13580/com.example.scrumpoker D/EGL_emulation: eglMakeCurrent: 0xa7f86f00: ver 3 0 (tinfo 0xafd8df90)
  • 从头开始在Firebase中重新创建我的项目两次。
  • 多次为我的项目重新生成我的google-services.json。
  • 调试了我的build.gradle依赖版本,以解决所有冲突。
  • 添加了SHA1,并再次重新生成了google-services.json。
  • 在onCreate中尝试了mAuth.getCurrentUser的变体。
  • 尝试在createUserWithEmailAndPasword函数中处理电子邮件和密码。
  • 清洁版本
  • 我在控制台上的项目Web API密钥与我的google-services.json中的api_key不匹配。我尝试在我的google-services.json中手动将其切换出去,但没有成功。

预期结果:将新用户添加到Firebase用户身份验证。 实际结果:什么也没发生。

1 个答案:

答案 0 :(得分:0)

它总是让我着迷,答案如此简单! :)

我忘记了getText()

mAuth.createUserWithEmailAndPassword(emailEditText.toString(), passwordEditText.toString())

将以上内容替换为

mAuth.createUserWithEmailAndPassword(emailEditText.getText().toString(), passwordEditText.getText().toString())

Mea Culpa!