Coder Social home page Coder Social logo

Comments (108)

dkornev avatar dkornev commented on June 14, 2024 56

Same request here.

But I'm using a walkaround that might be useful for someone:

  • Add VERSION_CODE_SHIFT environment variable into your build configuration. Basically, it's the last build number (CFBundleVersion for iOS and android:versionCode for Android) before you moved to App Center CI.

  • Update your appcenter-pre-build.sh (https://docs.microsoft.com/en-us/appcenter/build/custom/scripts/) and following lines there:

For iOS:
VERSION_CODE=$((VERSION_CODE_SHIFT + APPCENTER_BUILD_ID))
plutil -replace CFBundleVersion -string "$VERSION_CODE"
$APPCENTER_SOURCE_DIRECTORY/PATH_TO_YOUR_IOS_PROJECT/Info.plist

For Android:
MANIFEST_PATH="$APPCENTER_SOURCE_DIRECTORY/PATH_TO_YOUR_ANDROID_PROJECT/Properties/AndroidManifest.xml"
VERSION_CODE=$((VERSION_CODE_SHIFT + APPCENTER_BUILD_ID))
sed -i "" 's/android:versionCode="[^"]*"/android:versionCode="'$VERSION_CODE'"/' $MANIFEST_PATH

  • There is no need to turn on Automatically increment version code option. APPCENTER_BUILD_ID will be incremented anyway.

from appcenter.

philip-haspa avatar philip-haspa commented on June 14, 2024 54

Please implement this asap. For now its not possible to have an automated buildprocess for already existing apps with an higher versioncode.

from appcenter.

thomasgalliker avatar thomasgalliker commented on June 14, 2024 38

Guys, is someone working on this feature? It could be so easy:

  • Place a new numeric entry with some basic input validation
  • Save button to set the build number manually
  • Everyone is happy

from appcenter.

xgenem avatar xgenem commented on June 14, 2024 22

3 years after... I am adding a vote.

from appcenter.

nilofer avatar nilofer commented on June 14, 2024 15

Hey @alexshikov, we see this one as one of the top requested features and are definitely looking at it as we determine priorities each month.

from appcenter.

honzababarik avatar honzababarik commented on June 14, 2024 14

If it helps anyone, I just brute forced it with a browser script and ran/cancelled the builds to slowly increase the build ID. It's ridiculous solution, but it's the quickest for me right now and doesn't require me to keep maintaining different offsets per product flavor. This is what happens when you ignore blockers in your product for way too long 😄

Heads up, depending on some factors it might get interrupted and not make it to the entire offset, so it will require a few runs to get where you need to be. Just keep an eye on it while it's running. I needed to get to a build number north of 500 and didn't take me that long, surely quicker than me clicking.

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function waitForEl(sel) {
  const e = document.querySelector(sel);
  if (e) {
    return e;
  }
  await sleep(250);
  return waitForEl(sel);
}

async function runOnce() {
  const buildButton = await waitForEl('[data-test-id=build-now-button]');
  buildButton.click();
  
  const cancelButton = await waitForEl('[data-test-id=cancel-build-button]');
  cancelButton.click();

  const backButton = await waitForEl('[data-test-id=builds-page] button');
  backButton.click();
}

async function run(count) {
  for (var i = 0; i < count; i++) {  
    await runOnce();
  }
}

Copy&Paste to console and just run(whatever offset you need).

from appcenter.

kuhnza avatar kuhnza commented on June 14, 2024 11

@nathfy thanks for the pointers. There's a simpler way to do this though. I just added this function to my build.gradle file:

def getVersionCode = { ->
  def isAppCenter = System.getenv('APPCENTER_BUILD_ID') != null;

  if (isAppCenter) {
    try {
      def appcenterBuildId = Integer.parseInt(System.getenv('APPCENTER_BUILD_ID'))
      def versionCodeOffset = Integer.parseInt(System.getenv('VERSION_CODE_OFFSET'))

      return versionCodeOffset + appcenterBuildId
    } catch (e) {
      // ignore
    }
  }

  return 1 // default 
}

Then you can just call the function in your config like so:

defaultConfig {
  versionCode getVersionCode()
  versionName "1.0"
}

from appcenter.

nilofer avatar nilofer commented on June 14, 2024 10

@nathfy definitely not ignoring this, but having to continually prioritize across the product each month. We do hope to tackle this in the future.

from appcenter.

kazazes avatar kazazes commented on June 14, 2024 8

If you're having trouble with @honzababarik's solution, increase the sleep interval. 500ms worked for me, +150 in no time #21 (comment)

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function waitForEl(sel) {
  const e = document.querySelector(sel);
  if (e) {
    return e;
  }
  await sleep(500);
  return waitForEl(sel);
}

async function runOnce() {
  const buildButton = await waitForEl('[data-test-id=build-now-button]');
  buildButton.click();
  
  const cancelButton = await waitForEl('[data-test-id=cancel-build-button]');
  cancelButton.click();

  const backButton = await waitForEl('[data-test-id=builds-page] button');
  backButton.click();
}

async function run(count) {
  for (var i = 0; i < count; i++) {  
    await runOnce();
  }
}

from appcenter.

nilofer avatar nilofer commented on June 14, 2024 6

Hi @talsemgeest, thanks for this feature request. I can see how this is useful if you aren't starting out from scratch. We'll keep this issue open to track total interest in this ability.

from appcenter.

kuzzmi avatar kuzzmi commented on June 14, 2024 6

This might sound super stupid, but after migrating existing project to another App Center profile I recorded mouse movements and simulated amount of manual start build / cancel build actions to match the number of builds I had before.

from appcenter.

gagofure avatar gagofure commented on June 14, 2024 5

If your build runs on App Center and you don't want to follow the workaround suggested above, one lazy way to fix this issue is to build and immediately cancel the build repeatedly until you get to the desired Build ID

image

from appcenter.

Babazon avatar Babazon commented on June 14, 2024 4

I am sure this is a business decision by Microsoft Product Managers to not allow such a simple feature because they want you to be locked to using AppCenter only, and not other pipelines interchangeably. It's their business, and it's an economic decision. Developers don't call the shots, product managers with dollar sign eyes do.

from appcenter.

TomBruyneel avatar TomBruyneel commented on June 14, 2024 3

you can use the pre build script functionality from appcenter to change your info.plist

something like

PLIST=$APPCENTER_SOURCE_DIRECTORY/......./Info.plist
VERSION="1.0.${APPCENTER_BUILD_ID}"

echo "Setting version to ${VERSION}"

/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${VERSION}" $PLIST

from appcenter.

snios avatar snios commented on June 14, 2024 3

@snios I migrated couple of existing apps to appcenter, some with triple digit build numbers. The workaround is - I still agree - not very cool but it works well. Don't get me wrong: I also want this feature :)

Main thing here is to keep the thread alive, with hope to make this jump up in priority ;D

from appcenter.

djMax avatar djMax commented on June 14, 2024 3

The reason all these non-browser-scripting solutions are bad is because it makes appcenter less understandable. appcenter will show you build 1234, but you have to KNOW that corresponds to an output build of 123400 or 1234+5678. That's bad. The fact that this issue has persisted for so long tells you all you need to know about how Microsoft views appcenter. It's a shame, because there aren't clearly better alternatives, yet.

from appcenter.

ashish-d-hh avatar ashish-d-hh commented on June 14, 2024 3

Any updates on this ?

from appcenter.

TomBruyneel avatar TomBruyneel commented on June 14, 2024 2

Same request, I had to reset the build parameters after a repo change, and now the incremental build id is back at 1 too.

EDIT: apparently after building it goes back to the correct number

from appcenter.

alexshikov avatar alexshikov commented on June 14, 2024 2

Our app is already in the store and has build numbers history. Now there is no easy way to set base build number apart from writing custom pre-build scripts :(

from appcenter.

nilofer avatar nilofer commented on June 14, 2024 2

Hey @DominicCabral, no definite update for this month's iteration plan, but we intend to get to this very soon. Thanks for your patience!

from appcenter.

thomasgalliker avatar thomasgalliker commented on June 14, 2024 2

@snios I migrated couple of existing apps to appcenter, some with triple digit build numbers. The workaround is - I still agree - not very cool but it works well. Don't get me wrong: I also want this feature :)

from appcenter.

snios avatar snios commented on June 14, 2024 2

build and immediately cancel the build repeatedly until you get to the desired Build ID

We all know this. We are looking for a permanent fix not workarounds. And if your currently on build number 10xxx good luck with that.

from appcenter.

KevinHu-au avatar KevinHu-au commented on June 14, 2024 1

I am on the exact same situation. Move the existing app build automation to App Center

from appcenter.

meyerjg avatar meyerjg commented on June 14, 2024 1

Same request here.

from appcenter.

prollin avatar prollin commented on June 14, 2024 1

Same here. We are transitioning and existing app to AppCenter and being able to start from our current version number is absolutely necessary.

from appcenter.

alexshikov avatar alexshikov commented on June 14, 2024 1

@nrajpurkar how many likes do we need to move this feature to the next stage? :)

from appcenter.

jkatsiotis avatar jkatsiotis commented on June 14, 2024 1

+1

from appcenter.

rhouweling avatar rhouweling commented on June 14, 2024 1

My company switched to GitLab from a different source provider. It is impossible to switch from source provider without creating a new app and now I can't update the build number offset? Not very user friendly to have us create all kinds of custom solutions for something that should be in the product by default.

from appcenter.

hikui avatar hikui commented on June 14, 2024 1

It's been two years, still no changes? The workarounds are painful especially when you work in an agency and have to manage so many mobile projects. It becomes one of the biggest hurdles for us to switch to appcenter.

from appcenter.

saamerm avatar saamerm commented on June 14, 2024 1

I figured out to Automate Build numbering & App versioning for Android WITHOUT shell scripting while using Microsoft AppCenter CI/CD pipelines!
You can create environment variables and then use them in the build.gradle file like this:

versionCode System.getenv("VERSION_CODE") ? System.getenv("VERSION_CODE").toInteger() : 201
versionName System.getenv("VERSION_NAME") ? System.getenv("VERSION_NAME").toString() : "1.2.1"

More details in this article

from appcenter.

jkoutavas avatar jkoutavas commented on June 14, 2024 1

Hey @DominicCabral, no definite update for this month's iteration plan, but we intend to get to this very soon. Thanks for your patience!

Remaining patient. :-)

