Firebase用户登录失败,邮箱com.google.firebase无效。身份验证未找到

时间:2021-12-13 20:56:18

My LoginActivity contains EditTexts for user to input their email and password. All codes seems OK to me.

我的LoginActivity包含了EditTexts,用户可以输入他们的电子邮件和密码。我觉得所有的代码都没问题。

However, after clicking the login button, the user does not login. It turns out that the email is invalid, in which the EditText of email contains as following:

但是,点击登录按钮后,用户不会登录。原来邮件是无效的,其中电子邮件的EditText包含如下内容:

android.support.v7.widget.AppCompatEditText{b014ce3 VFED..CL. .F...... 56,646-1384,804 #7f0d0096 app:id/etEmailLogin}

Please help me to find what's wrong.

请帮我找出问题所在。

package com.example.loyalfine.myponda.app;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class LoginActivity extends AppCompatActivity {

    private static final String TAG = "LoginActivity";
    private FirebaseAuth.AuthStateListener mAuthListener;
    private FirebaseAuth mAuth;
    private EditText etEmailLogin;
    private EditText etPasswordLogin;

    private Button bLogin;
    private Button bSwitchToRegister;
    private Button bResetPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        mAuth = FirebaseAuth.getInstance();

        Toast.makeText(LoginActivity.this, (findViewById(R.id.etEmailLogin)).toString().trim(), Toast.LENGTH_LONG).show();

        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth         firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                if (user != null) {
                    // User is signed in
                    Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
                    Toast.makeText(LoginActivity.this, "onAuthStateChanged:signed_in:", Toast.LENGTH_LONG).show();

                } else {
                    // User is signed out
                    Log.d(TAG, "onAuthStateChanged:signed_out");
                    Toast.makeText(LoginActivity.this, "onAuthStateChanged:signed_out:", Toast.LENGTH_LONG).show();
                }
            }
        };

        etEmailLogin = (EditText) findViewById(R.id.etEmailLogin);
        etPasswordLogin = (EditText) findViewById(R.id.etPasswordLogin);
        bLogin = (Button) findViewById(R.id.bLogin);
        bLogin.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                signIn();
            }
        });
        bSwitchToRegister = (Button) findViewById(R.id.bSwitchToRegister);
        bSwitchToRegister.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent in = new Intent(LoginActivity.this, RegisterActivity.class);
                startActivity(in);
            }
        });
        bResetPassword = (Button) findViewById(R.id.bResetPassword);
        bResetPassword.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //TODO:     com.firebase.ui.auth.ui.email.ConfirmRecoverPasswordActivity
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
    }

    @Override
    public void onStop() {
        super.onStop();
        if (mAuthListener != null) {
            mAuth.removeAuthStateListener(mAuthListener);
        }
    }

    public void signIn() {
        final String passwordl = etPasswordLogin.toString().trim();
        final String emaill = etEmailLogin.toString().trim();

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        Toast.makeText(LoginActivity.this, user.getEmail()+"; "+    (findViewById(R.id.etEmailLogin)).toString().trim(), Toast.LENGTH_LONG).show();
    Log.d(TAG, emaill);

        mAuth.signInWithEmailAndPassword(emaill, passwordl);
        Intent in = new Intent(LoginActivity.this, WelcomeActivity.class);
        startActivity(in);
    };
}

And my LoginActivity Layout is

我的LoginActivity布局是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.loyalfine.myponda.app.LoginActivity"
    android:orientation="vertical"
    android:gravity="center_vertical">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Enter your Email"
        android:id="@+id/etEmailLogin"
        android:inputType="textEmailAddress" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/etPasswordLogin"
        android:ems="10"
        android:hint="Enter your password"
        android:inputType="textPassword"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login"
        android:id="@+id/bLogin"
        android:layout_gravity="center_horizontal"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Not registered yet? Click here for redistration!"
        android:id="@+id/bSwitchToRegister"
        android:layout_gravity="center_horizontal"
        android:clickable="true"
        android:background="#0000"
        android:textColor="#0a68ec"
        android:textSize="12dp"
        android:foreground="#0000" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Forget password? Click here to reset your password!"
        android:id="@+id/bResetPassword"
        android:layout_gravity="center_horizontal"
        android:onClick="onClick"
        android:textColor="#ed7a41"
        android:textSize="10dp"
        android:background="#0000" />

</LinearLayout>

following message:

以下信息:

