久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

resValue gradle 錯誤:不支持的類型“字符串"在“

resValue gradle error: Unsupported type quot;Stringquot; in quot;generated.xmlquot;(resValue gradle 錯誤:不支持的類型“字符串在“生成的.xml中)
本文介紹了resValue gradle 錯誤:不支持的類型“字符串"在“生成的.xml"中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

幾周前我發布了一個問題如何根據 buildType 覆蓋資源.就在昨天,還有一個 gradle 插件版本為 android.根據這篇關于 G+ 的帖子,我決定寫下這個問題.

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.

我已經詳細描述的問題:

我想根據 buildType 創建一些資源值,但這不能正常工作:只有在我通過命令行進行完整構建時才會創建文件generated.xml":

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...uild
esgenerated
eleasevaluesgenerated.xml

所有其他構建試用版都不會創建此文件.我嘗試了以下操作:

Every other build-trial doesn't create this file. I tried following:

  • 通過 IDE:
    • 重建項目
    • 執行外部任務assembleBuildVariant"
    • gradlew assembleBuildVariant

    奇怪的 gradle 控制臺輸出:

    Strange gradle console output:

    :app:generateBuildVariantResValues UP-TO-DATE
    

    我的 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"
        }
    }
    

    我的生成的.xml":

    <!-- Automatically generated file. DO NOT MODIFY -->
    
    <!-- Values from build type: release -->
    <item name="RES FOO" type="String">RES FOO RELEASE</item>
    

    我的問題:

    這是一個錯誤還是我錯過了什么?為什么這個文件不是由 IDE 上的 Rebuild 創建的?

    Is this a bug or did I miss something? And why this file isn't created by a Rebuild over the IDE?

    我的 build.gradle(更新 2014-02-10 基于 rciovatis 答案):

    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"
        }
    }
    

    2014 年 2 月 14 日更新它的工作原理:

    更新 gradle android 插件之后一切正常:

    在/build/res/all/中,您應該會看到以下文件夾:

    In /build/res/all/ you should see following folders:

    • 全部
    • 已生成(-> 在這里您可以通過 resValue 找到生成的資源值)
    • all
    • generated (-> here you find the generated resource values by resValue)

    第一個文件夾all 包含所有合并的資源.在方向 all/<buildVariant>/values/values.xml 你應該找到生成的資源,在我的例子中:

    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)
    

    推薦答案

    我解決了在 defaultConfig 塊中添加資源的問題.對你來說,它會是這樣的:

    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"
            }
        }
    }
    

    請注意:

    • 項目類型必須是 string 而不是 String
    • 項目名稱不得包含空格(與正常資源名稱一樣)

    從 0.8.3 開始,只需在構建類型塊中聲明 resValue 即可正常工作.

    Since 0.8.3 it should works fine just declaring the resValue in the build type block.

    這篇關于resValue gradle 錯誤:不支持的類型“字符串"在“生成的.xml"中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

    【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出現 IncompatibleClassChangeError)
How to get current flavor in gradle(如何在 gradle 中獲取當前風味)
How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修復“意外元素lt;查詢gt;在“清單中找到錯誤?)
Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多風味庫的多風味應用)
Android dependency has different version for the compile and runtime(Android 依賴在編譯和運行時有不同的版本)
Transitive dependencies for local aar library(本地 aar 庫的傳遞依賴)
主站蜘蛛池模板: 亚洲日韩中文字幕一区 | 欧美人成在线视频 | 亚洲日本欧美日韩高观看 | 天天草草草 | 黄色毛片网站在线观看 | 亚洲国产成人一区二区 | 在线电影日韩 | 国产日韩一区二区三免费高清 | 男女啪啪网址 | 欧美极品在线 | 日韩中文字幕视频在线观看 | 国产伦一区二区三区久久 | 欧洲一区二区三区 | 国产一区中文字幕 | 亚洲国产精品久久久久秋霞不卡 | 精品一区二区三区电影 | 日日骚网 | 免费在线观看一级毛片 | 免费亚洲一区二区 | 亚洲视频在线观看 | 秋霞在线一区二区 | 自拍偷拍亚洲欧美 | 老司机午夜性大片 | 日本人麻豆 | 欧美色999 | 伊人久操| 拍真实国产伦偷精品 | 日韩欧美一级 | 亚洲免费一区二区 | 国产精品夜间视频香蕉 | 亚洲视频在线观看 | 久久久国产一区二区三区四区小说 | 免费成人av | 看片91| 国产成人精品免费视频大全最热 | 天天碰日日操 | 久久精品国产一区二区电影 | 国产日韩精品一区二区三区 | 蜜桃在线一区二区三区 | 午夜影院在线观看 | 精品国产1区2区3区 在线国产视频 |