Lollipop AppCompat-v7 21 - Attribute "theme" has already been defined

AndroidAndroid 5.0-Lollipop

Android Problem Overview


I wanted to upgrade my project to support Android Lollipop and API 21, so I changed AppCompat version at the dependencies to 21.0.0, and my target SDK to 21.

But now, When I'm trying to sync project with gradle files, it gives me 102 errors that weren't there before:

1 error of "Attribute 'theme' has already defined" - given by my colors.XML file,

and another 101 errors of "no resources found that matches the given name..." - most of them are Material ones - given by "build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/res/values-v11/values.XML".

Already updated all SDK tools in Android SDK software, Using Android Studio 0.8.9 Beta.

Can anyone help? Thanks.

Android Solutions


Solution 1 - Android

I had the first issue as well. It can be fixed by updating the Google Play Services dependency to 6.1.+.

In Gradle (which I hope you are using) this is: compile 'com.google.android.gms:play-services:6.1.+'

As for the second issue - as people have said in the comments, you should make sure ALL the components in your SDK installation are up to date.

Solution 2 - Android

I had the same problem but upgrade to latest versions doesn't helped.

But error message Attribute “theme” has already been defined changed to Attribute “layout” has already been defined

In Google Play Services changes I've found this

  <declare-styleable name="WalletFragmentOptions">
         <!-- Theme to be used for the Wallet selector -->
-        <attr name="theme" format="enum">
+        <attr name="appTheme" format="enum">

And this is the key.

If you have in your attr.xml attributes theme or layout or maybe something else - rename it. It seems merger can't deal with it.

Solution 3 - Android

Gradle in the Android studio suggests the latest version of com.google.android.gms:play-services. After updating that to the latest version, the problem got solved.

compile 'com.google.android.gms:play-services:8.3.0'

Solution 4 - Android

Sometimes the library you are using has this attribute. I was using Sliding up panel library and I got following error during build time. I had following items in my dependency libraries:

dependencies {
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.sothree.slidinguppanel:library:+'
    // ...
}

I fixed my problem by removing sliding library :(

Solution 5 - Android

After adding a new activity in my project, it seems like Android Studio automatically updated my dependencies, after what that error started to appear.

I changed the following dependencies to the latest compatibility libraries:

compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'

to the ones I had in my gradle.build before Studio edited it without asking me:

compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'

Then let Studio make a Sync, and your build should work.

Solution 6 - Android

For Eclipse-users:

Because if you followed the recommandation for installing gps, you only have a copy of it in your workspace, which won't get updated.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3184899View Question on Stackoverflow
Solution 1 - Androidtilal6991View Answer on Stackoverflow
Solution 2 - AndroidFedor KazakovView Answer on Stackoverflow
Solution 3 - AndroidVikasView Answer on Stackoverflow
Solution 4 - AndroidHesamView Answer on Stackoverflow
Solution 5 - AndroidBenjamin PietteView Answer on Stackoverflow
Solution 6 - AndroidMurmelView Answer on Stackoverflow