09-11 03:00:24.280 32751-32751/com.example.loyalfine.myponda.app W/ViewRootImpl[WelcomeActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=205.09277, y[0]=2066.7188, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=20468343, downTime=20463897, deviceId=0, source=0x1002 }
09-11 03:00:24.521 32751-32751/com.example.loyalfine.myponda.app D/LoginActivity: android.support.v7.widget.AppCompatEditText{b014ce3 VFED..CL. .F...... 56,646-1384,804 #7f0d0096 app:id/etEmailLogin}
09-11 03:00:24.567 32751-398/com.example.loyalfine.myponda.app W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

Both two Toasts shows the same content as:

两个祝酒词的内容都是一样的:

android.support.v7.widget.AppCompatEditText{b014ce3 VFED..CL. .F...... 56,646-1384,804 #7f0d0096 app:id/etEmailLogin}

Also, please let me know why this is appearing:

同时,请让我知道为什么会出现这种情况:

Local module descriptor class for com.google.firebase.auth not found.

Thanks for your kindness.

谢谢你的好意。

UPDATES: After adding getText()s, and onCompleteListener, the messages shows:

更新:添加getText()s和onCompleteListener后,消息显示:

09-11 07:36:28.969 30405-30405/com.example.loyalfine.myponda.app W/ViewRootImpl[LoginActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=157.06055, y[0]=2073.6719, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=37033032, downTime=36201038, deviceId=0, source=0x1002 }
09-11 07:36:28.969 30405-30405/com.example.loyalfine.myponda.app W/ViewRootImpl[LoginActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=157.06055, y[0]=2073.6719, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=37033032, downTime=36201038, deviceId=0, source=0x1002 }
09-11 07:36:28.969 30405-30405/com.example.loyalfine.myponda.app W/ViewRootImpl[LoginActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=157.06055, y[0]=2073.6719, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=37033032, downTime=36201038, deviceId=0, source=0x1002 }
09-11 07:36:28.969 30405-30405/com.example.loyalfine.myponda.app W/ViewRootImpl[LoginActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=157.06055, y[0]=2073.6719, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=37033032, downTime=36201038, deviceId=0, source=0x1002 }
09-11 07:36:31.559 30405-30416/com.example.loyalfine.myponda.app I/art: Background sticky concurrent mark sweep GC freed 12136(1617KB) AllocSpace objects, 54(1220KB) LOS objects, 24% free, 9MB/12MB, paused 6.324ms total 111.816ms
09-11 07:36:31.770 30405-30405/com.example.loyalfine.myponda.app D/***LoginActivity: onAuthStateChanged:signed_in:8cG1dBsCFlNDAWiQHXAN4NSaulN2***
09-11 07:36:36.797 30405-30405/com.example.loyalfine.myponda.app W/ViewRootImpl[WelcomeActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=153.06152, y[0]=2073.6719, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=37040855, downTime=37035146, deviceId=0, source=0x1002 }
09-11 07:36:36.797 30405-30405/com.example.loyalfine.myponda.app W/ViewRootImpl[WelcomeActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=153.06152, y[0]=2073.6719, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=37040855, downTime=37035146, deviceId=0, source=0x1002 }
09-11 07:36:36.797 30405-30405/com.example.loyalfine.myponda.app W/ViewRootImpl[WelcomeActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=153.06152, y[0]=2073.6719, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=37040855, downTime=37035146, deviceId=0, source=0x1002 }
09-11 07:36:36.797 30405-30405/com.example.loyalfine.myponda.app W/ViewRootImpl[WelcomeActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=153.06152, y[0]=2073.6719, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=37040855, downTime=37035146, deviceId=0, source=0x1002 }
09-11 07:36:42.688 30405-30405/com.example.loyalfine.myponda.app W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
09-11 07:36:45.336 30405-30405/com.example.loyalfine.myponda.app W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
09-11 07:36:45.966 30405-30405/com.example.loyalfine.myponda.app D/LoginActivity: ***android.support.v7.widget.AppCompatEditText{2ad64b4 VFED..CL. ........ 56,646-1384,804 #7f0d0096 app:id/etEmailLogin}***
09-11 07:36:45.983 30405-30444/com.example.loyalfine.myponda.app W/DynamiteModule: Local module descriptor class for ***com.google.firebase.auth not found.***
09-11 07:36:45.983 30405-30444/com.example.loyalfine.myponda.app W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
09-11 07:36:56.234 30405-30444/com.example.loyalfine.myponda.app W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

2 个解决方案

#1


1  

First, make sure that everything looks good in the Firebase console (accounts are there, etc...)

首先,确保在Firebase控制台中一切都看起来很好(帐户在那里,等等…)

Right now there doesn't seem to be any code to handle the case where the sign-in isn't successful. I just implemented a sign-in with Firebase in my app, so here's the code I use when a user presses the sign-in button. (Note: I've just noticed a bug where the button is not set to clickable again before the return statements, but other than that everything is fine)

现在似乎没有任何代码来处理登录失败的情况。我刚刚在我的应用程序中实现了一个带有Firebase的登录,这是我在用户按下登录按钮时使用的代码。(注意:我刚刚注意到一个bug,在返回语句之前,按钮没有再次被设置为可单击,但除此之外,一切正常)

//    authenticates user, and starts main activity if successful
@OnClick(R.id.login_button)
public void login(View view) {

//        prevents the user launching the main activity multiple times if their login is valid
    loginButton.setClickable(false);

    String email = null;
    String pass = null;


    //        prevents null entries for email
    if (usernameInput.getText().length() != 0) {
        email = usernameInput.getText().toString();
    } else {
        Toast.makeText(LoginScreen.this, "Please enter your email",
                Toast.LENGTH_SHORT).show();
        return;
    }

    //        prevents null entries for pass
    if (passwordInput.getText().length() != 0) {
        pass = passwordInput.getText().toString();
    } else {
        Toast.makeText(LoginScreen.this, "Please enter your password",
                Toast.LENGTH_SHORT).show();
        return;
    }


//        signs in with the entered email and pass
    AuthManager.firebaseAuth.signInWithEmailAndPassword(email,pass)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
//                        sign in success
                    Log.v(TAG, "signIn:onComplete:" + task.isSuccessful());

//                        if sign in is successful, pass auth info to global variables, and launch intent and start the main activity
                    if (task.isSuccessful()){

                        AuthManager.user = AuthManager.firebaseAuth.getCurrentUser();
                        AuthManager.userUID = AuthManager.user.getUid();
                        AuthManager.loggedIn = true;
//                            creates the DB manager to make initial and future DB calls
                        new DBManager();

                        Toast.makeText(LoginScreen.this, "Signed in",
                                Toast.LENGTH_SHORT).show();
                        startMainActivity();
                    } else {
//                            if sign in fails
                        Log.w(TAG, "signIn", task.getException());
                        Toast.makeText(LoginScreen.this, "Incorrect username or password",
                                Toast.LENGTH_SHORT).show();
//                            makes the button clickable again
                        loginButton.setClickable(true);

                    }

                }
            });

}

I also use a custom AuthManager class in my implementation, but the way you set up your FirebaseAuth object is perfectly fine for it to work.

我还在实现中使用自定义AuthManager类,但是设置FirebaseAuth对象的方式非常适合它工作。

#2


0  

The returned exception code, ERROR_INVALID_EMAIL, indicates that the string you are passing as the email address to signInWithEmailAndPassword() does not have the format of a valid email address.

返回的异常代码ERROR_INVALID_EMAIL表明,作为电子邮件地址向signInWithEmailAndPassword()传递的字符串不具有有效电子邮件地址的格式。

Check your logcat output to see what is logged for Log.d(TAG, emaill). If it appears to you to be a valid address, please post the value.

检查您的logcat输出,以查看日志记录。emaill d(标签)。如果您的地址是有效的,请将该值张贴出来。

Update:

更新:

The problem is these statements:

问题在于:

final String passwordl = etPasswordLogin.toString().trim();
final String emaill = etEmailLogin.toString().trim();

you want something like this:

你想要这样的东西:

final String passwordl = etPasswordLogin.getText().toString().trim();
final String emaill = etEmailLogin.getText().toString().trim();

Update 2:

更新2:

After you made the suggested corrections, your signin() method should look like this:

在进行了建议的修改之后,您的signin()方法应该如下所示:

public void signIn() {
    final String passwordl = etPasswordLogin.getText().toString().trim(); //NOTE addition of getText()
    final String emaill = etEmailLogin.getText().toString().trim(); //NOTE addition of getText()

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    Toast.makeText(LoginActivity.this, user.getEmail()+"; "+    (findViewById(R.id.etEmailLogin)).toString().trim(), Toast.LENGTH_LONG).show();
    Log.d(TAG, emaill);

    mAuth.signInWithEmailAndPassword(emaill, passwordl);
    Intent in = new Intent(LoginActivity.this, WelcomeActivity.class);
    startActivity(in);
};

The output of Log.d(TAG, emaill) should be the valid email address you entered, something like myName@domainName. If the log output is not the email address you entered, post the value that is logged and re-post your code for signin().

日志的输出。d(TAG, emaill)应该是您输入的有效电子邮件地址,比如myName@domainName。如果日志输出不是您输入的电子邮件地址,则发布已记录的值,并重新发布用于登录()的代码。

#1


1  

First, make sure that everything looks good in the Firebase console (accounts are there, etc...)

首先,确保在Firebase控制台中一切都看起来很好(帐户在那里,等等…)

Right now there doesn't seem to be any code to handle the case where the sign-in isn't successful. I just implemented a sign-in with Firebase in my app, so here's the code I use when a user presses the sign-in button. (Note: I've just noticed a bug where the button is not set to clickable again before the return statements, but other than that everything is fine)

现在似乎没有任何代码来处理登录失败的情况。我刚刚在我的应用程序中实现了一个带有Firebase的登录,这是我在用户按下登录按钮时使用的代码。(注意:我刚刚注意到一个bug,在返回语句之前,按钮没有再次被设置为可单击,但除此之外,一切正常)

//    authenticates user, and starts main activity if successful
@OnClick(R.id.login_button)
public void login(View view) {

//        prevents the user launching the main activity multiple times if their login is valid
    loginButton.setClickable(false);

    String email = null;
    String pass = null;


    //        prevents null entries for email
    if (usernameInput.getText().length() != 0) {
        email = usernameInput.getText().toString();
    } else {
        Toast.makeText(LoginScreen.this, "Please enter your email",
                Toast.LENGTH_SHORT).show();
        return;
    }

    //        prevents null entries for pass
    if (passwordInput.getText().length() != 0) {
        pass = passwordInput.getText().toString();
    } else {
        Toast.makeText(LoginScreen.this, "Please enter your password",
                Toast.LENGTH_SHORT).show();
        return;
    }


//        signs in with the entered email and pass
    AuthManager.firebaseAuth.signInWithEmailAndPassword(email,pass)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
//                        sign in success
                    Log.v(TAG, "signIn:onComplete:" + task.isSuccessful());

//                        if sign in is successful, pass auth info to global variables, and launch intent and start the main activity
                    if (task.isSuccessful()){

                        AuthManager.user = AuthManager.firebaseAuth.getCurrentUser();
                        AuthManager.userUID = AuthManager.user.getUid();
                        AuthManager.loggedIn = true;
//                            creates the DB manager to make initial and future DB calls
                        new DBManager();

                        Toast.makeText(LoginScreen.this, "Signed in",
                                Toast.LENGTH_SHORT).show();
                        startMainActivity();
                    } else {
//                            if sign in fails
                        Log.w(TAG, "signIn", task.getException());
                        Toast.makeText(LoginScreen.this, "Incorrect username or password",
                                Toast.LENGTH_SHORT).show();
//                            makes the button clickable again
                        loginButton.setClickable(true);

                    }

                }
            });

}

I also use a custom AuthManager class in my implementation, but the way you set up your FirebaseAuth object is perfectly fine for it to work.

我还在实现中使用自定义AuthManager类,但是设置FirebaseAuth对象的方式非常适合它工作。

#2


0  

The returned exception code, ERROR_INVALID_EMAIL, indicates that the string you are passing as the email address to signInWithEmailAndPassword() does not have the format of a valid email address.

返回的异常代码ERROR_INVALID_EMAIL表明,作为电子邮件地址向signInWithEmailAndPassword()传递的字符串不具有有效电子邮件地址的格式。

Check your logcat output to see what is logged for Log.d(TAG, emaill). If it appears to you to be a valid address, please post the value.

检查您的logcat输出,以查看日志记录。emaill d(标签)。如果您的地址是有效的,请将该值张贴出来。

Update:

更新:

The problem is these statements:

问题在于:

final String passwordl = etPasswordLogin.toString().trim();
final String emaill = etEmailLogin.toString().trim();

you want something like this:

你想要这样的东西:

final String passwordl = etPasswordLogin.getText().toString().trim();
final String emaill = etEmailLogin.getText().toString().trim();

Update 2:

更新2:

After you made the suggested corrections, your signin() method should look like this:

在进行了建议的修改之后,您的signin()方法应该如下所示:

public void signIn() {
    final String passwordl = etPasswordLogin.getText().toString().trim(); //NOTE addition of getText()
    final String emaill = etEmailLogin.getText().toString().trim(); //NOTE addition of getText()

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    Toast.makeText(LoginActivity.this, user.getEmail()+"; "+    (findViewById(R.id.etEmailLogin)).toString().trim(), Toast.LENGTH_LONG).show();
    Log.d(TAG, emaill);

    mAuth.signInWithEmailAndPassword(emaill, passwordl);
    Intent in = new Intent(LoginActivity.this, WelcomeActivity.class);
    startActivity(in);
};

The output of Log.d(TAG, emaill) should be the valid email address you entered, something like myName@domainName. If the log output is not the email address you entered, post the value that is logged and re-post your code for signin().

日志的输出。d(TAG, emaill)应该是您输入的有效电子邮件地址,比如myName@domainName。如果日志输出不是您输入的电子邮件地址,则发布已记录的值,并重新发布用于登录()的代码。