需要根据环境更改 strings.xml 文件中的值
need to change values in strings.xml file according to environment
我正在开发 android 应用程序。我需要为我的开发环境和生产环境使用两个 google 控制台项目。但是有一个 strings.xml 文件,我不能根据环境更改它们的字符串。谁能帮帮我?
如果您要求根据调试或发布 apk 更改字符串值。那么你应该把值放在 Gradle (build.gradle 模块)而不是像这样的 String.xml 值。
buildTypes {
release {
resValue("string", "id", "your production value here")
}
debug {
resValue("string", "id", "your development value here")
}
}
你可以在这样的代码中得到这个值。
context.getString(R.string.id);
这将在您在 Gradle 中添加值后重建项目后显示,因为这些是生成的编译时间。
我希望这对您有所帮助,请注意我的英语,因为它不是我的母语。
我正在开发 android 应用程序。我需要为我的开发环境和生产环境使用两个 google 控制台项目。但是有一个 strings.xml 文件,我不能根据环境更改它们的字符串。谁能帮帮我?
如果您要求根据调试或发布 apk 更改字符串值。那么你应该把值放在 Gradle (build.gradle 模块)而不是像这样的 String.xml 值。
buildTypes {
release {
resValue("string", "id", "your production value here")
}
debug {
resValue("string", "id", "your development value here")
}
}
你可以在这样的代码中得到这个值。
context.getString(R.string.id);
这将在您在 Gradle 中添加值后重建项目后显示,因为这些是生成的编译时间。
我希望这对您有所帮助,请注意我的英语,因为它不是我的母语。