Search code examples
androidandroid-studioandroid-gradle-pluginandroid-productflavors

android: gradle product flavors messing up minSdkVersion


I've an Android app which min sdk level is 15, but from 15 to 18 i need to import extra libraries in order to make it work.

To do that i'm using "flavor" on gradle build file as the following snippet

   minSdkVersion 15
    targetSdkVersion 27
    versionCode 124
    versionName "3.4.2"
    multiDexEnabled true
    flavorDimensions "api"
    productFlavors {
        older {
            dimension "api"
            minSdkVersion 15
            maxSdkVersion 18
            versionCode 1 + android.defaultConfig.versionCode

        }
        newer {
            dimension "api"
            minSdkVersion 19
            versionCode android.defaultConfig.versionCode
        }
    }

the thing is after adding this flavor feature Android Studio doesn't allow me to run it on emulator sdk level 15 - 18.

enter image description here

but prior before it worked fine, i just splited the 2 flavors because the "extra api" needed to make the app works in older versions makes it grows twice the size, so i wanted the newer smartphones to avoid this extra overhead

how can i keep the two flavors building and still run on emulators ?


Solution

  • Go to

    Build -> Select Build Variant...

    A window that looks something like this should appear in the left sidebar:

    enter image description here

    Use the dropdown to select the older flavor. Use the button in the top right of that window to close it and then try running it again.