Home Features Docs Blog Support GitHub

Updating Bundle Version from Gradle script


(Alex Itelman - Muvix) #1

Hello,

We are updating our Xcode App Bundle version from our Gradle script using:

defaults write com.apple.dt.Xcode IDEApplicationwideBuildSettings -dict-add MOE_BUNDLE_VERSION $project.ext.versionWithBuildNumberWithoutSnapshotSuffix".execute().waitFor()

And then setting the Bundle Version in Xcode to ${MOE_BUNDLE_VERSION}

This seems to work well when we’re building our ipa on our build machine, but when simply running from Xcode for debugging, when updating our global version in our main gradle script, the xcode project doesn’t recognise the change, and the app still has the previous version.

This is very inconvenient.
How can we make it work?


(Gergely Kis - Migeran) #2

Hi,

we are using this tool from Apple in our Jenkins build pipeline script to update the version with the build number prior to running the Gradle build:

sh 'agvtool new-version -all ' + BUILD_NUMBER

It should be possible for you to add it to your build.gradle as well, so it runs before the actual build starts.

Would this be a solution for you?

Best Regards,
Gergely


(Alex Itelman - Muvix) #3

If it works, why not?
Does this also set the bundle short version?
How to I put it in the gradle script?
Where do I get this tool from?


(Alex Itelman - Muvix) #4

And what do I need to set in the info.plist in the bundle version and bundle short version?


(Alex Itelman - Muvix) #5

I tried this method, it seems to set the version in the info.plist (I used new-marketing-version for the bundle short version), but the build fails on:

User supplied UIDeviceFamily key in the Info.plist will be overwritten. Please use the build setting TARGETED_DEVICE_FAMILY and remove UIDeviceFamily from your Info.plist.

I don’t know what’s the relation… But when I remove the call to agvtool this doesn’t happen.


(Alex Itelman - Muvix) #6

Even when I actually remove the “UIDeviceFamily” from the plist like it suggests, it still doesn’t start the app from xcode, it just says “Build stopped” in the end…


(Alex Itelman - Muvix) #7

Any other ideas for this?


(Alex Itelman - Muvix) #8

I think Xcode doesn’t “like” the fact that the info.plist is changed during the build… So it just stops the build. :frowning:
Any other idea?


(Alex Itelman - Muvix) #9

Any help would be appreciated please


(Alex Itelman - Muvix) #10

For anyone who might have the same problem:

I ended up using a pre-action in xcode similar to what is described here: (info.plist preprocessing header file)

And I also called this script from the gradle build script, so it works both with a gradle command line build and when building in xcode.