You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android布局资源编译失败如何排查修复?附错误截图与布局代码

问题根因

布局文件存在非法的资源ID命名,具体错误点在第二个RadioGroup下的RadioButton控件:

<RadioButton
    android:id="@+id/isn't_for_me"
    style="@style/NormalStyleLtBlue"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/str_forOthers" />

Android资源ID的命名规则要求仅允许使用大小写英文字母、数字、下划线,且不能以数字开头,你这里的ID包含单引号',违反了命名规则,直接触发资源编译失败。

解决方案

将非法ID修改为符合规则的命名即可,示例修改如下:

<RadioButton
    android:id="@+id/is_not_for_me"
    style="@style/NormalStyleLtBlue"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/str_forOthers" />

修改后按以下步骤重新构建项目即可:

  • 点击Android Studio顶部菜单栏 Build -> Clean Project 清理项目缓存
  • 清理完成后执行 Build -> Rebuild Project 重新构建
    如果你的Kotlin代码中已经引用了原来的非法ID,同步修改代码中的引用名为新的ID名即可。

内容的提问来源于stack exchange,提问作者MohamadMF

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 09:24:03