title: How to setup flavors for android gradle project? Mysterious duplicate class error
body: <p>I have created simple test project: the goal is to show the message 'hello' by pressing a button on the screen. The first flavor build should write the message to the system log. The second flavor build should show a toast with message. How can this be achieved using gradle please?</p>
  
  <p>My build.gradle:</p>
  
  <pre><code>apply plugin: 'android'
  
  android {
  compileSdkVersion 19
  buildToolsVersion "19.0.1"
  
  defaultConfig {
      minSdkVersion 14
      targetSdkVersion 19
      versionCode 1
      versionName "1.0"
  }
  
  compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_7
      targetCompatibility JavaVersion.VERSION_1_7
  }
  
  productFlavors {
      toast {
  
      }
      log {
  
      }
  }
  
  sourceSets {
  
      main {
          java.srcDirs = ['src/main/java', 'src/log/java']
      }
  
      toast {
          java.srcDirs = ['src/main/java', 'src/toast/java']
      }
  }
  
  buildTypes {
      release {
          runProguard false
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
          }
      }
  }
  
  dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
  }
  </code></pre>
  
  <p>File structure:
  <img src="https://i.stack.imgur.com/pMFP5.png" alt="File structure"></p>
  
  <p>Flavor <code>log</code> contains single class Messenger with method <code>showMessage(Context context, CharSequence text)</code> and prints text using <code>Log.i(tag, msg)</code></p>
  
  <p>Flavor <code>toast</code> contains single class Messenger with method <code>showMessage(Context context, CharSequence text)</code> and shows toast with some text.</p>
  
  <p>Main sources don't contain this class.</p>
  
  <p>Why does the error <code>duplicate class:com.test.flavortest.Messenger</code> appear? Each flavor has a set of different non-crossing source paths? </p>
  
  <p><a href="https://drive.google.com/file/d/0B5KouoPaI5qqaWFjaWRiaWJLcm8/edit?usp=sharing" rel="nofollow noreferrer">Full sample project, zipped</a></p>