error: Attribute “***” has already been defined wh

2020-02-25 07:19发布

I'm using android-support-v7-appcompat as a library in my Android project. Now I want to include actionbarsherlock as another library project. When I add the second library, it gives so many errors like below

android-support-v7-appcompat\res\values\attrs.xml:476: error: Attribute "attributeName" has already been defined

By changing one attribute value and it's related code snippet is a one solution that I've tried. But when there are nearly 80 lines like above, it will get a messy. Is there any other way I can solve this issue?

5条回答
放荡不羁爱自由
2楼-- · 2020-02-25 07:44

I updated the build tools version and resynced, it worked fine.

查看更多
家丑人穷心不美
3楼-- · 2020-02-25 07:53

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

Fortunately, if you look below under Output: label, you will find the right path to the problem.

Here is an example

enter image description here

in your case it is android-support-v7-appcompat\res\values\attrs.xml:476: error: Attribute "attributeName" has already been defined

You can also build your project from command line and get the right path. attributeName Inside values\attrs.xml file on line 476 you would find a with property named "attributeName". 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.

查看更多
【Aperson】
4楼-- · 2020-02-25 07:55

Remove the appcompact support library project from Properties = > Android

查看更多
太酷不给撩
5楼-- · 2020-02-25 08:03

I solved this by removing appcompact from project, and changing in styles to

<style name="AppBaseTheme" parent="Theme.Sherlock">
查看更多
我想做一个坏孩纸
6楼-- · 2020-02-25 08:05

The correct way to solve this problem is by updating Android Support Libraries in all relevant projects and library projects. In my case I've used Android support library and also one of the library project to implement my application. When I update both libraries, the problem solved. The way of updating Android support library is;

  • Right click on the project
  • Select Android Tools from the pop up window
  • Select Add Support Library
查看更多
登录 后发表回答