21

im trying to use UI Automator in my project with minSdkVersion 9 and of course it not work because it target API 18.

So Android Studio throws me this error:

Error:(5, 5) uses-sdk:minSdkVersion 9 cannot be smaller than version 18 declared in library ~/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

Error:Execution failed for task ':app:processDebugAndroidTestManifest'.
> java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 9 cannot be smaller than version 18 declared in library ~/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

I added to my Manifest the tag <uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18" /> but the error keep showing, i am doing something wrong?

rafael
  • 732
  • 1
  • 11
  • 20

3 Answers3

42

If you use gradle you can add another Manifest to the androidTest build type which will get merged and does not affect your normal release / debug builds.

Add app/src/androidTest/AndroidManifest.xml to your project:

<manifest
    package="${applicationId}.test"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

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

This will merge the manifest with your normal one, not requiring to change your minSdk. PLease note, that this will probably crash if you try running UI Instrumentation Tests on sdk < 18.

By adding additional permissions to the debug/AndroidManifest you can also just add permissions for your tests like external storage if you don't regularly need them in your app. They will although be also available to your debug builds.

David Medenjak
  • 33,993
  • 14
  • 106
  • 134
2

This worked for me

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="${applicationId}.test">

<uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator" />

Morteza Rastgoo
  • 6,772
  • 7
  • 40
  • 61
0

You need to build your app with minSdkVersion 18, however you can still switch to espresso.