【Android】拿捏Illegal char <:> at index 47: com.xx.xxx.xx.app-mergeDebugResources-60:/values/val

报错

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);
        }

<think>好的,用户遇到了Gradle下载URL中的非法字符错误,具体是“Illegal char <:> at index 6”。我需要先理解这个问题出现的原因。通常,这种错误是因为URL的格式不正确,比如协议头缺失或者路径中的特殊字符未被正确转义。 首先,用户可能在配置仓库地址时,比如在build.gradle文件中使用了不正确的URL格式。例如,可能遗漏了“http://”或“https://”协议头,导致Gradle解析时遇到冒号认为是非法字符。比如,如果写成url &#39;maven.example.com:8081/repository&#39;,这里的冒号会被视为非法,因为正确的URL应该以协议开头,如url &#39;http://maven.example.com:8081/repository&#39;。 接下来,我需要检查用户提供的引用内容。引用[2]提到“repositoryUrl”属性未知,这可能是因为变量未定义。而引用[3]建议调整仓库顺序,这可能与依赖解析有关,但和URL格式错误关系不大。不过,引用[3]中的例子展示了正确的URL写法,比如使用url &#39;https://jitpack.io&#39;,这提示用户需要确保URL包含协议头。 可能的解决步骤包括: 1. 检查build.gradle文件中所有仓库的URL,确认每个URL都以“http://”或“https://”开头。 2. 确保URL中的特殊字符(如端口号后的冒号)在正确的位置,并且整个URL被正确引用。 3. 如果有使用变量来定义URL,确保变量值正确且没有语法错误。 4. 清理Gradle缓存并重新同步项目,以排除缓存导致的旧配置问题。 此外,用户可能需要检查Gradle脚本中的字符串拼接是否正确,避免意外的字符插入。比如,动态生成URL时,拼接字符串可能导致冒号出现在错误的位置。 最后,根据引用[4],有时IDE的配置问题也可能引发异常,但当前错误更可能与URL格式直接相关。建议用户按照上述步骤修正URL后,重新尝试构建项目。</think>针对Gradle下载URL中出现`Illegal char <:> at index 6`错误,通常是由于URL格式不规范或特殊字符未转义导致。以下是分步解决方案: 1. **检查URL协议头缺失** - 错误示例:`url &#39;example.com:8081/repo&#39;` - 正确写法:`url &#39;http://example.com:8081/repo&#39;` - 必须包含`http://`或`https://`协议声明[^3] 2. **处理特殊符号转义** - 若URL包含保留字符(如`[]`或空格),需用URL编码: ```groovy url &#39;http://example.com:8081/path%20with%20space&#39; // 空格转义为%20 ``` 3. **验证动态拼接的URL** - 避免字符串拼接导致非法字符: ```groovy def repoPort = 8081 url "http://example.com:${repoPort}/repo" // 正确拼接 ``` 4. **清理Gradle缓存** ```bash ./gradlew cleanBuildCache # 清理缓存后重新同步 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

全面解读

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值