Skip to content

mahi05/FlavoursDemo

Repository files navigation

Product Flavors


.
├── 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 for product flavors


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
}

Generated tasks

Build variants provide tasks as combination of build types and product flavors. For Example :-

  • freeDebug: Debug build for flavor Free
  • freeRelease: Release build for flavor Free
  • proDebug: Debug build for flavor Pro
  • proRelease: Release build for flavor Pro

About

Product Flavors

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages