resValue摇篮错误:不支持的类型"串"在" generated.xml" [英] resValue gradle error: Unsupported type "String" in "generated.xml"
问题描述
几个星期前,我发布了一个问题,<一个href="http://stackoverflow.com/questions/21159484/override-resources-with-gradle-depending-on-buildtype">How覆盖取决于buildType 资源。 而就在昨天有一个摇篮插件版本为Android 。 基于这个职位上G + 我决定写这个问题。
我已经详细描述的问题:
我想创建根据 buildType
,但这不能正常工作的一些资源值:
文件generated.xml将只如果我做一个完整的构建在命令行中创建的:
gradlew构建
但我也通过建立在comannd线完整的项目得到一个错误:
*出了什么问题:执行失败的任务:应用程序:合并&LT; buildVariant&GT;资源。
不支持的类型'字符串'在文件C:\用户\ ... \编译\水库\产生\发布\值\ generated.xml
每隔集结审判不会创建该文件。我尝试以下操作:
- 在IDE:
- 在改造项目
- 在执行外部任务assembleBuildVariant
- 在命令行:
- gradlew assembleBuildVariant
奇怪的摇篮控制台输出:
:应用:generateBuildVariantResValues UP-TO-DATE
我build.gradle:
buildTypes {
调试{
buildConfigField字符串,富,\FOO DEBUG \
resValue字符串,RES FOO,RES FOO DEBUG
}
推出 {
buildConfigField字符串,富,\FOO发布\
resValue字符串,RES FOO,RES FOO释放
}
}
我的generated.xml:
&LT;! - 自动生成的文件。请勿修改 - &GT;
&LT; - 从生成类型值:释放 - &GT;
&LT;项目名称=RES FOO类型=字符串&GT; RES FOO发布&LT; /项目&GT;
我的问题:
这是一个错误还是我错过了什么?为什么这个文件不是由创建一个重建
在IDE?
我build.gradle(更新2014年2月10日根据rciovatis答案):
defaultConfig {
的minSdkVersion 14
targetSdkVersion 19
版本code 1
VERSIONNAME1.0
resValue串,RES_FOO,RES FOO
}
buildTypes {
调试{
buildConfigField字符串,富,\FOO DEBUG \
resValue串,RES_FOO,RES FOO DEBUG
}
推出 {
buildConfigField字符串,富,\FOO发布\
resValue串,RES_FOO,RES FOO释放
}
}
更新2014年2月14日其工作原理:
在的摇篮Android插件一切的最新优秀作品:
在/建设/ RES /所有/你应该看到下列文件夹:
- 所有
- 生成( - 在这里>您查找生成的资源值
resValue
)
第一个文件夹所有
包含所有合并的资源。在方向所有/&LT; buildVariant&GT; /values/values.xml
你应该找到生成的资源,在我的情况:
//为buildType DEBUG
&LT;项目名称=命名为testFoo类型=字符串&GT;测试FOO DEBUG&LT; /项目&GT;
//为buildType发布
&LT;项目名称=命名为testFoo类型=字符串&GT;测试FOO发布&LT; /项目&GT;
要得到code的值只使用生成的资源所有其他人一样:
getResources()的getString(R.string.TESTFOO)
我解决还增加了资源的 defaultConfig
块。对于你这会是这样的:
安卓{
defaultConfig {
resValue串,RES_FOO,RES FOO释放
}
buildTypes {
调试{
buildConfigField字符串,富,\FOO DEBUG \
resValue串,RES_FOO,RES FOO DEBUG
}
推出 {
buildConfigField字符串,富,\FOO发布\
resValue串,RES_FOO,RES FOO释放
}
}
}
请注意:
- 在项目类型必须为
字符串
,而不是字符串
- 在项目名称中不能包含空格(如正常的资源名称)
编辑: 由于0.8.3它应该工作正常刚刚宣布resValue在构建类型的块。
A few weeks ago I posted a question How to override resources depending on buildType. And just yesterday there was a gradle plugin release for android. Based on this post on G+ I decided to write this question.
The problem I have described in detail:
I want to create some resource values depending on the buildType
, but this doesn't work properly:
The file "generated.xml" will be only created if I make a complete build over the command line:
gradlew build
But I also get an error by building the complete project over comannd line:
* What went wrong: Execution failed for task ':app:merge<buildVariant>Resources'.
Unsupported type 'String' in file C:\Users\...\build\res\generated\release\values\generated.xml
Every other build-trial doesn't create this file. I tried following:
- over IDE:
- rebuild project
- execute external task "assembleBuildVariant"
- over command line:
- gradlew assembleBuildVariant
Strange gradle console output:
:app:generateBuildVariantResValues UP-TO-DATE
My build.gradle:
buildTypes {
debug{
buildConfigField "String", "FOO", "\"FOO DEBUG\""
resValue "String", "RES FOO", "RES FOO DEBUG"
}
release {
buildConfigField "String", "FOO", "\"FOO RELEASE\""
resValue "String", "RES FOO", "RES FOO RELEASE"
}
}
My "generated.xml":
<!-- Automatically generated file. DO NOT MODIFY -->
<!-- Values from build type: release -->
<item name="RES FOO" type="String">RES FOO RELEASE</item>
My question:
Is this a bug or did I miss something? And why this file isn't created by a Rebuild
over the IDE?
My build.gradle (UPDATE 2014-02-10 based on rciovatis answer):
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
resValue "string", "RES_FOO", "RES FOO"
}
buildTypes {
debug{
buildConfigField "String", "FOO", "\"FOO DEBUG\""
resValue "string", "RES_FOO", "RES FOO DEBUG"
}
release {
buildConfigField "String", "FOO", "\"FOO RELEASE\""
resValue "string", "RES_FOO", "RES FOO RELEASE"
}
}
UPDATE 2014-02-14 IT WORKS:
After an update of the gradle android plugin everything works fine:
In /build/res/all/ you should see following folders:
- all
- generated (-> here you find the generated resource values by
resValue
)
The first folder all
contains all merged resources. In the direction all/<buildVariant>/values/values.xml
you should find the generated resources, in my case:
// for buildType DEBUG
<item name="TESTFOO" type="string">TEST FOO DEBUG</item>
// for buildType RELEASE
<item name="TESTFOO" type="string">TEST FOO RELEASE</item>
To get the values in code just use the generated resource like all others:
getResources().getString(R.string.TESTFOO)
I solved adding the resources also in the defaultConfig
block. For you it would be something like:
android {
defaultConfig {
resValue "string", "RES_FOO", "RES FOO RELEASE"
}
buildTypes {
debug{
buildConfigField "String", "FOO", "\"FOO DEBUG\""
resValue "string", "RES_FOO", "RES FOO DEBUG"
}
release {
buildConfigField "String", "FOO", "\"FOO RELEASE\""
resValue "string", "RES_FOO", "RES FOO RELEASE"
}
}
}
Please note that:
- item type must be
string
and notString
- item name must not contain spaces (as normal resource name)
EDIT: Since 0.8.3 it should works fine just declaring the resValue in the build type block.
这篇关于resValue摇篮错误:不支持的类型&QUOT;串&QUOT;在&QUOT; generated.xml&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!