【我的Android进阶之旅】解决一次报错 AAPT: error: resource drawable/ (aka xxx) not found 导致的错误AAPT2 aapt2 Daemon #0

一、错误描述

今天添加一些新的UI修改功能之后,合并了develop分支的代码之后,编译出现了错误,如下所示:

在这里插入图片描述

具体的完整错误日志如下所示:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':watch:processDebugResources'.
> Android resource linking failed
  Output:  warn: removing resource com.xtc.watch:array/brightness without required default value.
  warn: removing resource com.xtc.watch:string/LimitedSizeLv without required default value.
  warn: removing resource com.xtc.watch:string/arrow_rectangle without required default value.
  warn: removing resource com.xtc.watch:string/auto_hide_activity without required default value.
  warn: removing resource com.xtc.watch:string/btn_test_button without required default value.
  warn: removing resource com.xtc.watch:string/bubble_seekbar_end_value without required default value.
  warn: removing resource com.xtc.watch:string/bubble_seekbar_start_value without required default value.
  warn: removing resource com.xtc.watch:string/bubble_seekbar_view without required default value.
  warn: removing resource com.xtc.watch:string/dialog_bottom_card_content without required default value.
  warn: removing resource com.xtc.watch:string/dialog_test_view without required default value.
  warn: removing resource com.xtc.watch:string/et_test_view without required default value.
  warn: removing resource com.xtc.watch:string/hand_writing_input_view without required default value.
  warn: removing resource com.xtc.watch:string/head_portrait_view without required default value.
  warn: removing resource com.xtc.watch:string/lifecycle without required default value.
  warn: removing resource com.xtc.watch:string/message_send without required default value.
  warn: removing resource com.xtc.watch:string/please_input without required default value.
  warn: removing resource com.xtc.watch:string/pop_warning_test_view without required default value.
  warn: removing resource com.xtc.watch:string/popup_test_button without required default value.
  warn: removing resource com.xtc.watch:string/popup_test_common without required default value.
  warn: removing resource com.xtc.watch:string/popup_test_view without required default value.
  warn: removing resource com.xtc.watch:string/progressbar_activity without required default value.
  warn: removing resource com.xtc.watch:string/radar_test_view without required default value.
  warn: removing resource com.xtc.watch:string/record_voice_view without required default value.
  warn: removing resource com.xtc.watch:string/recycler_view_footer without required default value.
  warn: removing resource com.xtc.watch:string/recycler_view_header without required default value.
  warn: removing resource com.xtc.watch:string/refresh_listview_pull_down_to_refresh_5_data without required default value.
  warn: removing resource com.xtc.watch:string/sb_test_view without required default value.
  warn: removing resource com.xtc.watch:string/slide_item_listview without required default value.
  warn: removing resource com.xtc.watch:string/sticky_test_style1 without required default value.
  warn: removing resource com.xtc.watch:string/sticky_test_style2 without required default value.
  warn: removing resource com.xtc.watch:string/sticky_test_view without required default value.
  warn: removing resource com.xtc.watch:string/string_badgetview_sign without required default value.
  warn: removing resource com.xtc.watch:string/string_blur without required default value.
  warn: removing resource com.xtc.watch:string/string_btn_selector_test without required default value.
  warn: removing resource com.xtc.watch:string/string_button_button without required default value.
  warn: removing resource com.xtc.watch:string/string_button_click_login without required default value.
  warn: removing resource com.xtc.watch:string/string_button_close_auto_hello without required default value.
  warn: removing resource com.xtc.watch:string/string_button_closing without required default value.
  warn: removing resource com.xtc.watch:string/string_button_login_success without required default value.
  warn: removing resource com.xtc.watch:string/string_button_next without required default value.
  warn: removing resource com.xtc.watch:string/string_button_open_auto_hello without required default value.
  warn: removing resource com.xtc.watch:string/string_button_opening without required default value.
  warn: removing resource com.xtc.watch:string/string_click_to_delete_dialog without required default value.
  warn: removing resource com.xtc.watch:string/string_common without required default value.
  warn: removing resource com.xtc.watch:string/string_compatibility without required default value.
  warn: removing resource com.xtc.watch:string/string_date_select without required default value.
  warn: removing resource com.xtc.watch:string/string_date_selector without required default value.
  warn: removing resource com.xtc.watch:string/string_delete_dialog without required default value.
  warn: removing resource com.xtc.watch:string/string_delete_dialog_ptr without required default value.
  warn: removing resource com.xtc.watch:string/string_fix_scrollbar without required default value.
  warn: removing resource com.xtc.watch:string/string_number_picker_view without required default value.
  warn: removing resource com.xtc.watch:string/string_performance without required default value.
  warn: removing resource com.xtc.watch:string/string_phone without required default value.
  warn: removing resource com.xtc.watch:string/string_progressbar without required default value.
  warn: removing resource com.xtc.watch:string/string_pull_to_refresh without required default value.
  warn: removing resource com.xtc.watch:string/string_test_activity without required default value.
  warn: removing resource com.xtc.watch:string/string_third without required default value.
  warn: removing resource com.xtc.watch:string/string_time_selector without required default value.
  warn: removing resource com.xtc.watch:string/string_watch without required default value.
  warn: removing resource com.xtc.watch:string/test_custom10 without required default value.
  warn: removing resource com.xtc.watch:string/tips_text without required default value.
  warn: removing resource com.xtc.watch:string/toast_activity without required default value.
  warn: removing resource com.xtc.watch:string/toast_test_str without required default value.
  warn: removing resource com.xtc.watch:string/toast_test_view without required default value.
  warn: removing resource com.xtc.watch:string/top_banner_btn without required default value.
  warn: removing resource com.xtc.watch:string/top_banner_content without required default value.
  warn: removing resource com.xtc.watch:string/waveview_activity without required default value.
  C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\debug\drawable\progressbar_drawable.xml:11: error: resource drawable/shape_progressbar_progress (aka com.xtc.watch:drawable/shape_progressbar_progress) not found.
  C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\debug\drawable\progressbar_drawable_whitebg.xml:11: error: resource drawable/shape_progressbar_yellow (aka com.xtc.watch:drawable/shape_progressbar_yellow) not found.
  C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\debug\layout\titlebar_view_search_et.xml:39: error: resource drawable/shape_guard_search (aka com.xtc.watch:drawable/shape_guard_search) not found.
  error: failed linking file resources.
  
  Command: C:\Users\000\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\32e22c0bbf6a32a728b2c6f6ccfeada9\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
          C:\Android\SDK\platforms\android-28\android.jar\
          --manifest\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
          -o\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
          -R\
          @C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
          --auto-add-overlay\
          --java\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
          --proguard-main-dex\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\legacy_multidex_aapt_derived_proguard_rules\debug\processDebugResources\manifest_keep.txt\
          --custom-package\
          com.xtc.watch\
          -0\
          apk\
          -c\
          zh-rCN,zh-rHK,zh-rTW,zh-rMO\
          --output-text-symbols\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\symbols\debug\R.txt\
          --no-version-vectors
  Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
  Output:  warn: removing resource com.xtc.watch:array/brightness without required default value.
  warn: removing resource com.xtc.watch:string/LimitedSizeLv without required default value.
  warn: removing resource com.xtc.watch:string/arrow_rectangle without required default value.
  warn: removing resource com.xtc.watch:string/auto_hide_activity without required default value.
  warn: removing resource com.xtc.watch:string/btn_test_button without required default value.
  warn: removing resource com.xtc.watch:string/bubble_seekbar_end_value without required default value.
  warn: removing resource com.xtc.watch:string/bubble_seekbar_start_value without required default value.
  warn: removing resource com.xtc.watch:string/bubble_seekbar_view without required default value.
  warn: removing resource com.xtc.watch:string/dialog_bottom_card_content without required default value.
  warn: removing resource com.xtc.watch:string/dialog_test_view without required default value.
  warn: removing resource com.xtc.watch:string/et_test_view without required default value.
  warn: removing resource com.xtc.watch:string/hand_writing_input_view without required default value.
  warn: removing resource com.xtc.watch:string/head_portrait_view without required default value.
  warn: removing resource com.xtc.watch:string/lifecycle without required default value.
  warn: removing resource com.xtc.watch:string/message_send without required default value.
  warn: removing resource com.xtc.watch:string/please_input without required default value.
  warn: removing resource com.xtc.watch:string/pop_warning_test_view without required default value.
  warn: removing resource com.xtc.watch:string/popup_test_button without required default value.
  warn: removing resource com.xtc.watch:string/popup_test_common without required default value.
  warn: removing resource com.xtc.watch:string/popup_test_view without required default value.
  warn: removing resource com.xtc.watch:string/progressbar_activity without required default value.
  warn: removing resource com.xtc.watch:string/radar_test_view without required default value.
  warn: removing resource com.xtc.watch:string/record_voice_view without required default value.
  warn: removing resource com.xtc.watch:string/recycler_view_footer without required default value.
  warn: removing resource com.xtc.watch:string/recycler_view_header without required default value.
  warn: removing resource com.xtc.watch:string/refresh_listview_pull_down_to_refresh_5_data without required default value.
  warn: removing resource com.xtc.watch:string/sb_test_view without required default value.
  warn: removing resource com.xtc.watch:string/slide_item_listview without required default value.
  warn: removing resource com.xtc.watch:string/sticky_test_style1 without required default value.
  warn: removing resource com.xtc.watch:string/sticky_test_style2 without required default value.
  warn: removing resource com.xtc.watch:string/sticky_test_view without required default value.
  warn: removing resource com.xtc.watch:string/string_badgetview_sign without required default value.
  warn: removing resource com.xtc.watch:string/string_blur without required default value.
  warn: removing resource com.xtc.watch:string/string_btn_selector_test without required default value.
  warn: removing resource com.xtc.watch:string/string_button_button without required default value.
  warn: removing resource com.xtc.watch:string/string_button_click_login without required default value.
  warn: removing resource com.xtc.watch:string/string_button_close_auto_hello without required default value.
  warn: removing resource com.xtc.watch:string/string_button_closing without required default value.
  warn: removing resource com.xtc.watch:string/string_button_login_success without required default value.
  warn: removing resource com.xtc.watch:string/string_button_next without required default value.
  warn: removing resource com.xtc.watch:string/string_button_open_auto_hello without required default value.
  warn: removing resource com.xtc.watch:string/string_button_opening without required default value.
  warn: removing resource com.xtc.watch:string/string_click_to_delete_dialog without required default value.
  warn: removing resource com.xtc.watch:string/string_common without required default value.
  warn: removing resource com.xtc.watch:string/string_compatibility without required default value.
  warn: removing resource com.xtc.watch:string/string_date_select without required default value.
  warn: removing resource com.xtc.watch:string/string_date_selector without required default value.
  warn: removing resource com.xtc.watch:string/string_delete_dialog without required default value.
  warn: removing resource com.xtc.watch:string/string_delete_dialog_ptr without required default value.
  warn: removing resource com.xtc.watch:string/string_fix_scrollbar without required default value.
  warn: removing resource com.xtc.watch:string/string_number_picker_view without required default value.
  warn: removing resource com.xtc.watch:string/string_performance without required default value.
  warn: removing resource com.xtc.watch:string/string_phone without required default value.
  warn: removing resource com.xtc.watch:string/string_progressbar without required default value.
  warn: removing resource com.xtc.watch:string/string_pull_to_refresh without required default value.
  warn: removing resource com.xtc.watch:string/string_test_activity without required default value.
  warn: removing resource com.xtc.watch:string/string_third without required default value.
  warn: removing resource com.xtc.watch:string/string_time_selector without required default value.
  warn: removing resource com.xtc.watch:string/string_watch without required default value.
  warn: removing resource com.xtc.watch:string/test_custom10 without required default value.
  warn: removing resource com.xtc.watch:string/tips_text without required default value.
  warn: removing resource com.xtc.watch:string/toast_activity without required default value.
  warn: removing resource com.xtc.watch:string/toast_test_str without required default value.
  warn: removing resource com.xtc.watch:string/toast_test_view without required default value.
  warn: removing resource com.xtc.watch:string/top_banner_btn without required default value.
  warn: removing resource com.xtc.watch:string/top_banner_content without required default value.
  warn: removing resource com.xtc.watch:string/waveview_activity without required default value.
  C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\debug\drawable\progressbar_drawable.xml:11: AAPT: error: resource drawable/shape_progressbar_progress (aka com.xtc.watch:drawable/shape_progressbar_progress) not found.
      
  C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\debug\drawable\progressbar_drawable_whitebg.xml:11: AAPT: error: resource drawable/shape_progressbar_yellow (aka com.xtc.watch:drawable/shape_progressbar_yellow) not found.
      
  C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\debug\layout\titlebar_view_search_et.xml:39: AAPT: error: resource drawable/shape_guard_search (aka com.xtc.watch:drawable/shape_guard_search) not found.
      
  error: failed linking file resources.
  Command: C:\Users\000\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\32e22c0bbf6a32a728b2c6f6ccfeada9\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
          C:\Android\SDK\platforms\android-28\android.jar\
          --manifest\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
          -o\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
          -R\
          @C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
          --auto-add-overlay\
          --java\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
          --proguard-main-dex\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\legacy_multidex_aapt_derived_proguard_rules\debug\processDebugResources\manifest_keep.txt\
          --custom-package\
          com.xtc.watch\
          -0\
          apk\
          -c\
          zh-rCN,zh-rHK,zh-rTW,zh-rMO\
          --output-text-symbols\
          C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\watch\build\intermediates\symbols\debug\R.txt\
          --no-version-vectors
  Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 3s
