Automating build version for mobile projects in Flashdevelop
Developing my first game for iOS, I quickly had to come up with a way to handle the version of my builds and if possible to do that entirely automatically from when I press build to renaming the compiled .ipa file.
I first got the plugin Version Number for Flashdevelop, which will increment the version of your application when you Build and/or Test your project. It creates an AS class, so you can easily refer to the version in your code, but will also update your application.xml file automatically, which very handy giving the issue updating iOS application with a similar version number.
Now that’s great, but I wanted to have my Ad-Hoc IPA files (and only them) to include their version number, so here comes a bit of batch file editing…
Let’s start by finding the current version number from application.xml. We can do that in bat\SetupApplication.bat, find the Output Packages variables and on the line after DIST_NAME, add this:
FOR /f "tokens=3 delims=>< " %%a IN ('TYPE application.xml ^| FIND "<versionNumber>"') DO set DIST_VERSION=%%a
We just tell him to retrieve what’s inside the versionNumber tag of the application.xml file (if you have moved it from its default location, make sure to update code with its appropriate path then) and store it in the variable DIST_VERSION.
Now, we can update the batch file handling file output name, which is found in bat\Packager.bat, look for the following line:
set OUTPUT=%DIST_PATH%\%DIST_NAME%%TARGET%.%DIST_EXT%
You can replace it with:
if %TARGET% == -ad-hoc set OUTPUT=%DIST_PATH%\%DIST_NAME%%TARGET%-%DIST_VERSION%.%DIST_EXT%
if not %TARGET% == -ad-hoc set OUTPUT=%DIST_PATH%\%DIST_NAME%%TARGET%.%DIST_EXT%
Where we ask it to add the version number we stored in DIST_VERSION when the output file is building compiled for Ad-Hoc.
And that’s it, if you are OCD with your application version numbers as I am, you will feel hugely relieved!