androidazure-devopsazure-pipelines

Azure Devops Pipeline GooglePlayRelease@4 Failed with message: GaxiosError: Version code 1 has already been used


My auto-generated versionCode is actually 2343, not 1.

Im trying to release an android app via Azure Pipelines, but their GooglePlayRelease@4 task keeps throwing an error, saying I have already used version code 1. Thi is despite the fact that I dont set a static versioncode, but derive it from number of git commits:

def getVersionCode = { ->
    "git rev-list --count HEAD"
            .execute()
            .text.trim()
            .toInteger()
}

defaultConfig {
        applicationId 'com.my_app.app'
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode getVersionCode() // here, should be 2343
        versionName getVersionName()
    }

Here's the task. I believe the problem could be during the signing task:

    - task: AndroidSigning@3
      inputs:
        apkFiles: '$(Agent.BuildDirectory)/s/android/app/build/outputs/bundle/productionRelease/app-production-release.aab'
        apksignerArguments: "--min-sdk-version 23"
        apksignerKeystoreFile: 'my-app.keystore'
        apksignerKeystorePassword: $(storePassword)
        apksignerKeystoreAlias: $(keyAlias)
        apksignerKeyPassword: $(keyPassword)
    
    - task: GooglePlayRelease@4
      inputs:
        serviceConnection: 'Google Play Store Connection'
        applicationId: 'com.my_app.app'
        action: 'SingleBundle'
        bundleFile: '$(Agent.BuildDirectory)/s/android/app/build/outputs/bundle/productionRelease/app-production-release.aab'
        track: 'internal'
        releaseName: 'test connection'
        isDraftRelease: true

And the error:


GooglePlayRelease

View raw log

Starting: GooglePlayRelease
==============================================================================
Task         : Google Play - Release
Description  : Release an app to the Google Play Store
Version      : 4.244.0
Author       : Microsoft Corporation
Help         : https://marketplace.visualstudio.com/items?itemName=ms-vsclient.google-play
==============================================================================
Authenticated with Google Play and getting new edit
##[error]Error: Failed to upload the bundle /home/vsts/work/1/s/android/app/build/outputs/bundle/productionRelease/app-production-release.aab. Failed with message: GaxiosError: Version code 1 has already been used.
    at Gaxios._request (/home/vsts/work/_tasks/GooglePlayRelease_8cf7cac0-620b-11e5-b4cf-8565e60f4d27/4.244.0/node_modules/gaxios/build/src/gaxios.js:129:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async JWT.requestAsync (/home/vsts/work/_tasks/GooglePlayRelease_8cf7cac0-620b-11e5-b4cf-8565e60f4d27/4.244.0/node_modules/google-auth-library/build/src/auth/oauth2client.js:368:18) {
  response: [Object],
  config: [Object],
  code: 403,
  errors: [Array]
}.
Finishing: GooglePlayRelease

I even tried building locally and used Android Studio to analyze the AAB and APK, both generate a manifest file where the version code is 2343... So Im really not sure why Google Play says it's 1


Solution

  • Turns out ADO pipelines makes a shallow clone of the repo, which means that there's only 1 commit, thus causing `git rev-list --count HEAD` to return 1.

    To fix it, force the pipeline to fetch everything:

        - checkout: self
          fetchDepth: 0
          persistCredentials: true
          clean: false
          displayName: Checkout
        - script: |
              git rev-list --count HEAD
          displayName: "git count"