Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Gradle variant folders

SamYStudiO edited this page Mar 19, 2017 · 8 revisions

Each time you add a new variant in your build.gradle script (platform, build type or product flavor, you will be able to create a new corresponding folder under your src folder (platform variants are auto generated, so you won't have to do it manually). For example applying flair.android plugin adds src/android folder. These folders may contain any folder/file you may find under src/main folder but generated folder, this is useful when you need specific resources for your variant version. Here is a description on how Flair look up in different folders to find the right resources.

Note you may enabled build type and product flavor variant folders auto generation using autoGenerateVariantDirectories properties.

flair {
  autoGenerateVariantDirectories true
}

Considering the variant version androidFreeDogDebug, this can be split up as following:

  • platform: android
  • product flavors: free and dog
  • build type: debug

Flair will look up for resources in the following order:

  • src/android_free_dog_debug
  • src/android_debug
  • src/android_free_dog
  • src/android_dog
  • src/android_free
  • src/debug
  • src/dog
  • src/free
  • src/android
  • src/main

Notice how build types are the most priority then product flavors and finally platform. There is 2 cases to find resources, first to find the right one and second to process all and overwrite resources that have already been processed.


FIND THE RIGHT RESOURCE

This is the case with icons, splashs, signing folders and app descriptor xml. This means Flair will look up folders and once file or folder is found Flair will stop looking. For example if you added an icons folder under src/android_free_dog, src/free, src/android, Flair do as following:

  • look in src/android_free_dog_debug/icons > nothing check next
  • look in src/android_debug/icons > nothing check next
  • look in src/android_free_dog/icons > found the right icons, process it and stop looking (src/free and src/android are ignored)

PROCESS ALL RESOURCES

This is the case for all other resources, this means Flair will look through all variant folders. For example processing resources folders:

  • look in src/main/res > process resources
  • look in src/android/res > process resources overwriting if conflict name
  • look in src/free/res > process resources overwriting if conflict name
  • look in src/dog/res > process resources overwriting if conflict name
  • look in src/debug/res > process resources overwriting if conflict name
  • look in src/android_free/res > process resources overwriting if conflict name
  • look in src/android_dog/res > process resources overwriting if conflict name
  • look in src/android_free_dog/res > process resources overwriting if conflict name
  • look in src/android_debug/res > process resources overwriting if conflict name
  • look in src/android_free_dog_debug/res > process resources overwriting if conflict name

Special case with files under res/values, these files are not overwritten even if conflict names are detected. Indeed values xml files are actually merged into a unique file when processed. For example considering the following strings.xml file under src/main/res/values:

<resources>
  <string name="hello">Hello...</string>
  <string name="world">...World!</string>
  <string name="dog">dog</string>
</resources>

And adding a strings.xml under src/android/res/values:

<resources>
  <string name="world">...World Android!</string>
  <string name="cat">cat</string>
</resources>

will result as following:

<resources>
  <string name="hello">Hello...</string>
  <string name="world">...World Android!</string>
  <string name="dog">dog</string>
  <string name="cat">cat</string>
</resources>