問題描述
在將項目轉換為 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 使用錯誤的命名空間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!