Firebase身份验证错误:找不到com.google.firebase.auth的本地模块描述符类

时间:2016-11-07 22:32:42

标签: android firebase google-plus firebase-authentication

我正在开发一个使用来自Google+的Firebase使用auth的应用,但我收到以下错误:

11-07 19:20:16.827 29393-29393/br.com.santor.fidelity W/LoginActivity: signInWithCredential
   com.google.firebase.FirebaseException: An internal error has occurred. [ Bad Request ]
       at com.google.android.gms.internal.zzahe.zzfc(Unknown Source)
       at com.google.android.gms.internal.zzahb$zzg.zza(Unknown Source)
       at com.google.android.gms.internal.zzahm.zzfd(Unknown Source)
       at com.google.android.gms.internal.zzahm$zza.onFailure(Unknown Source)
       at com.google.android.gms.internal.zzahh$zza.onTransact(Unknown Source)
       at android.os.Binder.execTransact(Binder.java:453)
11-07 19:20:20.709 29393-2794/br.com.santor.fidelity V/FA: Inactivity, disconnecting from the service
11-07 19:20:25.806 29393-29436/br.com.santor.fidelity W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

我的LoginActivity是这样的:

public class LoginActivity extends AppCompatActivity implements
        GoogleApiClient.OnConnectionFailedListener {

    private static final String TAG = LoginActivity.class.getSimpleName();
    private GoogleApiClient mGoogleApiClient;
    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;

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

        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();

        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, this)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();

        mAuth = FirebaseAuth.getInstance();

        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                if (user != null) {
                    Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
                } else {
                    // User is signed out
                    Log.d(TAG, "onAuthStateChanged:signed_out");
                }
            }
        };
    }

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

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

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()) {
                GoogleSignInAccount account = result.getSignInAccount();
                firebaseAuthWithGoogle(account);
            }
        }
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        Log.e("Login", "Erro de conexão: " + connectionResult.getErrorMessage());
    }

    public void onSignUp(View view) {
        Auth.GoogleSignInApi.signOut(mGoogleApiClient);
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }

    private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
        AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (!task.isSuccessful()) {
                            Log.w(TAG, "signInWithCredential", task.getException());
                            Toast.makeText(LoginActivity.this, "Authentication failed.",
                                    Toast.LENGTH_SHORT).show();
                        }else{
                            Toast.makeText(LoginActivity.this, "Authentication success.",
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }
}

我遵循firebase auth教程(https://firebase.google.com/docs/auth/android/google-signin)并且它正常工作,但是在尝试再次运行并失败之后。拜托,有人可以帮助我吗?

0 个答案:

没有答案