title: Flavor specific code
body: <p>Consider an Activity <code>MainActivity</code> with a fragment <code>MainFragment</code>. The fragment has some complex layout hierarchy and a view group <code>Frame</code> which comes from a library <code>com.framer:frame_me:1.1</code>.</p>
  
  <p>If I have 2 flavours <code>foo</code> and <code>bar</code>, and I want this <code>Frame</code> to be there only in <code>bar</code> flavour and not in <code>foo</code>, the XML element java code <strong>and dependency</strong>. How should I do this?</p>
  
  <p>I can compile the dependency using</p>
  
  <pre><code>barCompile 'com.framer:frame_me:1.1'
  </code></pre>
  
  <p>But what about the fragment and its XML. I don't want to write 2 variations the fragment in both flavours because I don't want to maintain the same code in 2 places.</p>
  
  <hr>
  
  <p>One possible idea (probably a bad one) in my mind is that this:</p>
  
  <ol>
  <li>Move the XML element in a separate file in <code>bar</code> source set. Add <code>ViewStub</code> element in the <code>foo</code> source set with the same name. Now include this XML file using <code>include</code> in the fragment XML</li>
  <li>Add an interface to handle <code>Frame</code> view in <code>main</code> source set. Add an empty implementation in <code>foo</code> source set and one in <code>bar</code> source set. This way all logic can remain in <code>bar</code> while all common logic remains in <code>main</code> source set.</li>
  </ol>
  
  <p>This all sounds an awfully lot of work just to write flavour specific code and xml.</p>