Search code examples
androidgradleapkandroid-build

Output.json displays app version code as version name


When running assembleProdRelease to generate APK and output files I got something weird that I couldn't explain (My app has a prod flavour and release build type).

The output.json file actually shows version code as version name, see below

{
  "version": 1,
  "artifactType": {
    "type": "APK",
    "kind": "Directory"
  },
  "applicationId": "com.example.myapp",
  "variantName": "prodDebug",
  "elements": [
    {
      "type": "SINGLE",
      "filters": [],
      "properties": [],
      "versionCode": 2,
      "versionName": "2",
      "enabled": true,
      "outputFile": "app-prod-debug.apk"
    }
  ]
}

My build gradle (it's in Kotlin kts) is pretty standard:

defaultConfig {
        applicationId = "com.example.myapp"
        minSdkVersion(24)
        targetSdkVersion(29)
        versionName = "1.0.0"
        versionCode = 2
    }

I would expect "versionName": "1.0.0" instead of "2" as shown in the output.json file.

My CI setup relies on the output file content to grab the app version from there so this basically causes me generating wrong file name.

I was wondering if anyone has come across a similar issue and how did you resolve it?

Thanks


Solution

  • It is an issue with android gradle plugin 4.0.0. Update gradle plugin version

    classpath 'com.android.tools.build:gradle:4.0.2' // currently 4.1.0 might also apply
    

    Current version can be checked here