gpt4 book ai didi

Android BuildConfig 字段生成字符串不正确

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:21:08 27 4
gpt4 key购买 nike

开始新项目的最后一天,我在构建配置中创建了一些变量,作为在发布和调试构建之间单独处理它们的好习惯,如下所示:

...
buildTypes {
release {
minifyEnabled false
buildConfigField("String", "PARSE_APP_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
buildConfigField("String", "PARSE_CLIENT_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxx")
buildConfigField("String", "FACEBOOK_APP_ID", "999999999999999")
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
minifyEnabled false
buildConfigField("String", "PARSE_APP_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
buildConfigField("String", "PARSE_CLIENT_ID", "xxxxxxxxxxxxxxxxxxxxxxxxxx")
buildConfigField("String", "FACEBOOK_APP_ID", "999999999999999")
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
...

问题是它没有正确地创建字符串,而是直接打印字符串而没有这样的引号:

public final class BuildConfig {
.....
// Fields from build type: debug
public static final String FACEBOOK_APP_ID = 99999999999999999;
public static final String PARSE_APP_ID = xxxxxxxxxxxxxxxxxxxxxxxx;
public static final String PARSE_CLIENT_ID = xxxxxxxxxxxxxxxxxxxxxxxxx;
}

显然这会给你带来编译错误,我试图在 stackoverflow 中找到如何解决这个问题,因为这会导致我的构建出现错误,但没有找到任何相关信息。如何让 gradle 正确打印带引号的字符串?

最佳答案

写完这篇文章后,我找到了方法,似乎值的打印方式与它们定义的方式相同,因此如果您向其中添加转义引号,它将起作用,例如:

buildTypes {
release {
minifyEnabled false
buildConfigField("String", "PARSE_APP_ID", '"xxxxxxxxxxxxxxxxxxxxxxxx"')
buildConfigField("String", "PARSE_CLIENT_ID", '"xxxxxxxxxxxxxxxxxxxxxxxxx"')
buildConfigField("String", "FACEBOOK_APP_ID", '"999999999999999"')
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

之后,重建,它将正确打印字符串值:

public final class BuildConfig {
....
// Fields from build type: debug
public static final String FACEBOOK_APP_ID = "999999999999999999";
public static final String PARSE_APP_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
public static final String PARSE_CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxxxxx";
}

关于Android BuildConfig 字段生成字符串不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35851487/

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