title: Android: How to use lower minSdkVersion than declared in library (uiautomator-v18)
body: <p>I migrated an older Android app to Android-Studio/Gradle. The test need <code>uiautomator-v18</code> which requires <code>minSdkVersion=18</code>. However, I would like to have the <code>minSdkVersion</code> set to 15 or 16.</p>
  
  <p>There are many questions on SO over the same thing, but I am just not able to resolve this problem.</p>
  
  <p>Exerpt AndroidManifest.xml:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      package="com.example.searcher"
      android:versionCode="1"
      android:versionName="0.0.1" &gt;
  
      &lt;uses-sdk
          tools:overrideLibrary="android.support.test.uiautomator.v18"/&gt;
  
      &lt;!-- ... --&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The build.gradle:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 23
      buildToolsVersion "23.0.2"
  
      defaultConfig {
          applicationId "com.example.searcher"
          minSdkVersion 15
          targetSdkVersion 23
          testApplicationId "com.example.searcher.test"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
  }
  
  dependencies {
      compile 'com.android.support:appcompat-v7:23.2.0'
      compile 'com.google.android.gms:play-services-analytics:8.4.0'
      compile files('libs/dagger-1.2.1.jar')
      compile files('libs/dagger-compiler-1.2.1.jar')
      compile files('libs/javawriter-2.1.2.jar')
      compile files('libs/javax.inject.jar')
  
      androidTestCompile(
          'com.android.support:support-annotations:23.2.0',
          'com.android.support.test:runner:0.4.1',
          'com.android.support.test:rules:0.4.1',
          'com.android.support.test.uiautomator:uiautomator-v18:2.1.1',
          'org.hamcrest:hamcrest-library:1.3',
          'org.mockito:mockito-core:1.10.5',
          'junit:junit:4.12',
          'com.google.dexmaker:dexmaker:1.1',
          'com.google.dexmaker:dexmaker-mockito:1.1'
      )
  }
  </code></pre>
  
  <p>The above gives the error:</p>
  
  <pre><code>Error:Execution failed for task ':app:processDebugAndroidTestManifest'.
  &gt; java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 18 declared in library [com.android.support.test.uiautomator:uiautomator-v18:2.1.1] /mypath/app/build/intermediates/exploded-aar/com.android.support.test.uiautomator/uiautomator-v18/2.1.1/AndroidManifest.xml
      Suggestion: use tools:overrideLibrary="android.support.test.uiautomator.v18" to force usage
  </code></pre>
  
  <p>But I am already using the <code>overrideLibrary</code>. </p>
  
  <p>If this is not possible, is it possible to have different <code>minSdkVersion</code> for "main" and "androidTest"?</p>
  
  <p><strong>EDIT</strong>:
  After adding the flavors, I was able to run the tests using build variant <code>tstDebug</code>. However, building it with <code>prdDebug</code> ends in an error saying that there are unknown stuff in the androidTest (example: <code>package org.hamcrest does not exist</code>). The modified excerpt of <code>build.gradle</code>:</p>
  
  <pre><code>defaultConfig {
      applicationId "com.example.searcher"
      targetSdkVersion 23
      versionCode 6
      versionName "0.5.0"
  }
  
  productFlavors {
      prd {
          minSdkVersion 15
      }
      tst {
          minSdkVersion 18
          testApplicationId "com.example.searcher.test"
          testInstrumentationRunner "android.test.InstrumentationTestRunner"
      }
  }
  
  // And instead of "androidTestCompile" use "tstCompile"
  </code></pre>
  
  <p>Is it not possible to tell "Android Studio" that it should build the app without <code>androidTest</code>?</p>