error: Attribute “***” has already been defined when using two library projects in Android

柔情痞子 提交于 2019-11-29 06:09:21

问题


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?


回答1:


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



回答2:


Remove the appcompact support library project from Properties = > Android




回答3:


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

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.




回答4:


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

<style name="AppBaseTheme" parent="Theme.Sherlock">



回答5:


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



来源:https://stackoverflow.com/questions/19995970/error-attribute-has-already-been-defined-when-using-two-library-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!