This is my build.gradle
defaultConfig {
applicationId "com.xyz.abc.na"
minSdkVersion 16
targetSdkVersion 29
versionCode 36
versionName "5.0.2"
multiDexEnabled true
}
In my YML, I have
- task: android-manifest-version@1
displayName: 'Version Update'
inputs:
sourcePath: '$(manifestDirectory)'
versionCodeOption: 'buildid'
versionCode: '$(Build.BuildId)'
versionCodeOffset: '1'
printFile: true
- task: Gradle@2
displayName: 'Building Gradle'
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx3072m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: $(gradleTask)
codeCoverageToolOption: 'None'
javaHomeOption: 'JDKVersion'
jdkVersionOption: 'default'
jdkArchitectureOption: 'x64'
checkStyleRunAnalysis: false
findBugsRunAnalysis: false
Unless I manually change the versionCode
and versionName
in my build.gradle the values are never automatically updated.
How do I get the latest value, increment by 1 and update the build.gradle and then generate a build from the new version code and version name?
Below are the existing references that didn't work for me.
Ref1
Ref2
Ref3
to do it natively you can follow those steps:
gradle.properties
add those 2 propertiesappVersionCode=1
appVersionName="1.0"
build.gradle
Appreplace
versionCode 36
versionName "5.0.2"
with
versionCode appVersionCode.toInteger()
versionName appVersionName.toString()
options
and pass the $(MyAppBuildNumber)
and $(MyAppVersionNumber)
via variables- task: Gradle@2
inputs:
...
options: '-PappVersionCode=$(MyAppBuildNumber) -PappVersionName=$(MyAppVersionNumber)'
...
For those of you who can't install an extension, here's my PowerShell solution:
$BasePath = "$(Build.SourcesDirectory)\"
$BuildGradlePath = "${BasePath}[YourAppFolderStructure]\app\build.gradle"
$BuildGradleUpdatedPath = "${BasePath}[YourAppFolderStructure]\app\build.gradle.updated"
Get-Content $BuildGradlePath | ForEach-Object {
if($_ -match "versionCode \d"){
$versionCode = $_ -replace "versionCode", "" -as [int]
$newVersionCode = $versionCode + 1
Write-Host "Found versionCode ${versionCode}. Updated to ${newVersionCode}"
$_ = " versionCode " + $newVersionCode
}
elseif($_ -match "versionName"){
Write-Host "Updating versionName to $(Build.BuildNumber)"
$_ = " versionName '$(Build.BuildNumber)'"
}
$_
} | Set-Content $BuildGradleUpdatedPath;
Get-Content $BuildGradleUpdatedPath | Set-Content $BuildGradlePath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With