首页 文章

无法解析GoogleSignIn和GoogleSignInClient

提问于
浏览
21

在Android中实施Google登录时,我无法使用GoogleSignIn(com.google.android.gms.auth.api.signin.GoogleSignIn)和GoogleSignInClient(com.google.android.gms.auth.api.signin.GoogleSignInClient) Studio虽然我可以访问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'
    }
}

任何帮助,将不胜感激

5 回答

  • 19

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

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

    我遇到了同样的问题

    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'

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

  • 2

    对我来说,我在我的 app's build.gradle 中为Google Play服务应用了一个插件:

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

    以及在我的 Project's Build.gradle 我有谷歌服务 .

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

    我记得我添加了一些编译问题 . 但显然我不需要它们 .

    By removing them I found there were no more issues with the gms versions.

    EDIT

    因此删除最初解决了我的问题,但稍后通过谷歌登录向我提出了问题 . 将 apply plugin: 'com.google.gms.google-services' 添加到我的项目底部gradle而不是顶部确实解决了它 .

  • 5

    build.gradle Module脚本中,我不得不添加这两个依赖项,然后"Sync Now"并为我解决了问题 .

    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 Manager->支持存储库下的SDK工具)

相关问题