Android构建时报错: java.io.IOException: Could not parse XML from android/accounts/annotations.xml

本文详细介绍了在Android构建过程中遇到的与元素类型“item”相关联的“name”属性值不能包含‘<’字符的问题及解决方案。通过修改SDK下的platform-tools/api/annotations.zip文件中的多个XML文件,将‘<’和‘>’字符替换为"<”和“>”,可以解决构建错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android构建时报错:

app:lintVitalRelease[Fatal Error] :3:214: 与元素类型 “item” 相关联的 “name” 属性值不能包含 ‘<’ 字符。

Could not read /Users/panxin/Library/Android/sdk/platform-tools/api/annotations.zip

java.io.IOException: Could not parse XML from android/accounts/annotations.xml

原因:sdk下/platform-tools/api/annotations.zip这个文件里的xml文件不规范造成的。

解决方法

  1. 到sdk目录下找到/platform-tools/api/annotations.zip这个文件并解压。

  2. 用记事本打开以下两个文件,并且把标签内的 ‘<’ 和 ‘>’ 字符分别替换成 "&lt;” 和 “&gt;”。

  • android/accounts/annotations.xml
  • android/hardware/camera2/annotations.xml
  • android/hardware/camera2/params/annotations.xml
  • android/app/slice/annotations.xml
  • android/widget/annotations.xml
  • android/view/annotations.xml
  • android/view/textclassifier/annotations.xml
  • android/bluetooth/le/annotations.xml
  • android/media/annotations.xml
  • android/preference/annotations.xml
  • android/text/annotations.xml
  1. 保存并压缩,替换掉原来的annotations.zip文件。

OR~~ 如果不想一个个去修改,可以直接使用我改好的这个annotations.zip文件。

注意(1): 编辑时要用以UTF-8无BOM方式编码,如果被编辑器加了BOM头,会导致另一个错误:
app:lintVitalRelease[Fatal Error] :1:1: 前言中不允许有内容。

注意(2) : 如果报以下错误::app:lintVitalRelease[Fatal Error] :1:1: 前言中不允许有内容。
Could not read /Users/panxin/Library/Android/sdk/platform-tools/api/annotations.zipjava.io.IOException:
Could not parse XML from __MACOSX/annotations/android/hardware/camera2/._annotations.xml
原因是:压缩时Mac系统会往文件里加入系统文件"__MACOSX",
解决办法是:使用终端去压缩:zip -r annotations.zip ./android

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值