报错
Illegal char <:> at index 47: com.iot.listeninsoul.app-mergeDebugResources-60:/values/values.xml
痛点
- 不知道哪个文件报错
- 报错的文件打开看不出来错误
- 网上各种方法不起作用
如何解决
- 把整个layout和java代码备份到其他文件夹
- 项目中的layout和com下面无任何文件
- 此时继续运行build 还是报错
- 到此说明此错误和java或者kotlin以及layout文件无关
- 问题必然出在attrs.xml这里
- 由于我的项目已经删除了layout和java代码,我把整个attrs.xml里面的定义的属性全部删除
- 再次运行build没有报错
- 至此说明attrs.xml的有问题
- 二分法删除;留一半自定义属性;再次编译,最终发现有一个自定义属性有问题
<declare-styleable name="verticalProgress">
<attr name="progress_radius" format="integer" />
<attr name="progress_border_enable" format="boolean" />
<attr name="progress_gradient_enable" format="boolean" />
<attr name="progress_start_color" format="reference" />
<attr name="progress_solid_color" format="reference" />
<attr name="progress_end_color" format="reference" />
<attr name="progress_border_color" format="reference" />
<attr name="progress_border_width" format="reference" />
</declare-styleable>
改个名字 问题彻底解决
正确代码
xml部分
<declare-styleable name="verticalProgress">
<attr name="vertical_progress_radius" format="integer" />
<attr name="vertical_progress_border_enable" format="boolean" />
<attr name="vertical_progress_gradient_enable" format="boolean" />
<attr name="vertical_progress_start_color" format="reference" />
<attr name="vertical_progress_solid_color" format="reference" />
<attr name="vertical_progress_end_color" format="reference" />
<attr name="vertical_progress_border_color" format="reference" />
<attr name="vertical_progress_border_width" format="reference" />
</declare-styleable>
注意 progress_border_width改为了 vertical_progress_border_width
java部分
TypedArray typedArray = null;
if (attrs != null) {
typedArray = context.obtainStyledAttributes(attrs, R.styleable.verticalProgress);
mRadius = typedArray.getInt(R.styleable.verticalProgress_vertical_progress_border_color, 0);
mBorderEnable = typedArray.getBoolean(R.styleable.verticalProgress_vertical_progress_border_enable, false);
mGradientEnable = typedArray.getBoolean(R.styleable.verticalProgress_vertical_progress_gradient_enable, true);
mStartResId = typedArray.getResourceId(R.styleable.verticalProgress_vertical_progress_start_color, R.color.GREEN);
mProgressBgColorId = typedArray.getResourceId(R.styleable.verticalProgress_vertical_progress_solid_color, R.color.white);
mEndResId = typedArray.getResourceId(R.styleable.verticalProgress_vertical_progress_end_color, R.color.red);
mBorderColorResId = typedArray.getResourceId(R.styleable.verticalProgress_vertical_progress_border_color, R.color.red3);
mBorderWidth = typedArray.getResourceId(R.styleable.verticalProgress_vertical_progress_border_width, 10);
}