本文介绍了Gradle buildConfigField:数组&的语法地图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

android gradle文档中提到了关于buildConfigField:
$ b

我找不到关于buildConfigField值语法的任何信息,如果类型是字符串,那么值应该包含引号。数组,Arraylist还是HashMap?由于它们被编译到java代码中,所以一切都应该是可能的。



有没有人有一些例子或文档?

解决方案

对于数组

app.gradle

  buildConfigFieldString [],URL_ARRAY,
{+
\http:someurl \,+
\http :someurl \,+
\http:someurl\+
}

对于Map

  buildConfigFieldjava.util.Map< String,String>, NAME_MAP,
new java.util.HashMap< String,+
String>(){{put(\name \,\John \);放(\name1 \,\John \);放(\name2\,+
\John \);}}

访问代码:

  HashMap< String,String> ; name =(HashMap< String,String>)BuildConfig.NAME_MAP; 


The android gradle documentation says about buildConfigField:

I can't find any information about the syntax of buildConfigField values for Arrays, Arraylist or a HashMap? Since they are compiled into java code usually everything should be possible.

Does anyone has some examples or documentation?

解决方案

For array

app.gradle

        buildConfigField "String[]", "URL_ARRAY",
        "{" +
        "\"http:someurl\"," +
        "\"http:someurl\"," +
        "\"http:someurl\"" +
        "}"

For Map

        buildConfigField "java.util.Map<String, String>", "NAME_MAP",
                 "new java.util.HashMap<String, " +
                 "String>() {{ put(\"name\", \"John\"); put(\"name1\",  \"John\"); put(\"name2\", " +
                "\"John\"); }}"

Access in code:

HashMap<String, String> name = (HashMap<String, String>) BuildConfig.NAME_MAP;

这篇关于Gradle buildConfigField:数组&amp;的语法地图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 04:23