Android Free/Paid Versions Tutorial

There are situations when you might decide that you need to create 2 versions for your application: a free one and a paid one. So, in this tutorial, which is just a simple example (we will just set different colors for the 2 versions), we will see how to achieve this using flavors. Your project is certainly more complex, but I think that this tutorial will be ok for you to get the main idea of how you can do this.

Create Flavors

First of all, you have to add 2 flavors: free and the build.gradle file which is located inside app folder (to not be confused with the build.gradle of your application which is outside of the app folder). Below is the code:

  1. build.gradle (from app module diferctory)
apply plugin: ''

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner ""

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

    productFlavors {
        free {
            applicationId ""
            versionName "1.0-free"
            // this boolean can be accessed in java classes by using BuildConfig class
            // and now you can identify if your app is the paid version or not
            buildConfigField "boolean", "PAID_VERSION", "false"

        paid {
            applicationId "com.example.myapp.paid"
            versionName "1.0-paid"
            buildConfigField "boolean", "PAID_VERSION", "true"

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ''
    compile ''
    testCompile 'junit:junit:4.12'
    androidTestCompile ''
    androidTestCompile ''
    androidTestCompile ''

Configure Project Structure

Now, that we configured our 2 flavors we should create new folders (directories) in our project structure which map these 2 flavors. You can see how to do this in this tutorial. The project structure should look like this in the end:

free paid structure


NOTE: Notice that in order to identify later in our code if we use the free or paid version for enabling/disabling features, we have to add a custom flag in gradle using buildConfigField property. This custom flag “PAID_VERSION” will be available in BuildConfig class.

Below is the code used for using different colors for free and paid version.

  1. src – free – res – values – colors.xml
<?xml version="1.0" encoding="utf-8"?>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#9f3032</color>
    <color name="colorAccent">#FF4081</color>
  1. src – paid- res – values – colors.xml
<?xml version="1.0" encoding="utf-8"?>
    <color name="colorPrimary">#3fb592</color>
    <color name="colorPrimaryDark">#369f30</color>
    <color name="colorAccent">#FF4081</color>

Flavors Usage

And below is the code for or example application, where we have just one text view and a MainActivity.

  1. activity_main.xml (from main directory)
<?xml version="1.0" encoding="utf-8"?>
< xmlns:android=""

        app:layout_constraintTop_toTopOf="@+id/activity_main" />

package com.example.diana.freepaidapplication;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        TextView textView = (TextView) findViewById(;

        if (BuildConfig.PAID_VERSION) {// this is the flag configured in build.gradle
            textView.setText("Is Paid Version");
        } else {
            textView.setText("Is Free Version");

Now, in order to run your app in free version, you just have to select the freeDebug variant, from Build Variants which is located in the bottom-left of Android Studio:

free debug

And the result will be this:

free version

Do the same for the paid version. The result should be this after you run the app:

paid version

You can also check the tutorial on GitHub here.

Exit mobile version