Mar*_*fer 7 resources android build
假设我们有strings_test.xml,它存储用于测试的字符串值,应该在调试版本中显示.当apk构建为发布版本时,所有值都应该更改为空字符串,例如<string name="test_some_card_text">@string/empty</string>.
是否有可能实现这一目标?
一如既往,先谢谢.
Mad*_*bar 17
是的,您可以在buildTypes下的app gradle中执行此操作.
buildTypes {
mybuild {
resValue "string", "test_some_card_text", '"test"'
resValue "string", "other_text", '"other"'
}
debug {
resValue "string", "test_some_card_text", '"test"'
resValue "string", "other_text", '"other"'
}
}
Run Code Online (Sandbox Code Playgroud)
然后像这样访问它.
getApplicationContext().getResources().getString(R.string.test_some_card_text);
getApplicationContext().getResources().getString(R.string.other_text);
Run Code Online (Sandbox Code Playgroud)
对于构建,您需要选择它build variants并且必须构建它.