Skip to content Skip to sidebar Skip to footer

How To Access Versioncode From Task In Gradle Experimental Plugin

I would like to access versionCode and versionName in defaultConfig from a gradle task. I am using the experimental gradle plugin. I tried model.android.defaultConfig.versionCode b

Solution 1:

Create method in your build.gradle:

defgetVersionCode= { ->
    // calculate versionCode code or use hardcoded valuereturn1
}

Use this method in defaultConfig:

android {
    defaultConfig {
        versionCode getVersionCode()
    }
}

Use the same method in your custom task:

task printVersions{
    print"Version code is " + getVersionCode()
}

Alternative solution is to access versionCode property directly:

task printVersions{
    print"Version code is $project.android.defaultConfig.versionCode"
}

Solution 2:

Create method in your build.gradle:

defgetVersionCode= { ->
      return1
  }

Use this method in defaultConfig:

android {
  defaultConfig {
    versionCode getVersionCode()
  }
}

versionCode property can get like:

task printVersions{
  print"Version code is ${project.android.defaultConfig.versionCode}"
}

Post a Comment for "How To Access Versioncode From Task In Gradle Experimental Plugin"