from appcenter.

marstall avatar marstall commented on June 14, 2024

very interested in this one. i have 4 builds that are typically released together to qa. they all have different builids; would be nice to reset them all to a certain value so they would remain in sync.

from appcenter.

DominicCabral avatar DominicCabral commented on June 14, 2024

Hey @nrajpurkar, any update on this? 😄

from appcenter.

svego avatar svego commented on June 14, 2024

This is preventing us from using the distribute to app store functionality, that wou would love to use!

from appcenter.

nathfy avatar nathfy commented on June 14, 2024

just been directed here by app center support, pointing at the workaround above (#21 (comment)) @nrajpurkar can you update us with progress on this?

from appcenter.

nicolgit avatar nicolgit commented on June 14, 2024

Any update on this? I want to move on appcenter an existing app, and this is a blocker.

from appcenter.

heumn avatar heumn commented on June 14, 2024

Jumping on this as well. I can not use app center for an old project because of this

from appcenter.

lestadd1988 avatar lestadd1988 commented on June 14, 2024

Up

from appcenter.

cvo-4tell avatar cvo-4tell commented on June 14, 2024

Up

from appcenter.

nathfy avatar nathfy commented on June 14, 2024

As app center are ignoring this, here is the solution I am using. It's based on @dkornev one. We are android only at the moment, so only tested there. Should work for IOS with some teaks:

  • Add VERSION_CODE_SHIFT environment variable into your build configuration. Basically, it's the last build number (android:versionCode for Android) before you moved to App Center CI.
  • Add an gradle.properties file with your version details, next to the build.gradle:
VERSION_NAME=3.0.0
VERSION_CODE=279
  • Update build.gradle to use the variables from the gradle.properties:
defaultConfig {
        versionCode Integer.parseInt(VERSION_CODE)
        versionName (VERSION_NAME+VERSION_CODE)
    }
#!/usr/bin/env bash
# This updates the version number to be the build id from app center + the shift up to the build number from the google play store
# Currently we don't shift the ios version number.

PROJECT_NAME=NameOfProjectOnAppCenter
ANDROID_GRADLE_FILE=$APPCENTER_SOURCE_DIRECTORY/NameOfProjectOnAppCenter/android/app/gradle.properties
INFO_PLIST_FILE=$APPCENTER_SOURCE_DIRECTORY/NameOfProjectOnAppCenter/ios/$PROJECT_NAME/Info.plist
VERSION_CODE=$((VERSION_CODE_SHIFT + APPCENTER_BUILD_ID))
echo "Looking for $ANDROID_GRADLE_FILE to update build version";

if [ -e "$ANDROID_GRADLE_FILE" ]
then
    echo "Updating version code to $VERSION_CODE in $ANDROID_GRADLE_FILE"
    sed -i "" 's/VERSION_CODE=[0-9]*/VERSION_CODE='$VERSION_CODE'/' $ANDROID_GRADLE_FILE

    echo "File content:"
    cat $ANDROID_GRADLE_FILE
fi

from appcenter.

miroslavdurkovic avatar miroslavdurkovic commented on June 14, 2024

@kuhnza thanks it works, have you also workaround for iOS?

from appcenter.

kuhnza avatar kuhnza commented on June 14, 2024

@miroslavdurkovic sorry no. Only needed to solve it for Android at this point because previous versions were blocking me from publishing to App Store.

I suspect there’s a way to do it with Xcode’s build scripts though.

from appcenter.

CAMOBAP avatar CAMOBAP commented on June 14, 2024

@nilofer maybe there is some update on this?

from appcenter.

nilofer avatar nilofer commented on June 14, 2024

tapping in @elamalani for this

from appcenter.

alexandrius avatar alexandrius commented on June 14, 2024

Would be really useful indeed

from appcenter.

L-U-C-K-Y avatar L-U-C-K-Y commented on June 14, 2024

This might sound super stupid, but after migrating existing project to another App Center profile I recorded mouse movements and simulated amount of manual start build / cancel build actions to match the number of builds I had before.

Although not ideal at all, only workaround I‘ve heard so far the we could make use of.

@nilofer do you have any updates regarding this feature or an alternative workaround?

from appcenter.

King-of-Spades avatar King-of-Spades commented on June 14, 2024

@kuzzmi @LucBas Have you tried any approaches like @TomBruyneel's?

PLIST=$APPCENTER_SOURCE_DIRECTORY/......./Info.plist
VERSION="1.0.${APPCENTER_BUILD_ID}"
echo "Setting version to ${VERSION}"

Appending the APPCENTER_BUILD_ID value to your normal defined version would give you that kind of unique identifier per build. Plus, having the build number at the end of a semantic version is a pretty typical versioning standard, like so:

(1.0.0.324)
(Major.Minor.Patch.Build)

More info on the environment variable here: https://docs.microsoft.com/en-us/appcenter/build/custom/variables/
And on Build scripts here: https://docs.microsoft.com/en-us/appcenter/build/custom/scripts/

from appcenter.

kuzzmi avatar kuzzmi commented on June 14, 2024

@King-of-Spades unfortunately this workaround is not valid for my case. Because if I transfer the app to another account, I get the same kind of issue - build number won't be unique, because it starts from 1. Although we could bump the version in the plist file, but that requires me to change source code, what I expect not to happen here.

However, in general, Major.Minor.Patch.Build even can be one of the options in App Center - to have this kind of rule in addition to timestamps. But that's a bit different story.

from appcenter.

alexandrius avatar alexandrius commented on June 14, 2024

@King-of-Spades unfortunately this workaround is not valid for my case. Because if I transfer the app to another account, I get the same kind of issue - build number won't be unique, because it starts from 1. Although we could bump the version in the plist file, but that requires me to change source code, what I expect not to happen here.

However, in general, Major.Minor.Patch.Build even can be one of the options in App Center - to have this kind of rule in addition to timestamps. But that's a bit different story.

Just create simple post clone script and that's it

from appcenter.

kuzzmi avatar kuzzmi commented on June 14, 2024

@alexandrius I guess the whole topic is about being able to do this in the UI, not the possibility to do this in general with workarounds, but thanks.

from appcenter.

alexandrius avatar alexandrius commented on June 14, 2024

@alexandrius I guess the whole topic is about being able to do this in the UI, not the possibility to do this in general with workarounds, but thanks.

You are right sorry I thought this was different issue

from appcenter.

King-of-Spades avatar King-of-Spades commented on June 14, 2024

Yeah, I was only trying to highlight workarounds that might be less painful & more viable, I realize they don't really "fix" the issue but in some cases might be sufficient.

from appcenter.

sanojKashyap avatar sanojKashyap commented on June 14, 2024

any updates on this feature/issue?

from appcenter.

jgorecki-zz avatar jgorecki-zz commented on June 14, 2024

Adding a vote here.

from appcenter.

stevewinn74 avatar stevewinn74 commented on June 14, 2024

And another

from appcenter.

CHrycyna avatar CHrycyna commented on June 14, 2024

This would be really useful for apps that are already published.

from appcenter.

exajai avatar exajai commented on June 14, 2024

Adding one more request. here. Setting a base version of the build

from appcenter.

dileep-synapsesai avatar dileep-synapsesai commented on June 14, 2024

Add Other, please add ASAP

from appcenter.

SardorbekR avatar SardorbekR commented on June 14, 2024

More than a year passed/

from appcenter.

AndyNetDuma avatar AndyNetDuma commented on June 14, 2024

The script above half worked for me, I couldn't get it to do more than 3 at a time before bugging out. It still saved me a lot of time bumping 20 versions
Really disappointing we have to use a random script for such a basic feature. Seems like they aren't even pretending it's a priority anymore.

from appcenter.

yvbeek avatar yvbeek commented on June 14, 2024

@nilofer Any updates on this?

from appcenter.

nilofer avatar nilofer commented on June 14, 2024

I no longer work on App Center. @elamalani to provide support here.

from appcenter.

usamamoinakhter avatar usamamoinakhter commented on June 14, 2024

If it helps anyone, I just brute forced it with a browser script and ran/cancelled the builds to slowly increase the build ID. It's ridiculous solution, but it's the quickest for me right now and doesn't require me to keep maintaining different offsets per product flavor. This is what happens when you ignore blockers in your product for way too long 😄

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function waitForEl(sel) {
  const e = document.querySelector(sel);
  if (e) {
    return e;
  }
  await sleep(250);
  return waitForEl(sel);
}

async function runOnce() {
  const buildButton = await waitForEl('[data-test-id=build-now-button]');
  buildButton.click()
  
  const cancelButton = await waitForEl('[data-test-id=cancel-build-button]');
  cancelButton.click();

  const backButton = await waitForEl('[data-test-id=builds-page] button');
  backButton.click()
}

async function run(count) {
  for (var i = 0; i < count; i++) {  
    await runOnce();
  }
}

Copy&Paste to console and just run(whatever offset you need).

You are a lifesaver.

from appcenter.

johnnylambada avatar johnnylambada commented on June 14, 2024

I used @honzababarik's code and it worked. I had to change the timeout to 4000ms though, so it wasn't super fast, but I didn't have to sit and press over 3000 buttons 👍

from appcenter.

rddewan avatar rddewan commented on June 14, 2024

Increase the version code and version name in Android with appcenter-pre-build script

  1. create appcenter-pre-build.sh and place it under a app folder
  2. Create a environment variable VERSION_CODE and VERSION_NAME in App Center build settings

Note: You have to manually increase the VERSION_CODE and VERSION_NAME in App Center build settings on each release to Google Play Store. If you found any solution to increase the VERSION_CODE and VERSION_NAME after successful build please share.

`
#!/usr/bin/env bash

#This script allows the version code to be changed in an android build.gradle(app directory) file
#Please specify a VERSION_CODE variable and value in the app center build environment variables in
#the app center build settings pane online

#If no VERSION_CODE environment variable is found then the script will exit with

a message to define the version code in app center environment variables

if [ -z "$VERSION_CODE" ]
then
echo "To use this script, define VERSION_CODE in App Center build settings portal under environment variables"
exit
fi

#Identifies the build.gradle file in the app directory
ANDROID_BUILD_GRADLE=$APPCENTER_SOURCE_DIRECTORY/app/build.gradle

if [ -e "$ANDROID_BUILD_GRADLE" ]
then
echo "version code:" $VERSION_CODE
cat $ANDROID_BUILD_GRADLE
echo "Updating version code to $VERSION_CODE in build.gradle file"

#Finds the versionCode in build.gradle and replaces it with the $VERSION_CODE variable
#defined in app center environment variables
sed -i '' 's/versionCode [0-9a-zA-Z -_]*/versionCode '$(($VERSION_CODE))'/' $ANDROID_BUILD_GRADLE

#Displays the newly updated gradle file with updated versionCode
echo "File content:"
cat $ANDROID_BUILD_GRADLE

fi

#change version name
#If no $VERSION_NAME environment variable is found then the script will exit with

a message to define the version code in app center environment variables

if [ -z "$VERSION_NAME" ]
then
echo "To use this script, define VERSION_NAME in App Center build settings portal under environment variables"
exit
fi

#Identifies the build.gradle file in the app directory
ANDROID_BUILD_GRADLE=$APPCENTER_SOURCE_DIRECTORY/app/build.gradle

if [ -e "$ANDROID_BUILD_GRADLE" ]
then
echo "version name:" $VERSION_NAME
cat $ANDROID_BUILD_GRADLE
echo "Updating version name to $VERSION_NAME in build.gradle file"

#Finds the versionName in build.gradle and replaces it with the $VERSION_NAME variable
#defined in app center environment variables
sed -i '' 's/versionName "[0-9.]*"/versionName "'$VERSION_NAME'"/' $ANDROID_BUILD_GRADLE

#Displays the newly updated gradle file with updated versionCode
echo "File content:"
cat $ANDROID_BUILD_GRADLE

fi

`

from appcenter.

gabriel-tentaculo avatar gabriel-tentaculo commented on June 14, 2024

Also requesting this functionality.
Please allow us to set a value for the auto increment variable version code

from appcenter.

Temeteron avatar Temeteron commented on June 14, 2024

+1

from appcenter.

snios avatar snios commented on June 14, 2024

Bump! Any update on this?

from appcenter.

joemather avatar joemather commented on June 14, 2024

Adding a vote. This feature is long overdue.

from appcenter.

grafficmedia avatar grafficmedia commented on June 14, 2024

Would love to see this feature! Is there any update on it?

from appcenter.

thomasgalliker avatar thomasgalliker commented on June 14, 2024

@Babazon this feature would help onbording apps to appcenter which already exist, technically speaking, apps which have build versions >1 published in the stores. So, of course it is an economic business decision (because a) it costs money to develop this feature and b) there is a workaround for it which you c) don’t very often have use to be honest).

