最近升级了AS 3.2以及android 28版本以后,编译报错如下:
Android resource compilation failed
Output: /Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2402: error: <item> inner element must either be a resource reference or empty.
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2405: error: <item> inner element must either be a resource reference or empty.
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2407: error: <item> inner element must either be a resource reference or empty.
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2408: error: <item> inner element must either be a resource reference or empty.
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2410: error: <item> inner element must either be a resource reference or empty.
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2413: error: <item> inner element must either be a resource reference or empty.
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2417: error: <item> inner element must either be a resource reference or empty.
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2426: error: <item> inner element must either be a resource reference or empty.
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:2441: error: <item> inner element must either be a resource reference or empty.
Command: /Users/landsnail/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.0-4818971-osx.jar/e0da4fbc7cf5af02b16018ef1295676c/aapt2-3.2.0-4818971-osx/aapt2 compile --legacy \
-o \
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/res/merged/debug \
/Users/landsnail/Documents/gemdale/gdhlwandroid/decorate/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
Daemon: AAPT2 aapt2-3.2.0-4818971-osx Daemon #0
在帖子:https://blog.csdn.net/ZDF123654/article/details/81285995 的启发下,博主的报错定位到问题点后发现,最近赋值的id值都会报错,而系统的不会报错,显然是高版本不再允许单独定义xml元素中的id值:
<item name="glide_custom_view_target_tag" type="id"/> // 没报错
<item name="group_position" type="id">0x09</item> //这行报错了
<item name="home" type="id"/> // 没报错
看出区别了吗?
使用group_position
定位到ids.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="data" type="id">0x01</item>
<item name="image_view" type="id">0x02</item>
<item name="image_button" type="id">0x03</item>
<item name="ll_not_pass" type="id">0x04</item>
<item name="tag" type="id">0x05</item>
<item name="position" type="id">0x06</item>
<item name="iv_if_pass" type="id">0x07</item>
<item name="tv_if_pass" type="id">0x08</item>
<item name="group_position" type="id">0x09</item>
</resources>
把报错的item的格式改为:<item name="group_position" type="id" />,编译后报错解除。