美文网首页Android
Android fix minSdkVersion and li

Android fix minSdkVersion and li

作者: JaedenKil | 来源:发表于2017-12-01 14:59 被阅读7次

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!

相关文章

网友评论

    本文标题:Android fix minSdkVersion and li

    本文链接:https://www.haomeiwen.com/subject/bjhwbxtx.html