构建失败并出现异常:给定资源值无效<color>

问题描述 投票:0回答:1

尝试在 Pixel 5 设备上运行我的 Flutter 应用程序时,收到以下错误消息:

/Users/username/.gradle/caches/transforms-3/0ace7b4637c402760ef38d3581a65ee0/transformed/appcompat-1.4.2/res/values/values.xml:37:4: Invalid <color> for given resource value.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
   > Resource compilation failed. Check logs for details.

* 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 22s

这是产生问题的文件的一些代码。第 37 行是问题所在,但我不明白为什么,因为它的格式正确,如上面的行。

...
35    <color name="foreground_material_light">@android:color/black</color>
36    <color name="highlighted_text_material_dark">#6680cbc4</color>
37    <color name="highlighted_text_material_light">#66009688</color>
38    <color name="material_blue_grey_800">#ff37474f</color>
...

有人对这个错误有可能的解决方案吗?

android flutter material-ui colors build.gradle
1个回答
0
投票

这些值的格式似乎正确,并为其分配了颜色名称和十六进制值。

您收到的错误消息表明第 37 行指定的颜色存在问题:

<color name="highlighted_text_material_light">#66009688</color>
。颜色值格式似乎是正确的(alpha 值后跟 RGB),因此仅从该代码片段中可能不会立即看出错误。

如果尽管格式看似正确,但错误仍然存在,请考虑以下步骤:

  1. 验证语法:确保文件中没有拼写错误、缺少字符或语法错误。

  2. 检查引用一致性: 确保任何引用(例如

    @android:color/black
    )均已正确定义且可访问。

  3. 其他情况:有时,在特定行号报告的错误实际上可能源自较早的行或其他相关文件。查看整个

    values.xml
    文件是否存在任何潜在的相关问题。

  4. 构建工具或 IDE 缓存:如果错误看起来难以解释,清除 Gradle 缓存或重建项目可能有助于解决缓存数据引起的一些问题。

确保保存对

values.xml
文件所做的任何更改,然后尝试重建项目。如果问题仍然存在,检查完整的错误日志或使用调试选项运行构建可能会提供更具体的信息来查明问题。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.