If we need to add unit tests for an app, we may add this dependency in app\build.gradle
:
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
But it gives me an error:
Error:Execution failed for task ':demo:processNoExtensionsDebugAndroidTestManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 18 declared in library [com.android.support.test.uiautomator:uiautomator-v18:2.1.2] C:\Users\XXX\.android\build-cache\37eea5df41f6dc296d0d281f7127844b682e8f21\output\AndroidManifest.xml
Suggestion: use tools:overrideLibrary="android.support.test.uiautomator.v18" to force usage
So I did as told, as it suggests, add some code to src\main\AndroidManifest.xml
:
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="25" />
tools:overrideLibrary="android.support.test.uiautomator.v18"
/>
But anyway it still shows the error, which won't be fixed.
After some research on google, found the tricky part.
We actually need to add such code in src\androidTest\AndroidManifest.xml
.
So under src\androidTest
, just New - File
, and name it AndroidManifest.xml
.
And it should look like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:tools="http://schemas.android.com/tools"
package="com.google.android.exoplayer2.demo" >
<uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18" />
</manifest>
And it worked!
网友评论