gradle无法解决strings.xml中的$ {com.mxx.stc}

时间:2015-05-18 07:29:30

标签: android android-studio gradle

我的strings.xml

<bool name="debug_mode">${com.mxx.stc}</bool>

我的build.gradle

String debug_mode ="\\u0024\\u007Bcom.mxx.stc\\u007D"
def replaceInString = {variant, fromString, toString ->
            File valuesFile = file("${buildDir}/intermediates/res/${variant.dirName}/values/values.xml")
    println "Replacing revision number in " + valuesFile
    String content = valuesFile.getText('UTF-8')
    content = content.replaceAll(fromString, toString)
    valuesFile.write(content, 'UTF-8')
}
android.applicationVariants.all{ variant ->
    variant.mergeResources.doLast{
    replaceInString(variant,debug_mode ,"true")
}

然后gradle将显示错误:

Error:(22, 29) String types not allowed (at 'debug_mode' with value '${com.mxx.stc}')

我该如何解决这个问题?我可以跳过错误吗?顺便说一句,如果占位符是一个字符串标记,gradle工作正常。

0 个答案:

没有答案