dheeraj
dheeraj

Reputation: 305

Adding dependency only to specific flavour - Android Studio

My project has a free and paid version,

Free version uses Admob service but paid version does not have any ad. How can i remove the dependency for paid version

This is my build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.udacity.gradle.builditbigger"
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testApplicationId"com.udacity.gradle.builditbigger.tests"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors{
        free{
            applicationId"com.udacity.gradle.builditbigger.flavours.free"
        }
        paid{

            applicationId"com.udacity.gradle.builditbigger.flavours.paid"
        }


    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // Added for AdMob

    compile project(':mylibrary')
    compile project(path: ':endpoint-backend', configuration: 'android-endpoints')
    compile 'com.android.support:appcompat-v7:22.2.0'


        compile 'com.google.android.gms:play-services:7.5.0'


}

I want the dependency compile 'com.google.android.gms:play-services:7.5.0' only for free version but not for the paid version .

Upvotes: 2

Views: 1319

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363439

To add different dependencies to different build types or flavors you can use this

dependencies {
    releaseCompile 
    debugCompile 
    flavor1Compile 
    flavor1DebugCompile 
}

In your case:

 dependencies {
     freeCompile 'com.google.android.gms:play-services:7.5.0'
 }

Also, if you need olny Admob, you should use this dependency instead of full play-services.

   compile 'com.google.android.gms:play-services-ads:7.8.0'

Upvotes: 9

Related Questions