Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

appcompat-v7:21.0.0 not working with google play service 6.1+

I'm updating my app to bring material theme support(my app uses Google Play Services)

When I sync my project, this showed up:

...\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.1.11\res\values\wallet_colors.xml

Error:Attribute "showText" has already been defined

My gradle dependencies:

compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.google.android.gms:play-services:6.1.11'
// the latest version of play-services is 6.1.11

If I exclude appcompat-v7 then the project compiles without errors.

Did I got too excited about lollipop and didn't read the docs properly? How can I fix this?

Part of the build script:

compileSdkVersion 21
buildToolsVersion '21.0.1'
dexOptions {
    preDexLibraries true
    //incremental true
}
defaultConfig {
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 11
    versionName '1.0'
    renderscriptTargetApi 21
    renderscriptSupportMode true
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

Local Google repository looks like this: enter image description here

like image 300
tom91136 Avatar asked Oct 21 '14 06:10

tom91136


3 Answers

@igavran answer points to the right direction but I wanted to give more comprehensive answer, so there it is:

Gradle Resource Merger merges all resource folders from all dependencies and place into single folder. In case there are duplicates build process will fail.

For some weird reason, Android Studio points to the wallet_colors.xml of the Google Play Service library in the Messages window. Google Play Service has nothing to do with this problem. Fortunately, if you look below under Output: label, you will find the right path to the problem e.g.

Screenshoot from Android Studio

You can also build your project from command line and get the right path.

Inside values.xml file in line 172(in your case different line) you would find a <declare-styleable> with property named "color"("showText" in your case). Most probably it is your own styleable that you have to change to get rid of the duplicate.

So now, when you know the reason, you can locate that property in your project module and replace it with different name. I guess it will be located inside /values/attrs.xml file.

like image 187
Damian Petla Avatar answered Nov 17 '22 03:11

Damian Petla


I spent last two hours on the same issue and in my case the problem was that I had defined my own attribute "showText" (in res/values/attrs.xml) which was in collision with attribute defined in <declare-styleable name="SwitchCompat">.

This problem does not exist when using appcompat-v7:20 but with appcompat-v7:21 build fails.

like image 25
igavran Avatar answered Nov 17 '22 02:11

igavran


Don't use the whole play services like this following example 1

example 1: compile 'com.google.android.gms:play-services:7.5.0'

Use those services that you want to use in you application. For example if you want to use Google+ service than use as following example 2

example 2: compile 'com.google.android.gms:play-services-plus:7.5.0'

for more services visit: Setting Up Google Play Services

like image 1
Munish Kapoor Avatar answered Nov 17 '22 02:11

Munish Kapoor