我是android studio的新手。我在eclipse中完成了google的集成,但在工作室里遇到了问题。我正在从这个网站一步一步地跟随:qazxsw poi
但我有一个问题。我收到一个错误,无法解析我需要API的符号'Auth',也无法解析'SignInButton',请参阅代码:
https://developers.google.com/identity/sign-in/android/sign-in?configured=true
这是我的项目gradle:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
public class MainActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {
GoogleSignInOptions gso;
GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
这是我的应用程序gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.google.gms:google-services:1.5.0-beta2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
请帮我。
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.creaa.admin.googlesignin"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
apply plugin: 'com.google.gms.google-services'
}
放在apply plugin: 'com.google.gms.google-services'
下面。apply plugin: 'com.android.application'
区块内添加compile 'com.google.android.gms:play-services-auth:8.3.0'
。这将为项目添加相关的依赖项。使用最新版本(2.2.2),为解决此问题,我必须做的是将下面的行添加为我的dependencies
文件中的依赖项
app/build.gradle
希望能帮助到你。
将Firebase身份验证和Google登录的依赖项添加到您的应用级build.gradle文件中:
compile 'com.google.android.gms:play-services-auth:9.8.0'
我有同样的问题,在你的应用程序级gradle文件中添加编译'com.google.android.gms:play-services-auth:10.0.1(你项目的最新版本)。
尝试将apply plugin:'com.google.gms.google-services'从依赖项移动到gradle文件的顶部,就在apply plugin:'com.android.application'下。
编辑:
确保您已从SDK Manager安装了Extras / Google Repository,并将编译'com.google.android.gms:play-services:8.3.0'添加到您的依赖范围中。
我遇到了这个问题。我通过在app level gradle文件中添加此行来解决它:
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
(在文件的底部(重要))
并在app level dependencies部分中显示此行,
apply plugin: 'com.google.gms.google-services'
(最新版本,当我写这个答案的时候)
这是compile 'com.google.android.gms:play-services-auth:11.0.4'
。
在app gradle中的依赖关系块中添加此项
link to the documentation