2016-09-11 7 views
0

私のLoginActivityには、ユーザがメールとパスワードを入力するためのEditTextが含まれています。すべてのコードは私にとっては問題ないようです。無効なメールでFirebaseユーザのログインに失敗しましたcom.google.firebase.authが見つかりません

ただし、ログインボタンをクリックした後、ユーザーはログインしません。これは、電子メールのEditTextには、以下のように含まれている、電子メールが無効であることが判明:

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

間違っているものを見つけるために私を助けてください。メッセージ次

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); 
    }; 
} 

そして、私の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> 

です:

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. 

どちらも2トーストのように同じ内容を示しています

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

また、私を聞かせてください理由を知っているこれは表示されます:

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

あなたの優しさに感謝します。

UPDATES:、メッセージを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. 
+0

補完リスナーを 'signInWithEmailAndPassword()'に追加して、サインインが失敗した理由を確認してください。 [このサンプルコード](https://github.com/firebase/quickstart-android/blob/master/auth/app/src/main/java/com/google/firebase/quickstart/auth/EmailPasswordActivity.java#L150)を使用します。 -L172)をクイックスタートプロジェクトから削除します。 –

+0

はい、完了リスナーをsignInWithEmailAndPassword()に追加しました。結果は同じでした。そして、問題はonCreateメソッドが起動した直後に発生しているようです.... –

+0

このステートメントでログに記録されたエラー例外は何ですか: 'Log.w(TAG、" signInWithEmail:failed "、task.getException())'? –

答えて

1

まず、すべてがFirebaseコンソールに良く見えることを確認してください(アカウントがある、など...)

今、サインインが成功しなかったケースを処理するコードはありません。私は自分のアプリでFirebaseのサインインを実装したばかりなので、ユーザーがサインインボタンを押したときに使用するコードはここにあります。 (注:私はちょうどボタンをもう一度return文の前にクリック可能に設定されていないバグを気づいたが、それはすべて以外は結構です)

// 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); 

        } 

       } 
      }); 

} 

は、私も私の実装では、カスタム認証マネージャークラスを使用し、 FirebaseAuthオブジェクトを設定する方法は、それが動作するためにはまったく問題ありません。

+0

ユーザがFirebaseコンソールに正しく表示されます。前にOnCompleteListenerが追加されましたが、結果は同じでした。 –

0

返された例外コードERROR_INVALID_EMAILは、電子メールアドレスとしてsignInWithEmailAndPassword()に渡す文字列が有効な電子メールアドレスの形式を持たないことを示します。

logcatの出力を確認して、ログに記録されている内容を確認してください。Log.d(TAG, emaill)有効な住所と思われる場合は、値を掲示してください。

更新:

問題は、これらのステートメントである:

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

あなたはこのような何かしたい:

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

をアップデート2:

AFTE Rあなたが提案の修正をした、あなたの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); 
}; 

Log.d(TAG, emaill)の出力が入力した有効なメールアドレスである必要があり、[email protected]のようなものを。ログ出力が入力した電子メールアドレスでない場合は、記録された値を掲示し、signin()のコードを再投稿してください。

+0

Log.d(TAG、email)には、android.support.v7.widget.AppCompatEditText {b014ce3 VFED..CL。 .F ...... 56,646-1384,804#7f0d0096 app:id/etEmailLogin} –

+0

私は前にgetText()を試しました。結果は同じでした。 –

+0

あなたはちょうどgetText()。toString()を試してみましたか?私は最初にこれのフォーマットに関するいくつかの問題を抱えていましたが、これが動作することがわかりました... – JCLaHoot

関連する問題