编译报错,Error:(2) Attribute “**” has already been defined ,例:
/Users/zhangdan/Documents/dev/HaiTao_Android/app/src/main/res/values/colors.xml
Error:(2) Attribute "icon" has already been defined
Error:(2) Attribute "title" has already been defined
编译系统告诉我们,属性”icon”被定义过;属性”title”被定义过,并告诉我们是在“../colors.xml” 文件中
解决办法
找到它 “**”(例子里是 “icon” ,”title”)
- 通常建议在系统报错信息给出的文件里面,用find搜索一下。(通常找不到,我这次就没找到,编译系统也会忽悠人哦)
- 直接找attrs.xml文件看是非有报错属性
- App里资源文件很多,可以每个文件都找一篇,建议用全局搜索字符
修改它
既然是已经被定义过了,重复了,那就改个别的名吧,并相应修改所有使用它的地方
更改前:
<declare-styleable name="PurchaseNoteView">
<attr name="icon" format="reference"/>
</declare-styleable>
更改后:
<declare-styleable name="PurchaseNoteView">
<attr name="purchaseIcon" format="reference"/>
</declare-styleable>
名称通常加个相关前缀就不大会重复了。改好名称后,记得把相关用到的地方都一并改过来,再编译就OK了