Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Flavors : Multiple java and src directories for each flavor

Can anyone explain to me how I can use for each of my flavors more then just the main and the flavor specific java/src directories ? My goal is to have directories which are used by more than one flavor but not all of them.

For example I have 3 flavors : A1, A2 and B.

  • All favors use main/src (default main src directory)
  • A1 uses A1/src (default flavor src directory)
  • A2 uses A2/src (default flavor src directory)
  • B uses B/src (default flavor src directory)
  • A1 and A2 use A/src ("special" shared directory)

Is this possible ? If so, what should I put in my build.gradle file ?

And as a bonus question, can I chose in which order gradle goes looking for files in my different directories ?

For example if I have a.png declared in both A/src and A1/src, can I tell gradle to first look for this file in A/src, and only if nothing is found look for it in A1/src ?

like image 794
Pâris Jean-christophe Avatar asked Sep 02 '15 15:09

Pâris Jean-christophe


People also ask

What are buildTypes and product Flavours in Gradle and what can you use them for?

Build Variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Build Type applies different build and packaging settings. An example of build types are “Debug” and “Release”.

What is Productflavors Android?

Product flavours lets you create multiple variants of an android app while using a single codebase. To create product flavours you need to define rules in the build.

What is Productflavors?

LibraryProductFlavor. TestProductFlavor. Encapsulates all product flavors properties for this project. Product flavors represent different versions of your project that you expect to co-exist on a single device, the Google Play store, or repository.

What is missingDimensionStrategy?

missingDimensionStrategy(dimension, requestedValues) Specifies a sorted list of flavors that the plugin should try to use from a given dimension in a dependency. proguardFile(proguardFile) Specifies a ProGuard configuration file that the plugin should use. proguardFiles(files)


1 Answers

As described here

As mentioned above, each sourceSet can define multiple resource folders.

You can define multiple resource folder. For example something like this:

android {
     ...
     sourceSets {
            main {
                //....
                res.srcDirs = ['/src/main/res']

            }
            flavorA1 {
                 res.srcDirs = ['/src/flavor1/res', '/src/commonA/res']
            }
            flavorA2 {
                 res.srcDirs = ['/src/flavor2/res', '/src/commonA/res']
            }     
            //.....other flavors   
     }
}
like image 182
Gabriele Mariotti Avatar answered Sep 19 '22 00:09

Gabriele Mariotti