Google SignInButton is not being rendered on Android Studio's preview pane. An error is being shown and I'm not figuring out what is happening. I just want to implement a Google Login, but this is preventing me from being able to.
My gradle file:
apply plugin: 'com.android.application'
apply plugin: 'android'
android {
compileSdkVersion 21
buildToolsVersion "21.0.0"
defaultConfig {
applicationId "com.rleote.googlelogin"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:6.1.+'
}
And this is how I'm referencing the SignInButton in my activity:
<com.google.android.gms.common.SignInButton
android:id="@+id/btn_sign_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"/>
The error in the preview pane is this: Exception Details android.content.res.Resources$NotFoundException: Could not find drawable resource matching value 0x7FFF001C (resolved name: common_signin_btn_text_dark) in current configuration. at android.content.res.BridgeResources.throwException(BridgeResources.java:699) at android.content.res.BridgeResources.getColorStateList(BridgeResources.java:210) at com.google.android.gms.common.internal.q.c at com.google.android.gms.common.internal.q.a at com.google.android.gms.common.SignInButton.a at ... Failed to configure parser for C:\Users\Rodrigo\Source\Repos\googlelogin\GoogleLogin\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.1.71\res\drawable\common_signin_btn_text_dark.xml org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: tag requires a 'android:color' attribute ...
Looks like it is not being able to parse common_signin_btn_text_dark.xml because of a missing color atribute. But I didn't define this drawable. Looks like this is a component from google services, why would this be missing?
Thanks for the help!
Ok, I've figured out a workaround for this. Basically the error is stating that the drawing file doesn't have a required android:color attribute. However, I didn't want to add a custom color. Then I get the path to the drawing file res\drawable\common_signin_btn_text_dark.xml and saw that it was like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/common_signin_btn_text_pressed_dark" />
<item
android:state_enabled="false"
android:state_focused="true"
android:drawable="@drawable/common_signin_btn_text_disabled_focus_dark" />
<item
android:state_focused="true"
android:drawable="@drawable/common_signin_btn_text_focus_dark" />
<item
android:state_enabled="false"
android:drawable="@drawable/common_signin_btn_text_disabled_dark" />
<item
android:drawable="@drawable/common_signin_btn_text_normal_dark" />
</selector>
You can notice there is no color attribute. Then I saw that the path res\color had a few files, and one of them is a common_signin_btn_text_dark.xml, containing this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:color="@color/common_signin_btn_dark_text_pressed" />
<item
android:state_enabled="false"
android:state_focused="true"
android:color="@color/common_signin_btn_dark_text_disabled" />
<item
android:state_focused="true"
android:color="@color/common_signin_btn_dark_text_focused" />
<item
android:state_enabled="false"
android:color="@color/common_signin_btn_dark_text_disabled" />
<item
android:color="@color/common_signin_btn_dark_text_default" />
</selector>
The difference is the color tag and no drawable. However, drawable is also mandatory. What I did was to "merge" both into:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/common_signin_btn_text_pressed_dark"
android:color="@color/common_signin_btn_dark_text_pressed"/>
<item
android:state_enabled="false"
android:state_focused="true"
android:drawable="@drawable/common_signin_btn_text_disabled_focus_dark"
android:color="@color/common_signin_btn_dark_text_disabled"/>
<item
android:state_focused="true"
android:drawable="@drawable/common_signin_btn_text_focus_dark"
android:color="@color/common_signin_btn_dark_text_focused" />
<item
android:state_enabled="false"
android:drawable="@drawable/common_signin_btn_text_disabled_dark"
android:color="@color/common_signin_btn_dark_text_disabled" />
<item
android:drawable="@drawable/common_signin_btn_text_normal_dark"
android:color="@color/common_signin_btn_dark_text_default" />
</selector>
I still would like an explanation if I'm doing it right or this should work automatically. This looks pretty much like a workaround instead of a straightforward solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With