341 actionable tasks: 302 executed, 39 up-to-date

二、分析错误

错误日志显示下面的几个drawable资源文件找不到。

C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\
debug\drawable\progressbar_drawable.xml:11: error: resource drawable/shape_progressbar_progress 
(aka com.xtc.watch:drawable/shape_progressbar_progress) not found.

  C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\
  debug\drawable\progressbar_drawable_whitebg.xml:11: error: resource drawable/shape_progressbar_yellow 
  (aka com.xtc.watch:drawable/shape_progressbar_yellow) not found.
  
  C:\CodeForAndroid\XTCWatch\XTCWatch\XTCWatch\basiclib\build\intermediates\packaged_res\
  debug\layout\titlebar_view_search_et.xml:39: error: resource drawable/shape_guard_search
   (aka com.xtc.watch:drawable/shape_guard_search) not found.
  

2.1 上面的几个资源文件是否真的不存在?

于是我去查询下这几个资源文件是否真的不存在?

  • shape_progressbar_progress 文件明明是存在的
    在这里插入图片描述
  • progressbar_drawable_whitebg 文件明明是存在的
    在这里插入图片描述
  • shape_guard_search 文件明明是存在的
    在这里插入图片描述

查看代码可以分析出来这几个资源文件是真实存在的,可是为什么要报错AAPT的时候这几个文件不存在呢?

