Android应用上的Firebase用户登录呼叫登录失败

时间:2018-01-05 22:28:49

标签: java android firebase firebase-authentication

首先,我已经检查过了。我没有找到任何答案..我正在使用Firebase身份验证制作Android应用。我正在关注添加身份验证的教程。我知道我用正确的密码创建了用户。当我输入密码时,登录始终失败。

图片: user password in firebase

failing to log in. EVEN WITH THE RIGHT DETAILS!

图片链接: one image another image

代码:

    package org.reliefdev.relief;

    import android.os.Bundle;
    import android.support.annotation.NonNull;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.Toast;

    import com.google.android.gms.tasks.OnCompleteListener;
    import com.google.android.gms.tasks.Task;
    import com.google.firebase.auth.AuthResult;
    import com.google.firebase.auth.FirebaseAuth;
    import com.google.firebase.auth.FirebaseUser;
    import com.google.firebase.database.DataSnapshot;
    import com.google.firebase.database.DatabaseError;
    import com.google.firebase.database.DatabaseReference;
    import com.google.firebase.database.FirebaseDatabase;
    import com.google.firebase.database.ValueEventListener;

    import static org.reliefdev.relief.PublicStuff.passwordString;
    import static org.reliefdev.relief.PublicStuff.usernameString;

    public class LoginActivity extends AppCompatActivity {
    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        mAuth = FirebaseAuth.getInstance();

        TextView loginButton = findViewById(R.id.goLoginBtnLabel);
        final EditText loginUsername = findViewById(R.id.loginUsername);
        final EditText loginPassword = findViewById(R.id.loginPassword);



        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Set the public variables to something.
                usernameString = loginUsername.getText().toString();
                passwordString = loginPassword.getText().toString();

                //All logic for the text boxes/EditTexts.
                if (!usernameString.equals("") && !passwordString.equals("")) {

                    //To actually log the user in!
                    mAuth.signInWithEmailAndPassword(usernameString, passwordString)
                            .addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
                                @Override
                                public void onComplete(@NonNull Task<AuthResult> task) {
                                    if (task.isSuccessful()) {
                                        //Login has completed properly (the username and password are correct)
                                        Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_toast_welcome_login) + " " + loginUsername.getText().toString() + getResources().getString(R.string.excla), Toast.LENGTH_SHORT).show();
                                    } else {
                                        Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_toast_please_check_sign_in_info_details), Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                }  /*if (usernameString.equals("")) {
                    Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_toast_please_enter_a_username), Toast.LENGTH_SHORT).show();
                }  if (!usernameString.equals("") && passwordString.equals("")) {
                    Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_toast_username_but_need_pass), Toast.LENGTH_SHORT).show();
                }  if (usernameString.equals("") && passwordString.equals("")) {
                    Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_toast_need_both_pass_and_username), Toast.LENGTH_SHORT).show();
                }*/
            }
        });

        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();

                if (user != null) {
                    //The user is signed in
                    // startActivity(new Intent(LoginActivity.this, HomeActivity.class));
                } else {
                    //The user is signed out

                }
            }
        };


    }

    public void onBackPressed() {
        Toast.makeText(LoginActivity.this, getResources().getString(R.string.login_toast_on_back_pressed), Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onStart() {
        super.onStart();

        mAuth.addAuthStateListener(mAuthListener);
    }

    @Override
    protected void onStop() {
        super.onStop();

        if (mAuth != null) {
            mAuth.removeAuthStateListener(mAuthListener);
        }
    }
}

logcat

01-05 22:57:15.445 8070-8070/? I/zygote: Not late-enabling -Xcheck:jni (already on)
01-05 22:57:15.457 8070-8070/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
01-05 22:57:15.860 8070-8070/org.reliefdev.relief W/zygote: Unsupported class loader
01-05 22:57:15.861 8070-8070/org.reliefdev.relief W/zygote: Skipping duplicate class check due to unsupported classloader
01-05 22:57:15.871 8070-8070/org.reliefdev.relief W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
01-05 22:57:15.884 8070-8070/org.reliefdev.relief W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
01-05 22:57:15.909 8070-8070/org.reliefdev.relief I/BiChannelGoogleApi: [FirebaseAuth: ] No Fallback module; NOT setting up for lazy initialization
01-05 22:57:15.930 8070-8070/org.reliefdev.relief D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
01-05 22:57:15.942 8070-8087/org.reliefdev.relief W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
01-05 22:57:15.949 8070-8087/org.reliefdev.relief I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
01-05 22:57:15.949 8070-8087/org.reliefdev.relief I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
01-05 22:57:15.988 8070-8070/org.reliefdev.relief V/FA: Cancelling job. JobID: 1388094817
01-05 22:57:16.008 8070-8070/org.reliefdev.relief V/FA: Registered activity lifecycle callback
01-05 22:57:16.011 8070-8070/org.reliefdev.relief I/FirebaseInitProvider: FirebaseApp initialization successful
01-05 22:57:16.013 8070-8070/org.reliefdev.relief I/InstantRun: starting instant run server: is main process
01-05 22:57:16.039 8070-8090/org.reliefdev.relief V/FA: Collection enabled
01-05 22:57:16.039 8070-8090/org.reliefdev.relief V/FA: App package, google app id: org.reliefdev.relief, 1:982107279652:android:dc8fd1d87ede636d
01-05 22:57:16.040 8070-8090/org.reliefdev.relief I/FA: App measurement is starting up, version: 11910
01-05 22:57:16.040 8070-8090/org.reliefdev.relief I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
01-05 22:57:16.040 8070-8090/org.reliefdev.relief I/FA: To enable faster debug mode event logging run:
                                                          adb shell setprop debug.firebase.analytics.app org.reliefdev.relief
01-05 22:57:16.040 8070-8090/org.reliefdev.relief D/FA: Debug-level message logging enabled
01-05 22:57:16.087 8070-8090/org.reliefdev.relief V/FA: Connecting to remote service
01-05 22:57:16.103 8070-8090/org.reliefdev.relief V/FA: Connection attempt already in progress
01-05 22:57:16.140 8070-8070/org.reliefdev.relief V/FA: onActivityCreated
01-05 22:57:16.368 8070-8090/org.reliefdev.relief V/FA: Connection attempt already in progress
01-05 22:57:16.375 8070-8090/org.reliefdev.relief V/FA: Activity resumed, time: 3510863
01-05 22:57:16.388 8070-8090/org.reliefdev.relief I/FA: Tag Manager is not found and thus will not be used
01-05 22:57:16.392 8070-8090/org.reliefdev.relief D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=WelcomeActivity, firebase_screen_id(_si)=850490102224929754}]
01-05 22:57:16.412 8070-8095/org.reliefdev.relief D/OpenGLRenderer: HWUI GL Pipeline
01-05 22:57:16.450 8070-8090/org.reliefdev.relief V/FA: Connection attempt already in progress
01-05 22:57:16.465 8070-8090/org.reliefdev.relief V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 83
01-05 22:57:16.465 8070-8090/org.reliefdev.relief V/FA: Connection attempt already in progress
01-05 22:57:16.465 8070-8090/org.reliefdev.relief V/FA: Activity paused, time: 3510921
01-05 22:57:16.492 8070-8070/org.reliefdev.relief V/FA: onActivityCreated
01-05 22:57:16.583 8070-8090/org.reliefdev.relief V/FA: Connection attempt already in progress
01-05 22:57:16.584 8070-8090/org.reliefdev.relief V/FA: Activity resumed, time: 3511072
01-05 22:57:16.597 8070-8090/org.reliefdev.relief D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=WelcomeActivity, firebase_previous_id(_pi)=850490102224929754, firebase_screen_class(_sc)=LoginActivity, firebase_screen_id(_si)=850490102224929755}]
01-05 22:57:16.670 8070-8075/org.reliefdev.relief I/zygote: Do partial code cache collection, code=16KB, data=21KB
01-05 22:57:16.671 8070-8090/org.reliefdev.relief V/FA: Connection attempt already in progress
01-05 22:57:16.671 8070-8075/org.reliefdev.relief I/zygote: After code cache collection, code=16KB, data=22KB
01-05 22:57:16.671 8070-8075/org.reliefdev.relief I/zygote: Increasing code cache capacity to 128KB
01-05 22:57:16.676 8070-8075/org.reliefdev.relief I/zygote: Do partial code cache collection, code=16KB, data=40KB
01-05 22:57:16.677 8070-8075/org.reliefdev.relief I/zygote: After code cache collection, code=16KB, data=40KB
01-05 22:57:16.677 8070-8075/org.reliefdev.relief I/zygote: Increasing code cache capacity to 256KB
01-05 22:57:16.677 8070-8075/org.reliefdev.relief I/zygote: JIT allocated 71KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
01-05 22:57:16.677 8070-8075/org.reliefdev.relief I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)

                                                            [ 01-05 22:57:16.692  8070: 8095 D/         ]
                                                            HostConnection::get() New Host Connection established 0x981fa380, tid 8095
