Android Gradle 合并 Values.xml 使用错误的命名空间 [英] Android Gradle merged Values.xml uses wrong namespace

查看:10
本文介绍了Android Gradle 合并 Values.xml 使用错误的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将项目转换为 Android 构建系统的过程中,每当我尝试编译时都会收到此错误.

In the process of converting a project to the Android build system I get this error whenever I attempt to compile.

Gradle:解析 XML 时出错:前缀不能绑定到保留的命名空间名称之一

合并后的 values.xml 文件包含以下根元素:

The merged values.xml file contains the following root element:

<资源 xmlns:ns1="http://www.w3.org/2000/xmlns/">

此错误的原因是什么?如何解决?

What is the cause of this error and how can it be fixed?

推荐答案

我刚刚花了大约 2 个小时来挖掘破坏了我们的 Gradle 构建的 Git 提交.此提交包含超过 200 个更改的文件,其中包含 4000 多条修改的行.你可以想象它是多么有趣;)

I just spent around 2 hours digging through the Git commit that broke our Gradle build. This commit contained over 200 changed files with 4000+ modified lines. You can imagine how much fun it was ;)

无论如何,这就是导致我们这个模糊的 Gradle 错误的原因:在 res/values/styles.xml 中定义了一些具有 xmlns:custom 属性的样式:

Anyway, here is what caused this obscure Gradle error for us: Some styles with a xmlns:custom attribute were defined in res/values/styles.xml:

<style name="content" xmlns:custom="http://schemas.android.com/apk/res-auto">
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">@color/content</item>
</style>

如您所见,甚至没有使用 custom 命名空间.出于某种原因,Ant 和 ADT 构建并不关心这个属性,但是 Gradle :processDebugResources 任务却出现了一条不太有用的错误消息.

As you can see the custom namespace is not even used. For some reason the Ant and ADT builds did not care about this attribute, but the Gradle :processDebugResources task barfed with a not very helpful error message.

删除 xmlns:custom="http://schemas.android.com/apk/res-auto" 修复它.

使用的版本:Gradle 1.10 和 'com.android.tools.build:gradle:0.8.0'

Versions used: Gradle 1.10 and 'com.android.tools.build:gradle:0.8.0'

这篇关于Android Gradle 合并 Values.xml 使用错误的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