title: Using flavours in Android studio and - error with wrong AndroidManifest selected / not merged
body: <p>I am trying to set up flavours, so I can build different apps in he same project that share the same code... But I am not sure I am doing it fully correct...</p>
  
  <p>I have created a project called com.sharedid.app in folder W:\android-studio-projects\sharedid\</p>
  
  <p><strong>For this I have</strong></p>
  
  <p>1) 
  Created AndroidManifest.xml in W:\android-studio-projects\sharedid\app\src\main looking like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sharedid.app"
    android:versionCode="1"
    android:versionName="1.0"
  &gt;
  &lt;activity android:name="com.shared.app.SharedMain" android:label="@string/MicMainName" &gt;
    &lt;intent-filter&gt;
      &lt;action android:name="android.intent.action.MAIN" /&gt;
      &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
    &lt;/intent-filter&gt;
  &lt;/activity&gt;  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>2) In
  <em>W:\android-studio-projects\sharedid\app\src\main\java</em> ... I have all .java files</p>
  
  <p>3) In
  <em>W:\android-studio-projects\sharedid\app\src\main\res</em> I have all shared and/or dummy resources</p>
  
  <p><strong>For my flavour</strong> I have:</p>
  
  <p>1) I have created AndroidManifest.xml in W:\android-studio-projects\sharedid\app\src\myflavour (this file is what defines everything - it is unqiue for each flavour)</p>
  
  <p>2) In
  <em>W:\android-studio-projects\sharedid\app\src\myflavour\res</em> I have a single folder <em>drawable-hdpi</em> conttaining variois graphics</p>
  
  <p>3) In
  <em>W:\android-studio-projects\sharedid\app\src\myflavour\assets</em> I have all sorts of data, configuration and graphic files for <strong>that</strong> specifc app. (read by the code at runtime)</p>
  
  <p>4)
  In *W:\android-studio-projects\sharedid\app\src\myfavlour* I have the following <em>AndroidManifest.xml</em> file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myflavour.app"
    android:versionCode="2"
    android:versionName="2.0"
  &gt;
  &lt;uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="17" 
  /&gt;
    &lt;uses-feature android:glEsVersion="0x00020000" android:required="true" /&gt;
  
  &lt;application
    android:allowBackup="true"
    android:icon="@drawable/app_logo__forlarge"
    android:label="@string/MicAppName"
    android:theme="@style/MicTheme_myflavour"
    android:name="com.shared.app.MicApp"
  &gt;
  &lt;provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="com.myflavour.app.fileprovider"
    android:grantUriPermissions="true"
    android:exported="false"&gt;
    &lt;meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_filepaths" /&gt;
  &lt;/provider&gt;
  &lt;activity android:name="com.shared.app.SharedMain" android:label="@string/MicMainName" &gt;
    &lt;intent-filter&gt;
      &lt;action android:name="android.intent.action.MAIN" /&gt;
      &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
    &lt;/intent-filter&gt;
  &lt;/activity&gt;        
  &lt;activity&gt;...more...&lt;/activity&gt;        
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Here's how "Gradle Scripts" - "Build Gradle" (Module: app) looks like:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      signingConfigs {
      }
      compileSdkVersion 21
      buildToolsVersion '21.1.2'
      defaultConfig {
          applicationId "com.sharedid.app"
          minSdkVersion 9
          targetSdkVersion 17
      }
      buildTypes {
          release {
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
          }
      }
      repositories {
          maven { url "https://jitpack.io" }
      }     
      productFlavors {
        myflavour {
            applicationId "com.myflavour.app"
        }
      }
      sourceSets {
        main {
          manifest.srcFile 'src/main/AndroidManifest.xml'
        }
        myflavour {
          manifest.srcFile 'src/myflavour/AndroidManifest.xml'
        }
      }           
  }    
  dependencies {
      compile 'com.android.support:support-v4:18.0.0'
      compile 'com.google.android.gms:play-services:+'
      compile 'com.android.support:appcompat-v7:21.1.2'
      compile 'com.github.PhilJay:MPAndroidChart:v2.0.8'
  }
  </code></pre>
  
  <p><strong>My problem is this</strong></p>
  
  <p>When I in "build variants" select "module=app" and "build-variant=com.myflavour.appDebug" and click "Run > Debug..." I get a dialog that states: <em>"Error: Default activity not found"</em></p>
  
  <p>From my studies of flavours I should not need to define sourcesets paths since I use the default <strong>conventenion</strong> of files for flavours... If I am right abnout that - then why does it not see the Androidmanifest file for the flavour selected?</p>
  
  <p>Links for reference I base my understanding on:</p>
  
  <ul>
  <li><a href="https://developer.android.com/tools/building/manifest-merge.html" rel="noreferrer">https://developer.android.com/tools/building/manifest-merge.html</a></li>
  <li><a href="https://stackoverflow.com/questions/19461145/gradle-flavors-for-android-with-custom-source-sets-what-should-the-gradle-file">Gradle flavors for android with custom source sets - what should the gradle files look like?</a></li>
  </ul>
  
  <p><strong>Additional troubleshooting</strong></p>
  
  <p>In my attempt to find the root of this problem, I begun to suspect manifest merging was not working. The reason for this suspicion was that if I ignored the error about no activity and tried to push the compiled app out on the mobile, I would get a warning about the version number being smaller than the one installed on the mobile - clear indication wrong manifest file was being used.</p>
  
  <p>So i have also tried to delete <em>src/main/AndroidManifest.xml</em> which results in error: </p>
  
  <blockquote>
    <p>A problem was found with the configuration of task
    ':app:checkmyflavourDebugManifest'. File
    W:\android-studio-projects\sharedid\src\main\AndroidManifest.xml'
    specified for property 'manifest' does not exist</p>
  </blockquote>
  
  <p>This leads me to believe Android Studio is completely ignoring that I am actually specifying it to use another manifest file... And the same time though it would seem i an building the correct variation build.</p>
  
  <p>I would apreciate any comment/analysis on this - even if just to confirm my thinking of the cause</p>
  
  <p><strong>Screenshot of my current setup</strong></p>
  
  <p>(in this screenshot I have experiemented deleting main/shared androidmanifest file, but otherwise it complete)</p>
  
  <p><strong>Latest update</strong></p>
  
  <p>I conclude flavors is not working / my gradle setup must be wrong.  If I e.g. select building variation myflavourDebug Android studio does not use the manifest file defined in gradle. This alone should be enough to conclude where the problem relies.</p>
  
  <p>Maybe my gradle file is wrong somehow, I don't know, but I have taken great care in getting i right. If someone posts an asnwer while bounty is active I will try hurry and assign it.</p>
  
  <p><a href="https://i.stack.imgur.com/ugXA0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ugXA0.png" alt=""></a></p>