Skip to content

Instantly share code, notes, and snippets.

@benshippee
Created February 11, 2020 01:37
Show Gist options
  • Save benshippee/0b1446287517aa44a675c86c0711c2bf to your computer and use it in GitHub Desktop.
Save benshippee/0b1446287517aa44a675c86c0711c2bf to your computer and use it in GitHub Desktop.
Unity build post process script to automatically bump iOS and Android version numbers
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
public class BuildNumberIncrementer
{
[PostProcessBuild]
public static void OnBuildComplete(BuildTarget buildTarget, string pathToBuiltProject)
{
IncrementBuildNumber(buildTarget);
}
private static void IncrementBuildNumber(BuildTarget buildTarget)
{
switch (buildTarget)
{
case BuildTarget.iOS:
BumpiOSBuildNumber();
break;
case BuildTarget.Android:
BumpAndroidBuildNumber();
break;
default:
break;
}
}
private static void BumpiOSBuildNumber()
{
var buildNumberString = PlayerSettings.iOS.buildNumber;
int buildNumber;
if (int.TryParse(buildNumberString, out buildNumber))
{
PlayerSettings.iOS.buildNumber = (buildNumber + 1).ToString();
Debug.Log("Bumped iOS Build Number to " + PlayerSettings.iOS.buildNumber);
AssetDatabase.SaveAssets();
}
}
private static void BumpAndroidBuildNumber()
{
var buildNumber = PlayerSettings.Android.bundleVersionCode;
PlayerSettings.Android.bundleVersionCode = buildNumber + 1;
Debug.Log("Bumped Android Bundle Version Code to " + PlayerSettings.Android.bundleVersionCode);
AssetDatabase.SaveAssets();
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment