Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get BuildConfig values from xml?

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?

like image 260
sirvon Avatar asked Feb 03 '15 18:02

sirvon


1 Answers

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.

like image 129
CommonsWare Avatar answered Oct 14 '22 03:10

CommonsWare