Hi there, I was wondering if it was possible to set the BundleVersionCode through a custom editor script. I am making a simple build panel for an android project with the BundleVersion set to match my company’s version naming convention. I would like to set the BundleVersionCode with this same convention (minus the "."s) but cant seem to find an access point.
Is there really no way to access/ mutate that data at build time? And if not, why? It doesn’t seem like bad form to do this but maybe I’m wrong.
And I answered my own question 3 minutes after I asked it. While the BundleIdentifier and BundleVersion values are shared between platforms (marked clearly in the inspector with a *) the BundleVersionCode is not. That means it can be found in PlayerSettings.Android.bundleVersionCode.
Next time I’ll dig a little deeper before asking here.
Basically, my problem was version conflict when you compile for IOS. The new iTunes TestFlight does not allow same version number as the old TestFlight. I solved writing an editor script that rewrite every editor update the bundle version with a fixed string like i.e. “1.202.” followed by month+day+hour+minute. So I can now forget about to change bundle version when I’m gonna build any bundle.
using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
[InitializeOnLoad]
public class bundleVersion {
static bundleVersion ()
{
EditorApplication.update += Update;
}
static void Update ()
{
string month;
if (System.DateTime.Now.Month<=9) {
month="0"+System.DateTime.Now.Month;
}
else{
month=System.DateTime.Now.Month.ToString();
}
string day;
if (System.DateTime.Now.Day<=9) {
day="0"+System.DateTime.Now.Day;
}
else{
day=System.DateTime.Now.Day.ToString();
}
string hour;
if (System.DateTime.Now.Hour<=9) {
hour="0"+System.DateTime.Now.Hour;
}
else{
hour=System.DateTime.Now.Hour.ToString();
}
string minute;
if (System.DateTime.Now.Minute<=9) {
minute="0"+System.DateTime.Now.Minute;
}
else{
minute=System.DateTime.Now.Minute.ToString();
}
PlayerSettings.bundleVersion = "1.202."+month+day+hour+minute;
}
}
put this in a file called “bundleVersion.cs” inside /Assets/Editor folder.