11

I am creating an application that should have two flavors, netball and football. When I set up my project as per https://developer.android.com/tools/building/configuring-gradle.html only one of the flavors are being recognized i.e netball and other flavor's package i.e football is not.

image 1

image2

This is my build.gradle file

apply plugin: 'com.android.application'

 android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "net.brawtasports.brawtasportsgps"
    minSdkVersion 11
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

productFlavors {
    netball {
        applicationId "net.brawtasports.brawtasportsgps.netball"
        versionName "1.0"
    }

    football {
        applicationId "net.brawtasports.brawtasportsgps.football"
        versionName "1.0"
    }

}

sourceSets {
    main {
        java.srcDirs = ['src/main/java']
        res.srcDirs = ['src/main/res']
    }
    football {
        java.srcDirs = ['src/football/java']
        res.srcDirs = ['src/football/res']
    }
    netball {
        java.srcDirs = ['src/netball/java']
        res.srcDirs = ['src/netball/res']
    }

  }

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.vstechlab.easyfonts:easyfonts:1.0.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}

I realize that is is only recognizing the first item in productFlavors i.e netball. if I place football first it will recognize football and not netball. What is wrong?????

Castell James
  • 329
  • 6
  • 23

1 Answers1

23

You also need to select your current flavour on the panel Build variants to the left of the IDE window.

AndroidEx
  • 15,524
  • 9
  • 54
  • 50
  • is it necessary to also the sourceSet for main? or is it optional? – Castell James Jul 13 '15 at 04:51
  • 1
    @CastellJames if you use default locations for flavour files (as in your case) then you don't need `sourceSets` altogether, AS normally will find them. If you move any of your flavour's files to a non-default location, then you'll need to set this new location. – AndroidEx Jul 13 '15 at 12:11