title: How do I automatically increment the build id and version number of an Android App using Azure Pipelines
body: <p>This is my build.gradle</p>
  
  <pre><code>defaultConfig {
          applicationId "com.xyz.abc.na"
          minSdkVersion 16
          targetSdkVersion 29
          versionCode 36
          versionName "5.0.2"
          multiDexEnabled true
      }
  </code></pre>
  
  <p>In my YML, I have</p>
  
  <pre><code> - 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
  </code></pre>
  
  <p>Unless I manually change the <code>versionCode</code> and <code>versionName</code> in my build.gradle the values are never automatically updated. </p>
  
  <p>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?</p>
  
  <p>Below are the existing references that didn't work for me.</p>
  
  <p><a href="https://stackoverflow.com/questions/53735441/azure-pipeline-increment-build-number-and-display-in-web-app">Ref1</a></p>
  
  <p><a href="https://stackoverflow.com/questions/60206117/not-generate-android-apk-version-wise-using-devops-pipeline-after-changes-versio">Ref2</a></p>
  
  <p><a href="https://stackoverflow.com/questions/60206117/not-generate-android-apk-version-wise-using-devops-pipeline-after-changes-versio">Ref3</a></p>