Android構建時報錯: java.io.IOException: Could not parse XML from android/accounts/annotations.xml

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章