无法解决GoogleSignIn和GoogleSignInClient

31

在Android Studio中实现Google登录时,我无法使用GoogleSignIn(com.google.android.gms.auth.api.signin.GoogleSignIn)和GoogleSignInClient(com.google.android.gms.auth.api.signin.GoogleSignInClient),而我可以访问App中的其他类。

com.google.android.gms.auth.api.signin.GoogleSignInAccount;
com.google.android.gms.auth.api.signin.GoogleSignInOptions;
com.google.android.gms.common.SignInButton;

我 build.gradle(app) 文件的精简版本如下所示

android {

}

dependencies {

    compile 'com.google.android.gms:play-services-auth:11.4.2'
    compile('com.google.api-client:google-api-client-android:1.23.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    compile('com.google.apis:google-api-services-gmail:v1-rev72-1.23.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    implementation 'com.google.gms:google-services:3.1.2'
}

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

我的 build.gradle(包)是

buildscript {

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.gms:google-services:3.1.2'
    }
}
任何帮助都将不胜感激。

如果你遇到任何错误,请添加你的logcat。 - Upendra Shah
你的SDK Manager中是否安装了Google Repository - Yupi
@Yupi 是的,我正在使用最新版本的Google存储库。 - pcforgeek
6个回答

30

将此添加到您的应用程序级别依赖项

compile 'com.google.android.gms:play-services-auth:12.0.1'

1
为你的答案添加一些描述。 - Mathews Sunny
1
在此处找到所有依赖项列表。https://developers.google.com/android/guides/setup - Yene Mulatu
我已经获取了今天的最新版本 "16.0.0"。 - Sattar Hummatli

16

我遇到了相同的问题。

GoogleSignInGoogleSignInClient是在Google Play服务SDK版本11.6中引入的。在旧版本中使用GoogleApiClient。

因此,请尝试将依赖项中的编译'com.google.android.gms:play-services-auth:11.4.2'更改为'com.google.android.gms:play-services-auth:12.0.1'

依赖关系 { compile 'com.google.android.gms:play-services-auth:12.0.1' }


5

对我来说,我正在为我的应用程序的 build.gradle 应用插件以使用 Google Play 服务:

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

在我的项目的Build.gradle文件中,我还添加了Google服务。

buildscript {
    ext.kotlin_version = '1.1.60'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:3.1.2' // <== this guy
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

我记得我添加它们时遇到了一些编译问题。但显然我并不需要它们。

删除它们后,与gms版本相关的问题就没有了。

编辑

因此,最初删除解决了我的问题,但稍后在谷歌登录方面却给我带来了问题。将apply plugin: 'com.google.gms.google-services'添加到项目gradle底部而不是顶部确实解决了这个问题。


将 apply plugin: 'com.google.gms.google-services' 放在项目 gradle 的底部而不是顶部即可解决此问题。 - SWAppDev
我也是,我有implementation 'com.google.android.gms:play-services-auth:18.1.0',所以我认为这不是版本问题。完全删除插件行可以解决缺少GoogleSignIn引用的问题,但并不起作用。将插件行单独添加到文件末尾似乎已经解决了问题。这似乎是插件中的一个错误(可能是命名空间错误)。 - Emilie

3
build.gradle 模块脚本中,我需要添加这两个依赖项,然后点击 "立即同步",问题就解决了。
dependencies {  
    // Your own command lines
    //...

    compile 'com.google.android.gms:play-services-drive:11.8.0'
    compile 'com.google.android.gms:play-services-auth:11.8.0'
}

1

你不能使用任何更新的版本吗?例如11.6.0。 尝试更新你的Google存储库。 (工具->Android->SDK管理器->支持存储库下的SDK工具)


2
+1. GoogleSignIn / GoogleSignInClient类的最低要求版本为11.6.0(旧版本具有稍微不同的类名)。 - Isabella Chen
1
但是有一个问题,com.google.gms:google-services:3.1.2包含版本11.4.2,并且它与版本11.4.2和11.6.0发生冲突,而新版本在google-services上不可用。 - Vahe Gharibyan
@VaheGharibyan 我能够毫无问题地使用它们。您能具体说明问题是什么吗? - pcforgeek
1
如果你收到以下信息“Error:Execution failed for task ':app:processDebugGoogleServices'. > Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 11.4.2.",那么你可以通过将apply plugin: 'com.google.gms.google-services'移动到build.gradle(app)文件的末尾来解决问题。 - pcforgeek
1
@pcforgeek 我被迫使用API 11.4.2,但问题是,API 11.4.2不包含GoogleSignIn / GoogleSignInClient类。 - Vahe Gharibyan
显示剩余4条评论

0
将此行添加到 build.gradle 模块文件的 dependencies 中。
implementation 'com.google.firebase:firebase-auth:21.0.1'

例如:

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-database:20.0.2'
    implementation 'com.google.android.gms:play-services-auth:20.2.0'
    implementation 'com.google.firebase:firebase-firestore:24.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'


}

不需要添加Firebase依赖项,因为GoogleSignIn和GooglSignInClient都在Google Play服务中。 - Abhishek Dutt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接