skywinder skywinder - 1 month ago 14
Android Question

How to read `minSdkVersion` in gradle?

I set

minSdkVersion
in flavor:

android {
buildTypes {
release {
}

debug {
debuggable true
}

productFlavors {
myFlavor {
minSdkVersion 19
}
}
}


Accroding this:

enter image description here

I want to build
versionCode
, that contains
minSdkVersion
in the
versionCode
:

applicationVariants.all { variant ->
// get the version code of each flavor
variant.mergedFlavor.versionCode = variant.versionCode * 100000 + minSdkVersion(?) * 1000 + defaultConfig.versionCode
}


How can I access to
minSdkVersion
in this script?

I tried:


  • variant.minSdkVersion

  • android.minSdkVersion

  • project.minSdkVersion

  • project.android.minSdkVersion



But have no luck.

Answer

What you need is:

applicationVariants.all { variant ->
    def api = variant.mergedFlavor.minSdkVersion.apiLevel
    ....
}
Comments