久久久久久久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 庫的傳遞依賴)
主站蜘蛛池模板: 亚洲一级毛片 | 天堂国产| 国产专区视频 | 欧美日产国产成人免费图片 | 午夜视频在线免费观看 | 日韩a级片| 日本在线精品视频 | 亚洲天天干 | 国产成人在线一区 | 日本欧美黄色片 | 亚洲国产精品一区二区久久 | 国产黄色在线观看 | 国产一区亚洲二区三区 | 久久久久久久国产精品影院 | 国产精品资源在线 | 国产高清在线观看 | 欧美一级片a | 久久av一区二区三区 | 国产网站在线免费观看 | 国产精品亚洲精品 | 欧美精品v国产精品v日韩精品 | 亚洲36d大奶网 | 亚洲免费视频在线观看 | 夜夜爽99久久国产综合精品女不卡 | 久久精品国产99国产精品亚洲 | 成人在线精品视频 | 精品久久国产 | 久草青青草 | 欧美一区二区三区 | 成人av播放| 国产精品亚洲第一 | 日韩久草 | 欧美日韩亚洲一区 | 精品国产一区久久 | 99热热| 国产精品久久久久久久久久 | 国产h在线 | 免费一级片 | 成人在线精品 | 人人爽日日躁夜夜躁尤物 | 麻豆视频在线免费观看 |