Resource Variants¶
Resource variant enables you to provide alternative resource among different build configuration. You can add or override some resource files by using this feature.
This is a typical NeoMAD project structure without resource variants:
MyProject/
src/
com/
company/
application/
MyApplication.java
MyScreen.java
assets/
my_asset_file.txt
res/
icon/
icon-48.png
image/
graphic.png
layout/
main.xml
info.xml
values/
strings-en.xml
Providing resource variants¶
Variants bring the developer two use cases:
- Override the content of an already existing resource.
- Provide a new resource.
To add a variant to your application:
- Create a
res-your_variant_name
folder in the project root folder. - Insert some files in this folder. The folder needs to respect the same conventions as the
res
folder: subfolders and subfiles names should be respected (raw, values, layout, etc).
Note
When having a single res folder, all the required resources (see Resource requirements) must be in the folder. When using variants, there is no constraint as to where to position the required resources. The required resources do not need to be in each folder separately, but must be present in the union of the different variant folders and the res folder.
This is an example of a variant’s structure:
res-variant1/
layout/
info.xml
values/
strings-en.xml
Declare variant in the URS¶
NeoMAD needs to know which variant to use during the build and where the files to embed are located.
<res>
<variant path="res-variant1"/>
</res>
Enable or disable the variant appliance¶
You may need to enable or disable some variant according to some conditions.
<res>
<variant path="res-variant1" condition="MY_CONDITION"/>
</res>
The MY_CONDITION condition can then be defined in the Constants.java file.
public static boolean MY_CONDITION = false;
Finally, this condition can be toggled by the code or by the command line with the -D option.
See the Conditioning section in the user guide forme more details.