- Home /
 
Set Bundle Version Code through editor script
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.
Thanks in advance,
Answer by FHRaph · Feb 06, 2013 at 09:33 PM
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.
Answer by GerryM · Feb 06, 2013 at 08:48 PM
You can easily change the bundle version (it's a string) to anything you like with an editor script:
 [MenuItem("Test/Set Bundle Version")]    
 static void SetBundle()
 {
     PlayerSettings.bundleVersion = "1-1";    
 }    
 
               Also, check the scripting reference for all settings.
I was actually referring to the BundleVersionCode which is an android specific value. I just didn't think to look at PlayerSettings.Android.BundleVersionCode. Thanks though.
True, my bad, BundleVersionCode is kind of hidden:
 PlayerSettings.Android.bundleVersionCode  = 1;
 
                 Answer by obi_juan_ · Mar 10, 2015 at 02:39 PM
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.
Your answer