2

I'd like to increase the minSdk to 21 just for androidTest. Is this possible without introducing a product flavor?

Note: Using Android Gradle Plugin 3.0, and my app's minSdk needs to be 16.

ZakTaccardi
  • 12,212
  • 15
  • 59
  • 107

2 Answers2

0

You can try as this post suggests creating a new Manifest in the folder where you run your test adding the attribute

uses-sdk

as per documentation

Also is indicated to play in gradle with some if statements in the gradle file, but they are ugly. Anyway you could use it as a plan B solution:

if (gradle.startParameter.taskNames.contains(":app:assembleDebug")) {
        minSdkVersion 21
    }else{
        minSdkVersion 14
    }
trocchietto
  • 2,607
  • 2
  • 23
  • 36
-1

You can add the minSdk in either the projects gradle file or manifest. When adding the minSdk it means that you are specifying the minimum sdk level that you have designed and tested your app. You also would want to add the targetSdk. A google support link which may interest you https://developer.android.com/training/basics/supporting-devices/platforms.html

In the manifest it would look like

<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" /> ... </manifest>

In your gradle file

defaultConfig {
    applicationId "com.project.projectName"
    minSdkVersion 14
    targetSdkVersion 21
}
BigApeWhat
  • 321
  • 3
  • 15
  • `minSdk` needs to be `16`. I want to multidex for `androidTest`, so I need to `minSdk = 21` - but for `androidTest only – ZakTaccardi Nov 13 '17 at 22:40
  • You cannot add a minSdk only for testing, you give it for the whole project including tests. On top of that you can multidex prior to 21 – BigApeWhat Nov 13 '17 at 23:11
  • you cannot multidex your test apk. just your app apk – ZakTaccardi Nov 13 '17 at 23:29
  • Your asking the wrong questions and moving in the wrong direction. If you know that you cannot use multidex in test apk why are you trying to add multidex for your tests? I dont really care, either way you cannot have a different minSdk on your tests than your app. It seems like your facing a different problem and your trying to find a solution in the wrong area. – BigApeWhat Nov 13 '17 at 23:45
  • the methods from your main apk do not count against the methods in your test apk. your main apk can multidex, but not a test apk (`androidTest`). – ZakTaccardi Nov 13 '17 at 23:47
  • What is the problem you are really having cause i dont understand what you are trying to accomplish with having different minSdk versions. And by "test apk" do you mean a debug build? – BigApeWhat Nov 13 '17 at 23:50
  • I mean the androidTest apk (for espresso tests) https://stackoverflow.com/questions/47269314/how-can-i-list-which-dependencies-count-against-the-dex-limit-for-an-androidtest – ZakTaccardi Nov 13 '17 at 23:51
  • Ok i think what you need is, @SdkSuppress(minSdkVersion = 18) above the class test? – BigApeWhat Nov 13 '17 at 23:53
  • no. my build is failing because I need to multidex my test apk. – ZakTaccardi Nov 13 '17 at 23:55
  • are you trying to extend a custom application class? Gradle should also have "testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"" Update the question cause its not a "how to set minSdk for tests" but rather "why are my tests not working" – BigApeWhat Nov 13 '17 at 23:59