ResValue definition using an existing string definition

I am interested in defining my many tastes of my applications, moreover, in the strings.xml files, and not in build.gradle. Given several options, I would like to simplify the release / debug option:

buildTypes { release { signingConfig signingConfigs.release resValue "string", "app_name", "@string/prod_name" } debug { applicationIdSuffix ".beta" resValue "string", "app_name", "@string/beta_name" } 

Then, in each of my custom res / values ​​/strings.xml build files, I define each my own prod_name and beta_name. I also want to use this similar structure to determine vendor authority, etc.

Currently, it will work just fine using the gradle command line, but cannot be recognized by Android Studio.

Android Studio Error:

I find this in the generate.xml file

 <!-- Values from build type: debug --> <string name="app_name">@string/beta_name</string> 

This is typical of how one line refers to another. But this time Android Studio gives me this error:

 Error:(7, 29) No resource found that matches the given name (at 'app_name' with value '@string/beta_name'). 

I am using Android Studio 2.1 Preview 5

+6
source share
2 answers

In my experience, you cannot enable @string/my_string in DSL resValue . Gradle put the value as a simple line in the resource file.

In this case, to achieve this, you can use a different folder:

Just use:

 src/release/res/values/strings.xml src/debug/res/values/strings.xml 

If you want to use a different resource for each build option (build type + flavor), you can use:

 src/flavor1Release/res/values/strings.xml src/flavor1Debug/res/values/strings.xml src/flavor2Release/res/values/strings.xml src/flavor2Debug/res/values/strings.xml 
+4
source

It is really possible. All you have to do is declare these lines empty in defaultConfig, for example:

 defaultConfig { resValue "string", "prod_name", "" resValue "string", "beta_name", "" } 
+2
source

All Articles