我有一个Google登录按钮,我不知道如何修复它:(
错误是当传递App.xaml
该类是一个Activity并实现它时:
setContentView(R.layout.activity_login);
我不知道错误在哪里,但在它没问题之后:(,有人可以帮我吗?
public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<Cursor>, Responser<User>,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "es.iesnervion.qa"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//AÑADIDO PARA JAVA 8
jackOptions {
enabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
buildTypes {
lease {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:design:25.1.0'
//For CardViews and RecyclerViews
//Retrofit
//For animations
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:cardview-v7:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.github.lzyzsd:circleprogress:1.2.1'
compile 'org.apache.ant:ant:1.7.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'org.testng:testng:6.9.6'
testCompile 'junit:junit:4.12'
compile project(path: ':libraries:BaseGameUtils')
}
apply plugin: 'com.android.library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
}
}
dependencies {
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('appcompat_library_version')) {
ext.appcompat_library_version = '20.0.+'
}
if (!project.hasProperty('support_library_version')) {
ext.support_library_version = '20.0.+'
}
if (!project.hasProperty('gms_library_version')) {
ext.gms_library_version = '8.4.0'
}
compile "com.android.support:appcompat-v7:${appcompat_library_version}"
compile "com.android.support:support-v4:${support_library_version}"
compile "com.google.android.gms:play-services-games:${gms_library_version}"
compile "com.google.android.gms:play-services-auth:${gms_library_version}"
compile "com.google.android.gms:play-services-plus:${gms_library_version}"
}
android {
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('android_compile_version')) {
ext.android_compile_version = 23
}
if (!project.hasProperty('android_min_version')) {
ext.android_min_version = 15
}
if (!project.hasProperty('android_version')) {
ext.build_tools_version = "23.0.2"
}
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!project.hasProperty('android_min_sdk_version')) {
ext.android_min_sdk_version = 9
}
compileSdkVersion android_compile_version
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion android_min_version
targetSdkVersion android_compile_version
}
}
这是追踪:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/loginId"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="center_horizontal"
android:noHistory="true"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/colorBackground"
tools:context="es.iesnervion.qa.ui.View.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<LinearLayout
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/logo"
android:maxHeight="200dp"
android:src="@drawable/logo_big"
android:adjustViewBounds="true"
android:layout_gravity="center"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/prueba">
<AutoCompleteTextView
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="@+id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:minLines="1" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:layout_marginTop="16dp"
android:text="@string/action_sign_in"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Ó"
android:textColor="@color/colorPrimary"
android:textAlignment="center" />
<!-- sign-in button -->
<com.google.android.gms.common.SignInButton
android:id="@+id/google_sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
答案 0 :(得分:2)
确保Google的Maven存储库包含在项目的顶级build.gradle文件中:
allprojects {
repositories {
google()
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
}
}
然后在您的应用级build.gradle文件中声明Google Play服务作为依赖项:
apply plugin: 'com.android.application'
...
dependencies {
compile 'com.google.android.gms:play-services-auth:11.8.0'
}
** PS:**避免声明多个版本的播放服务依赖项,这可能会导致不匹配,从而产生您所面临的错误。
答案 1 :(得分:0)
只需在build.gradle(app)中包含compile 'com.google.android.gms:play-services:11.0.4'
依赖项。
答案 2 :(得分:0)
您必须为Google登录添加实现“ com.google.android.gms:play-services-auth:17.0.0”。因为Google登录按钮用于Google登录。因此,您应该在gradle文件(app)中包含它的依赖项