2.2 继续分析

我一开始以为是因为我合并了develop分支,增加了很多代码导致的。但是查看了合并记录,这几个文件并没有任何改动。所以合并代码这怀疑点被pass了。

但是其他的地方又无法查到到底是什么原因导致的?

其实我也有怀疑是不是自己增加的UI改动出现了问题,但是整个预览过程都没问题,正好合并完develop代码就出现问题无法编译无法预览了,因为合并完代码需要sync一下,sync失败了。

直到我看到下面的这个stackOverflow的信息,我才怀疑真的是自己添加的UI改动可能出现了问题

  • https://stackoverflow.com/questions/49965610/aapt-error-resource-drawable-not-found》

I fixed the error, which was probably coming from a mal-formatted copied xml file (probably some line-ending confusion)
Rewriting those fixed the error, although Android Studio displayed another file as the source of the problem, which in fact had nothing to do with the error itself

在这里插入图片描述

这句话的大概翻译是:

我修正了这个错误,它可能来自一个格式错误的复制XML文件(可能是一些行尾混乱)。
重写这些文件修复了错误,尽管Android Studio显示了另一个文件作为问题的根源,实际上这与错误本身无关。

好吧,看起来就是这个原因,尽管Android Studio显示了另一个文件作为问题的根源,实际上这与错误本身无关。

