.
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
├── free
│ └── java <--- Source code for "free" product flavor
├── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── res
└── pro
└── java <--- Source code for "paid" product flavor
-
To start with the flavors, we need to declare different flavors at app level build.gradle file inside android block.
i.e. :-
productFlavors { free { applicationId "yourpackagename.free" } paid { applicationId "yourpackagename.paid" } }
- Now go to src directory of the project and create folders with the name of flavors. i.e. free, paid.
- Create folders with the names of java and res inside newly created flavor folders.
- Add package with the same package name of project inside java directory of both flavors.
- Create a java class with the name of "Constants.java" in both flavors.
- Add a static string with the different url of different flavors.
i.e. :-
1. http://www.example.com/FreeApi 2. http://www.example.com/PaidApi
- Now use this apis in different falavors.
dependencies {
compile 'com.android.support:multidex:1.0.1' <--- Dependency for regular source code
proCompile 'com.android.support:multidex:1.0.1' <--- Dependency for product flavor
}
Build variants provide tasks as combination of build types and product flavors. For Example :-
freeDebug
: Debug build for flavor FreefreeRelease
: Release build for flavor FreeproDebug
: Debug build for flavor ProproRelease
: Release build for flavor Pro