4

I have an android studio project with minSdkVersion set to 14 in both AndroidManifest.xml and in build.gradle

Now I want to write some automated tests so I added some more dependences in build.gradle. One of them is: androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'

When I try to run the tests I get:

Error:(5, 5) uses-sdk:minSdkVersion 14 cannot be smaller than version 18 declared in library com.android.support.test.uiautomator/uiautomator-v18/2.1.1/AndroidManifest.xml

Error:Execution failed for task ':app:processDebugTestManifest'. java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 18 declared in library 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 changed my manifest file to: , but this didn't help.

If I change build.gradle to minSdkVersion 18, then it works. But I don't want to change the minSdkVersion of my app just because of the test libraries.

Is there a way to configure build.gradle to use minSdkVersion 18 when I run the automated tests, but keep minSdkVersion 14 for the app?

1 Answer 1

2

Here is how I did it:

  1. Create two flavours:
    • appConfig : it is empty so it inherits all from defaultConfig
    • testConfig : it declares minSdkVersion 18.
  2. Add the dependency for uiautomator for the testConfig only.

Below is the excerpt from my build.gradle

defaultConfig {
        applicationId "..."
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    productFlavors {
        appConfig {
        }
        testConfig {
            minSdkVersion 18
            testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
        }
    }
}

dependencies {
...
    testConfigCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
Sign up to request clarification or add additional context in comments.

1 Comment

Did not work for me. Still showing error when appConfigDebug is chosen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.