gpt4 book ai didi

android - 如何在字符串资源文件中使用resValue

转载 作者:行者123 更新时间:2023-12-03 05:13:29 25 4
gpt4 key购买 nike

我在~/.gradle/gradle.properties中定义了一个属性,我想在字符串资源文件中访问它。

~/.gradle/gradle.properties中的定义ServerIP="XXX.XXX.XX.XX"app/build.gradle中的声明

android {  
buildTypes.each {
it.resValue "string", "ServerIP", "SERVER_IP"
}
}

string/web_services.xml中的用法 <string name="serverIP">@string/SERVER_IP</string>
在生成时出错 Error:(4, 5) No resource found that matches the given name (at 'serverIP' with value '@string/SERVER_IP').
有什么方法可以做到这一点还是不能做到?

最佳答案

问题在于此行:

it.resValue "string", "ServerIP", "SERVER_IP"

第一个参数是type,第二个参数是name,第三个参数是value。在您的情况下,名称应为 "SERVER_IP",值应为 ServerIP(不带引号)。所以最后一块 build.gradle:
android {  
buildTypes.each {
it.resValue "string", "SERVER_IP", ServerIP
}
}

关于android - 如何在字符串资源文件中使用resValue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38686210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com