找不到符号类GoogleSignInApi

时间:2016-12-22 02:44:38

标签: android firebase firebase-authentication google-signin

我尝试使用Google for Firebase设置身份验证并遵循此document

但是我收到了这些错误:

error: cannot find symbol class GoogleSignInApi
error: cannot find symbol variable RC_SIGN_IN

我的build.gradle(app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.myapp.sc"
        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.firebaseui:firebase-ui:1.0.1'
    compile 'com.google.firebase:firebase-auth:10.0.1'
    compile 'com.google.android.gms:play-services-auth:10.0.1'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

MainActivity.java

private FirebaseAuth mAuth;
private AuthStateListener mAuthListener;

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

    // setup google sign in
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.clientId)).requestEmail().build();
    GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, (OnConnectionFailedListener) this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();

    if (mAuth.getCurrentUser() == null) {
        signIn(mGoogleApiClient);
    }
}

private void signIn(GoogleApiClient mGoogleApiClient) {
    Intent signInIntent = new Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

我尝试过清理/重建项目并使缓存无效,但它并没有解决问题。我有什么遗失的吗?

1 个答案:

答案 0 :(得分:5)

添加以下行:

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);

而不是:

Intent signInIntent = new Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);

并添加:

private static int RC_SIGN_IN = 100;

还需要:

import com.google.android.gms.auth.api.Auth;