错误:无法确定标签'< item name ='APP_URL'的类型;type =“字符串">"https://www.dummyurl_dev.com/"</item>'在构建gradleResValues.xml中 [英] Error: Can't determine type for tag '<item name="APP_URL" type="String">"https://www.dummyurl_dev.com/"</item>' in build gradleResValues.xml

查看:85
本文介绍了错误:无法确定标签'< item name ='APP_URL'的类型;type =“字符串">"https://www.dummyurl_dev.com/"</item>'在构建gradleResValues.xml中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的应用程序API URL保留在项目根文件夹的 config.properties 中,并尝试在模块级build.gradle 中读取这些值.>文件,并将其分配给 resValue 以便在应用程序中进行全局访问.

I tried to keep my app API URL in config.properties in the root folder of the project, and try to read in those value in module-level build.gradle file and assign it to resValue for global access in the application.

但是,我面临一个问题.我将URL保留在属性文件中,并尝试基于构建变体执行应用程序,但是编译器将返回错误.如何保持全球价值?
预先感谢.

but, I am facing an issue. I keep the URL in a property file and try to execute the application based on the build variant, but the compiler will return an error. how to keep the value global?.
Thanks in advance.

这是我在 build.gradle 中阅读的 config.properties

def configProperties = new Properties()
configProperties.load(new FileInputStream(rootProject.file("config.properties")))

buildTypes

buildTypes {
          rc {
              resValue("String", "APP_URL", configProperties.getProperty('RC_URL'))
             }
 }

在编译时将显示此错误

错误: 构建:失败

:uimodule:mergeDevResources

uimodule/build/生成/res/resValues/dev/values/gradleResValues.xml无法确定标签" https://www.dummyurl_dev.com/"

项目根路径:

访问build.gradle中的属性文件:

构建输出中的编译器错误

推荐答案

最后,我找到了解决此问题的方法,

Finally, I got the solution for this issue,

在模块级build.gradle的buildTypes中引入新变量,将resValue替换为buildConfigField并传递类似这样的参数 "\" $ appUrl \" .在此示例中,我使用 'RC' 作为构建变体,而不是 'dev' .

Introduce new variable in buildTypes in module-level build.gradle, replace resValue into buildConfigField and pass the arguments like this "\"$appUrl\"" .Here I using 'RC' as build variant instead of 'dev' for this example.

build.gradle: 模块级别

buildTypes {
         rc {
              def appUrl = configProperties['RC_URL']
              buildConfigField("String", "APP_URL", "\"$appUrl\"")
              // following line made this error
              //resValue("String", "APP_URL", configProperties.getProperty('RC_URL'))
            }
}

BuildConfig.java:作为参考,我在这里添加了buildconfig文件代码,实际上是这样做的.

BuildConfig.java: for reference, I added my buildconfig file code here, which is actually done so for.

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "com.mohan.uimodule";
  public static final String BUILD_TYPE = "rc";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";
  

//types of url which i have in config.properties
  public static final String DEV_URL = "https://www.dummyurl_dev.com/";
  public static final String PROD_URL = "https://www.dummyurl_prod.com/";
  public static final String RC_URL = "https://www.dummyurl_rc.com/";

// Fields from build type: rc
  public static final String APP_URL = "https://www.dummyurl_rc.com/";
}

解决方案:这是我从 buildconfig.java 获得的预期结果,这也是我的期望

Solution: this is the expected result I got from buildconfig.java and this is my expectation too

public static final String APP_URL = "https://www.dummyurl_rc.com/";

希望这个答案会有所帮助.编码愉快,谢谢:)

Hope this answer will help. happy coding, Thanks :)

这篇关于错误:无法确定标签'< item name ='APP_URL'的类型;type =“字符串">"https://www.dummyurl_dev.com/"</item>'在构建gradleResValues.xml中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