Android Gradle how to custom sourceSet in library by product flavor?

Viewed 187

Here's my main project structure:

App/src
 - main
 - flavor1
 - flavor2
 - dimension1
 - dimension2
 - debug
 - release

Both flavor* and dimension* are flavor dimensions. The build variants are:

flavor1Dimension1Debug
flavor1Dimension2Debug
flavor2Dimension1Debug
...

And library's dir structure:

Lib/src
 - main
 - flavor2
  - DebugInterceptor.java
 - debug
  - DebugInterceptor.java
 - release
  - DebugInterceptor.java

What I want:

  • if variant contains 'flavor2', this variant should use src/flavor2/DebugInterceptor.java. It should take higher priority than build types. You can assume that these three dirs(flavor2, debug, release) contain only one file DebugInterceptor.java
  • o.w. merging by default build rules.

How can I configure gradle to achieve this?

1 Answers

use only one dimension and multiple flavor, don't use multiple dimension or remove code from dimension, dimension is not suitable for code but for other configs like api level

Related