2.3 还原自己修改的UI代码,看看是否可以正常编译

如下所示,我使用git操作将自己提交的这一次代码全部revert
在这里插入图片描述

然后重新编译,好吧,这次编译成功了!

在这里插入图片描述

看来问题果然是这样的

尽管Android Studio显示了另一个文件作为问题的根源,实际上这与错误本身无关。

看起来Android Studio显示的是那三个我完全没有修改过,合并代码也没有修改过的文件找不到的错误,实际上完全和那几个文件没半毛钱关系。太坑了!

2.4 恢复之前提交的代码,查看问题所在

所以可能肯定一定是自己提交的代码出现了问题,因为恢复之前提交的代码之后又不能编译了。所以最终把所提交的代码一行一行的看,到底哪里出了问题。

在这里插入图片描述

看红框中,根本原因是copy代码无意中多copy了一段xml的声明头

问题是 即使是多写了xml声明头,也可以正常预览。
在这里插入图片描述
错误代码如下

<?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?>
<!--banner蓝色的底色渐变效果背景-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="315"
        android:endColor="#0099ff"
        android:startColor="#00a8ff"
        android:type="linear" />
    <corners android:radius="12dp" />
</shape>

2.5 解决错误

将上面多与的xml声明头 去掉 即可正常编译了。

正确的代码

<?xml version="1.0" encoding="utf-8"?>
<!--banner蓝色的底色渐变效果背景-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="315"
        android:endColor="#0099ff"
        android:startColor="#00a8ff"
        android:type="linear" />
    <corners android:radius="12dp" />
</shape>

在这里插入图片描述

三、总结

3.1 这个问题的根本原因

这个问题的根本原因是 xml布局文件 多写了一个 xml声明头

3.2 Android Studio 报错

尽管Android Studio显示了另一个文件作为问题的根源,实际上这与错误本身无关。 太TM坑爹了!

找到这个问题,瞬间感觉很无语,很SB,这代码应该就是我copy其他的xml文件的时候,导致xml声明头重复了,但是Android Studio没有任何的提示错误导致的。

3.3 计划自定义Lint规则

看来这个问题,我还真得写一个自定义的Lint规则来检测这个xml声明头部多写的问题。

之前我有写Lint规则来检测 xml头部文件没有写的错误,这次得加一个多写了的Lint规则才行。
在这里插入图片描述


作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:https://blog.csdn.net/qq446282412/article/details/97922012
☞ 本人QQ: 3024665621
☞ QQ交流群: 123133153
☞ github.com/ouyangpeng
☞ oypcz@foxmail.com


发布了469 篇原创文章 · 获赞 1452 · 访问量 355万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览