One point I don’t really like is that there is almost no communication going on 🤷🏼‍♂️

from appcenter.

snios avatar snios commented on June 14, 2024

@Babazon this feature would help onbording apps to appcenter which already exist, technically speaking, apps which have build versions >1 published in the stores. So, of course it is an economic business decision (because a) it costs money to develop this feature and b) there is a workaround for it which you c) don’t very often have use to be honest).

One point I don’t really like is that there is almost no communication going on 🤷🏼‍♂️

"don’t very often have use to be honest"

Well, except for every app we already have developed outside Appcenter. Most of them in other words. And the workaround is not a good option, because it is a workaround.

There is however a script in one of these threads that with little tweaking can start and cancel builds for you. (perhaps not viable if your build number is in the triple digits though.

from appcenter.

briankurr avatar briankurr commented on June 14, 2024

+1

from appcenter.

jtorvald avatar jtorvald commented on June 14, 2024

@elamalani any update?

from appcenter.

buzzware avatar buzzware commented on June 14, 2024

This issue led me to use timestamp build numbers, but that has problems too, so I created this issue,
#2090
which has just been automatically closed by a bot with no resolution :(

from appcenter.

RedkoVO avatar RedkoVO commented on June 14, 2024

+1

from appcenter.

jbenzshawel avatar jbenzshawel commented on June 14, 2024

+1

from appcenter.

bed42 avatar bed42 commented on June 14, 2024

Thanks for the js scripts everyone. If you're having issues with it, also try it in Chrome - it was bugging out in Safari but running perfectly in Chrome.

AppCenter really does need to address this properly however .

from appcenter.

henryallsuch avatar henryallsuch commented on June 14, 2024

I had not paid attention to @kornev's comment

There is no need to turn on Automatically increment version code option. APPCENTER_BUILD_ID will be incremented anyway.

Which in fact was stopping the solution I had in place because it was enabled.

This was what I ended up with for Android.

build.gradle


//Environment Variables
def envProperties = new Properties()
try {
    def envPropertiesFile = rootProject.file("env.properties")
    envProperties.load(new FileInputStream(envPropertiesFile))
} catch (FileNotFoundException e) {
    logger.info("env.properties file not found")

    //Defaults
    envProperties['VERSION_BASE_NAME'] = '0.0.0'
    envProperties['VERSION_CODE_PREFIX'] = 1
    envProperties['APPCENTER_BUILD_ID'] = 1
}

def VERSION_BASE_NAME = System.getenv("VERSION_BASE_NAME") ? System.getenv("VERSION_BASE_NAME") : envProperties['VERSION_BASE_NAME']

def VERSION_CODE_PREFIX = System.getenv("VERSION_CODE_PREFIX") ? System.getenv("VERSION_CODE_PREFIX") as Integer : envProperties['VERSION_CODE_PREFIX'] as Integer

def APPCENTER_BUILD_ID = System.getenv("APPCENTER_BUILD_ID") ? System.getenv("APPCENTER_BUILD_ID") as Integer : envProperties['APPCENTER_BUILD_ID'] as Integer

def FINAL_VERSION_CODE = (VERSION_CODE_PREFIX + APPCENTER_BUILD_ID) as Integer

android {

...

defaultConfig {

    setProperty("versionCode", FINAL_VERSION_CODE)
    setProperty("versionName", VERSION_BASE_NAME)
    setProperty("archivesBaseName", "myapp-v" + versionName + "-" + versionCode)

...

}

...
}

env.properties file for local settings

VERSION_BASE_NAME=6.0.1-beta
VERSION_CODE_PREFIX=60100

from appcenter.

tons613 avatar tons613 commented on June 14, 2024

@nathfy thanks for the pointers. There's a simpler way to do this though. I just added this function to my build.gradle file:

def getVersionCode = { ->
  def isAppCenter = System.getenv('APPCENTER_BUILD_ID') != null;

  if (isAppCenter) {
    try {
      def appcenterBuildId = Integer.parseInt(System.getenv('APPCENTER_BUILD_ID'))
      def versionCodeOffset = Integer.parseInt(System.getenv('VERSION_CODE_OFFSET'))

      return versionCodeOffset + appcenterBuildId
    } catch (e) {
      // ignore
    }
  }

  return 1 // default 
}

Then you can just call the function in your config like so:

defaultConfig {
  versionCode getVersionCode()
  versionName "1.0"
}

This workaround by @kuhnza worked for me, but I had to change System.getenv('APPCENTER_BUILD_ID') to System.env.APPCENTER_BUILD_ID for it to work

def getVersionCode = { ->
  def isAppCenter = System.env.APPCENTER_BUILD_ID != null;

  if (isAppCenter) {
    try {
      def appcenterBuildId = Integer.parseInt(System.env.APPCENTER_BUILD_ID)
      def versionCodeOffset = Integer.parseInt(System.env.VERSION_CODE_OFFSET)

      return versionCodeOffset + appcenterBuildId
    } catch (e) {
      // ignore
    }
  }

  return 1 // default 
}

from appcenter.

 avatar commented on June 14, 2024

I'm wondering if there's any update on this? We're willing to switch to automated AppCenter builds, and also switch to a paid plan. But this seems to be a bit of a killer, since we're having tons of existing apps, and don't want to integrate workarounds for all of them. Any news on this, AppCenter?

from appcenter.

saamerm avatar saamerm commented on June 14, 2024

@dani-digital what framework/language are you using to build your app? Check this comment out:

#21 (comment)

from appcenter.

 avatar commented on June 14, 2024

Thanks @saamerm , that helps for Android. We're having tons of iOS apps also, where this solution won't work, I assume.

from appcenter.

djMax avatar djMax commented on June 14, 2024

It is really a shame that this has survived this long... you figure it has to be just an admin-tool with a sql statement away from complete, but here we all are doing crazy things. I used the browser script above as inspiration for a headless version. To run it, go in Chrome dev tools and then click the "build" button to get the headers and request (you can use "Copy Node fetch request" to make it easiest. Then substitute the values where appropriate, and run this in node.

const fetch = require('isomorphic-fetch');

const headers = {
  // Put all the header values here. Should include "accept", "cookie", "authorization", and etc
};

const baseUrl = 'https://appcenter.ms/api/v0.1/apps/YourOrg/YourApp';
const commitHash = '*** some git hash of the most recent commit which you will see in the BODY of the build request ***';

async function target(targetBuildNumber) {
  let current = 0;
  let startBuild;
  const start = Date.now();
  while (current < targetBuildNumber) {
    const { buildNumber } = await fetch(`${baseUrl}/branches/develop/builds`, {
      headers,
      referrerPolicy: 'no-referrer',
      body: JSON.stringify({ sourceVersion: commitHash }),
      method: 'POST',
    })
      .then((response) => response.json())
      .catch((error) => {
        console.error('Build failed', error);
        return {};
      });
    if (!buildNumber) {
      continue;
    }
    // Don't wait on the cancel, keep on going.
    fetch(`${baseUrl}/builds/${buildNumber}`, {
      headers,
      referrerPolicy: 'no-referrer',
      body: JSON.stringify({ status: 'cancelling' }),
      method: 'PATCH',
    }).catch((error) => console.error('Cancel failed', error));

    if (current === 0) {
      startBuild = buildNumber;
    }
    current = buildNumber;

    const elapsed = Date.now() - start;
    const total = ((targetBuildNumber - startBuild) * elapsed) / (current - startBuild);
    console.log(
      `Build ${buildNumber}/${targetBuildNumber} consumed. Expected completion ${new Date(
        start + total,
      )}`,
    );
  }
}

target(20000).then(() => console.log('Done'));

from appcenter.

djMax avatar djMax commented on June 14, 2024

I made a package for it. You should be able to call it like so:

npx appcenter-build-bot --app [put appcenter url for your app here] --key [put the API key you generated here] build <target-number>

from appcenter.

Bayramito avatar Bayramito commented on June 14, 2024

@nathfy thanks for the pointers. There's a simpler way to do this though. I just added this function to my build.gradle file:

def getVersionCode = { ->
  def isAppCenter = System.getenv('APPCENTER_BUILD_ID') != null;

  if (isAppCenter) {
    try {
      def appcenterBuildId = Integer.parseInt(System.getenv('APPCENTER_BUILD_ID'))
      def versionCodeOffset = Integer.parseInt(System.getenv('VERSION_CODE_OFFSET'))

      return versionCodeOffset + appcenterBuildId
    } catch (e) {
      // ignore
    }
  }

  return 1 // default 
}

Then you can just call the function in your config like so:

defaultConfig {
  versionCode getVersionCode()
  versionName "1.0"
}

This workaround by @kuhnza worked for me, but I had to change System.getenv('APPCENTER_BUILD_ID') to System.env.APPCENTER_BUILD_ID for it to work

def getVersionCode = { ->
  def isAppCenter = System.env.APPCENTER_BUILD_ID != null;

  if (isAppCenter) {
    try {
      def appcenterBuildId = Integer.parseInt(System.env.APPCENTER_BUILD_ID)
      def versionCodeOffset = Integer.parseInt(System.env.VERSION_CODE_OFFSET)

      return versionCodeOffset + appcenterBuildId
    } catch (e) {
      // ignore
    }
  }

  return 1 // default 
}

I just tried your solution but when i try to push release throws me this error
failed with exception "No property named "1.2 + getVersionCode()" exists in the "android/gradle.properties" file.

from appcenter.

juliancorrea avatar juliancorrea commented on June 14, 2024

I got success doing like this:
`
ext.versionCode = 12009;

def getVersionCode = { ->
    logger.quiet(':::getVersionCode ==> invoked')
    def buildVersionCode = ext.versionCode; // default
    def isAppCenter = System.getenv('APPCENTER_BUILD_ID') != null;

if (isAppCenter) {
  if(System.getenv('USER-DEFINED_VERSION_CODE_OFFSET') == null){
      throw new MissingPropertyException("Runing inside AppCenter is necessary inform the USER-DEFINED_VERSION_CODE_OFFSET to avoid versionCode issues on Google Play Store.")
}
  def appcenterBuildId = Integer.parseInt(System.getenv('APPCENTER_BUILD_ID'))
  def versionCodeOffset = Integer.parseInt(System.getenv('USER-DEFINED_VERSION_CODE_OFFSET'))
  buildVersionCode = versionCodeOffset + appcenterBuildId
  }
logger.quiet(":::getVersionCode isAppCenter ==>  ${isAppCenter} FINAL VERSION CODE  ==> ${buildVersionCode}");
return buildVersionCode
}

android {

defaultConfig {
    ........
    versionCode getVersionCode()
    ........
}`

from appcenter.

DenisBalan avatar DenisBalan commented on June 14, 2024

I made a package for it. You should be able to call it like so:

npx appcenter-build-bot --app [put appcenter url for your app here] --key [put the API key you generated here] build <target-number>

Nice one! Link to @djMax repo
https://github.com/gas-buddy/appcenter-build-bot

Helped me. Full command:

> docker run --rm -it node /bin/bash
(now inside container)
> cd /tmp 
> npm i -D appcenter-build-bot
> npx appcenter-build-bot --app https://appcenter.ms/orgs/XXXXXXX/apps/APP.Android/ --key mykey --branch dev build 1337

from appcenter.

xgenem avatar xgenem commented on June 14, 2024

+1

from appcenter.

msftbot avatar msftbot commented on June 14, 2024

This issue has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs within 15 days of this comment.

from appcenter.

snios avatar snios commented on June 14, 2024

Any updates on an official fix for this?

from appcenter.

xgenem avatar xgenem commented on June 14, 2024

For anyone still hoping, give up. It doesn't seem like it's a feature that will become available at all. Just try to find a workaround.

from appcenter.

snios avatar snios commented on June 14, 2024

For anyone still hoping, give up. It doesn't seem like it's a feature that will become available at all. Just try to find a workaround.

Perhaps so. I just like reminding them of their neglect towards one of their promises.

Promise made in 2019

"nilofer commented on Oct 11, 2019
Hey @DominicCabral, no definite update for this month's iteration plan, but we intend to get to this very soon. Thanks for your patience"

from appcenter.

fawad-khalil-retailo avatar fawad-khalil-retailo commented on June 14, 2024

@nilofer
Being patient :)

from appcenter.

SAMUEL-KETECHIE avatar SAMUEL-KETECHIE commented on June 14, 2024

It's been 3 yrs and counting. This fix has not sufficed yet.
Is there any hope on this? @appcenter

from appcenter.

SAMUEL-KETECHIE avatar SAMUEL-KETECHIE commented on June 14, 2024

It's been 3 yrs and counting. This fix has not sufficed yet.
Is there any hope on this? @appcenter

from appcenter.

SAMUEL-KETECHIE avatar SAMUEL-KETECHIE commented on June 14, 2024

It's been 3 yrs and counting. This fix has not sufficed yet.
Is there any hope on this? @appcenter

from appcenter.

snios avatar snios commented on June 14, 2024

@elamalani will there be a fix for this soon? This was promised a very long time ago.

from appcenter.

juliancorrea avatar juliancorrea commented on June 14, 2024

Exactly @snios! Sometimes people cannot think outside the box, only look at their problems... Manual repairs will never be a solution...
we are developers, we create solutions to make processes faster and more reliable.
This problem is still open today, it's a shame for Microsoft...

from appcenter.

SAMUEL-KETECHIE avatar SAMUEL-KETECHIE commented on June 14, 2024

For Christ sake, MSFT....
please find a solution to this for us -:)
it's almost 4 good years.

from appcenter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.