如何在gradle中阅读`minSdkVersion`?

时间:2016-10-14 12:40:57

标签: android gradle android-gradle versioning

我将minSdkVersion设置为风味:

android {
 buildTypes {
    release {
    }

    debug {
        debuggable true
    }

    productFlavors {
            myFlavor {
                minSdkVersion 19
            }
        }
}

记录:

enter image description here

我想在versionCode中构建包含minSdkVersion的{​​{1}}:

versionCode

如何在此脚本中访问 applicationVariants.all { variant -> // get the version code of each flavor variant.mergedFlavor.versionCode = variant.versionCode * 100000 + minSdkVersion(?) * 1000 + defaultConfig.versionCode }

我试过了:

  • minSdkVersion
  • variant.minSdkVersion
  • android.minSdkVersion
  • project.minSdkVersion

但没有运气。

1 个答案:

答案 0 :(得分:4)

您需要的是:

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