01-05 22:57:16.704 8070-8095/org.reliefdev.relief I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
01-05 22:57:16.705 8070-8095/org.reliefdev.relief I/OpenGLRenderer: Initialized EGL, version 1.4
01-05 22:57:16.705 8070-8095/org.reliefdev.relief D/OpenGLRenderer: Swap behavior 1
01-05 22:57:16.705 8070-8095/org.reliefdev.relief W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
01-05 22:57:16.705 8070-8095/org.reliefdev.relief D/OpenGLRenderer: Swap behavior 0
01-05 22:57:16.708 8070-8095/org.reliefdev.relief D/EGL_emulation: eglCreateContext: 0xa8004720: maj 2 min 0 rcv 2
01-05 22:57:16.715 8070-8095/org.reliefdev.relief D/EGL_emulation: eglMakeCurrent: 0xa8004720: ver 2 0 (tinfo 0xa8003640)
01-05 22:57:16.758 8070-8090/org.reliefdev.relief D/FA: Connected to remote service
01-05 22:57:16.758 8070-8090/org.reliefdev.relief V/FA: Processing queued up service tasks: 7
01-05 22:57:16.781 8070-8095/org.reliefdev.relief D/EGL_emulation: eglMakeCurrent: 0xa8004720: ver 2 0 (tinfo 0xa8003640)
01-05 22:57:17.008 8070-8070/org.reliefdev.relief V/View: dispatchProvideAutofillStructure(): not laid out, ignoring 0 children of 1073741834
01-05 22:57:17.014 8070-8070/org.reliefdev.relief I/AssistStructure: Flattened final assist data: 3392 bytes, containing 1 windows, 12 views
01-05 22:57:22.075 8070-8090/org.reliefdev.relief V/FA: Inactivity, disconnecting from the service
01-05 22:57:29.658 8070-8075/org.reliefdev.relief I/zygote: Do full code cache collection, code=125KB, data=80KB
01-05 22:57:29.659 8070-8075/org.reliefdev.relief I/zygote: After code cache collection, code=122KB, data=52KB
01-05 22:57:32.925 8070-8070/org.reliefdev.relief V/View: dispatchProvideAutofillStructure(): not laid out, ignoring 0 children of 1073741834
01-05 22:57:32.937 8070-8070/org.reliefdev.relief I/AssistStructure: Flattened final assist data: 3456 bytes, containing 1 windows, 12 views
01-05 22:57:34.930 8070-8075/org.reliefdev.relief I/zygote: Do partial code cache collection, code=124KB, data=64KB
01-05 22:57:34.931 8070-8075/org.reliefdev.relief I/zygote: After code cache collection, code=124KB, data=64KB
01-05 22:57:34.932 8070-8075/org.reliefdev.relief I/zygote: Increasing code cache capacity to 512KB
01-05 22:57:41.230 8070-8070/org.reliefdev.relief W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms
01-05 22:57:42.079 8070-8095/org.reliefdev.relief D/EGL_emulation: eglMakeCurrent: 0xa8004720: ver 2 0 (tinfo 0xa8003640)
01-05 22:57:42.296 8070-8095/org.reliefdev.relief D/EGL_emulation: eglMakeCurrent: 0xa8004720: ver 2 0 (tinfo 0xa8003640)

1 个答案:

答案 0 :(得分:1)

以及文献; 如果您尚未将应用与Firebase项目相关联,请从Firebase console执行此操作。

启用电子邮件/密码登录: 在Firebase console中,打开“身份验证”部分。 在“登录方法”选项卡上,启用“电子邮件/密码登录”方法,然后单击“保存”。

如果你已经完成了, 启用&#34; Identity Toolkit API&#34;在Google云端控制台中

最后一个提议是在您的Android应用中使用Identity Toolkit。虽然,

  

最新版Google Identity Toolkit已发布为   Firebase身份验证。它包括升级的客户端SDK,开源   UI库,会话管理和集成电子邮件发送服务   忘记了密码流。

     

新项目应使用Firebase身份验证。迁移   从Identity Toolkit到Firebase身份验证的现有项目,请参阅   migration guide