Set different minSdkVersion for testAndroid than for main app

Code-Apprentice picture Code-Apprentice · Jun 2, 2015 · Viewed 12.8k times · Source

Is it possible to set a different minSdkVersion for tests than for the app itself? I ask because I want to use the new Test Support Library and UI Automator for testing. However, this is only available on API 18+. At the same time, I still want to support older versions of Android, albeit not as thoroughly tested. What do I need to add to my build.gradle file in order to do this?

To clarify, I am using Android Studio and the "new" Gradle-based project structure.

Answer

theblang picture theblang · Aug 7, 2015

I got this from the new testing template from Google.

Create a new AndroidManifest.xml file in your test or androidTest folder.

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:tools="http://schemas.android.com/tools"
    package="your.package.name">

    <uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18"/>
</manifest>