Appcenter: Android versionCode does not auto increment

Created on 9 Feb 2019  路  10Comments  路  Source: microsoft/appcenter

What App Center service does this affect?
Android release builds

Describe the bug
AppCenter fails to auto increment the versionCode

To Reproduce
Steps to reproduce the behavior:

  1. Open the branch/build configuration
  2. Toggle ON Automatically increment version code
  3. select the timestamp option
  4. Save & Build
  5. Build again

Expected behavior
I expect each successive build to update the version code, however the number from the gradle file is used no matter what the version code build setting is

Screenshots
screen shot 2019-02-08 at 8 20 14 pm
screen shot 2019-02-08 at 8 21 03 pm

Desktop (please complete the following information):

  • OS: Android
  • Browser n/a
  • Version 28.0.3

Additional context
I've tried builds with the toggle on and off, using the incremented build number vs timestamp... everything. I just won't come unstuck.

bug build

All 10 comments

Hi @iamcam, do you mind reaching out through the chat feature in the App Center web portal to get your configuration looked at by someone from our team? It's difficult for us to triage issues with peoples build configurations here, but we would be happy to give you some 1 on 1 support there.

@patniko Sure thing, thanks.

I received 1 on 1 support in App Center for this today. Auto increment for versionCode doesn't work with Android gradle plugin version 3.3.0 or higher. Downgrade to 3.2.1 and you should be good.

Edit: My advice to downgrade was accurate at the time but is now outdated.

@iamcam still hitting this issue or was support able to help you out?

Closing this for now as there hasn't been follow up from the original reporter.

The solution is just a workaround, so what is the status of the issue? is that fixed? I am facing this issue even today. @patniko

@ramasamyprabakaran @patniko have either of you found a solution?

still doesn't work

This is still happening. Please reopen the issue.

I have a solution if you use timestamp based versionCode:

appcenter-post-clone.sh

#!/usr/bin/env bash -e

cd $APPCENTER_SOURCE_DIRECTORY

if [[ -z "$APPCENTER_XCODE_PROJECT" ]]; then
  node ./appcenter-post-clone.android.js
fi

appcenter-post-clone.android.js:

const path = require("path");
const fs = require("fs");

const buildFilePath = path.join(__dirname, "android", "app", "build.gradle"); // react-native project, you might want to adjust the path
const buildFile = fs.readFileSync(buildFilePath, { encoding: "utf8" });

const versionCodeRegExp = /versionCode (?<versionCode>\d+)/g;
const buildFileMatch = versionCodeRegExp.exec(buildFile);

if (!buildFileMatch) {
  console.error("Could not increment versionCode");
  process.exit(1);
}

const nextVersionCode = Math.floor(Date.now() / 1000).toFixed(0);

fs.writeFileSync(
  buildFilePath,
  buildFile.replace(versionCodeRegExp, `versionCode ${nextVersionCode}`),
  { encoding: "utf8" },
);

It should also work with pre-build script, but I didn't tested it, and I'm not sure the difference matter.
This is still a workaround, I hope this will be fixed 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sindresorhus picture sindresorhus  路  3Comments

botatoes picture botatoes  路  4Comments

vonovak picture vonovak  路  3Comments

galfonso777 picture galfonso777  路  3Comments

patrickdoodyIRL picture patrickdoodyIRL  路  3Comments