I have a xml file. In the xml file I want to get a BuildConfig value. BuildConfig value is set in build.gradle.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="com_my_api_key">**REPLACE_WITH_YOUR_API_KEY**</string>
</resources>
I want to get that api Key from buildConfig, similar to how I get those values in the java code.
public class MyApp extends Application{
public String APPTIMIZE_KEY = BuildConfig.APPTIMIZE_KEY;
}
Here is the value being set in build.gradle, its coming from an external file.
release {
buildConfigField "boolean", "APP_DEBUG", "false"
buildConfigField "String", "APPTIMIZE_KEY", "\"${props.getProperty("apptimizeKey_App1")}\""
How do i reference this ---> BuildConfig.APPTIMIZE_KEY in the xml file to get it?
There is a lightly documented resValue
counterpart to buildConfigField
. I haven't tried it yet, but something along the lines of this would be where I would start:
resValue "string", "com_my_api_key", "\"${props.getProperty("apptimizeKey_App1")}\""
This would go alongside your existing buildConfigField
, if you need/want that value to also be accessible from BuildConfig
. You would no longer need to manually declare the string resource, but instead it would be generated for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With