我有很多红线用于Firebase身份验证

时间:2016-12-26 09:52:30

标签: android firebase firebase-authentication

firebase

我在我的应用项目中添加了Firebase,并且我正在尝试向我的应用添加身份验证,但似乎它没有运行良好。

我有很多红线,我不明白发生了什么类型的问题。你能帮我解决这个问题吗? 谢谢。

4 个答案:

答案 0 :(得分:0)

这是解决方案,在build.gradle中添加它(模块应用程序)

dependencies {
 compile 'com.google.firebase:firebase-auth:10.0.1'
 .....
}

问题解决了。

答案 1 :(得分:0)

这是我的代码

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.example.kse.jackieapp"
    minSdkVersion 23
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner    "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),  'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.google.firebase:firebase-core:10.0.1'
testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'

答案 2 :(得分:0)

我认为您尚未在项目中添加BaseActivity。 请按照以下步骤操作

  1. 添加BaseActivity
  2. 将BaseActivity替换为AppCompactActivity
  3. 在build.gradle(App Module)中添加它 - 编译'com.google.firebase:firebase-auth:10.0.1'
  4. 以下是完整演示 - 尝试将您的项目与此Firebase demo

    进行比较

    如果有问题,请告诉我。

答案 3 :(得分:0)

请查看所有星标。

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        **GoogleSignInResult** result = **Auth**.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.**isSuccess**()) {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.**getSignInAccount**();
            firebaseAuthWithGoogle(account);
        } else {
            // Google Sign In failed, update UI appropriately
            // [START_EXCLUDE]
            updateUI(null);
            // [END_EXCLUDE]
        }
    }
}

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

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    showProgressDialog();
    // [END_EXCLUDE]

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(**GoogleSignInActivity**.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                    // [START_EXCLUDE]
                    hideProgressDialog();
                    // [END_EXCLUDE]
                }
            });
}

private void updateUI(FirebaseUser user) {
    hideProgressDialog();
    if (user != null) {
        mStatusTextView.setText(getString(R.string.**google_status_fmt**, user.getEmail()));
        mDetailTextView.setText(getString(R.string.**firebase_status_fmt**, user.getUid()));

        findViewById(R.id.sign_in_button).setVisibility(View.GONE);
        findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
    } else {
        mStatusTextView.setText(R.string.**signed_out**);
        mDetailTextView.setText(null);

        findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
        findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
    }
}