As mentionned in the linked post, you can use flavors to include different dependencies, BUT you can also include specific src files in a flavor:
Create directories src/pro/java/ and src/free/java/ .
All source files in src/pro/java will be compiled only in the "pro" flavor using the dependencies defined for the "pro" flavor.
All source files in src/free/java will be compiled only in the "free" flavor using the dependencies defined for the "free" flavor.
Now assume that you have a java source file SomeClass.java calling some code in admob.jar. You can the the following :
- put
SomeClass.java in src/free/java/SomeClass.java
- duplicate
SomeClass.java in src/pro/java/SomeClass.java
- remove all calls to admob.jar from
src/pro/java/SomeClass.java
- if you did it properly : both flavors of your project should compile
Tip: try to organize your code in such a way that duplicated class are reduced to the strict minimum.