• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by FHRaph · Feb 06, 2013 at 06:00 PM · androideditorbuildplayersettings

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,

Comment
Graham-Dunnett
Paulius-Liekis
Lohoris2
IggyZuk

People who like this

4 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

  • Sort: 
avatar image
Best Answer

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.

Comment
Graham-Dunnett
Paulius-Liekis
Lohoris2

People who like this

3 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

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.

Comment
Fattie
Lohoris2

People who like this

2 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FHRaph · Feb 06, 2013 at 09:15 PM 0
Share

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.

avatar image GerryM · Feb 07, 2013 at 09:37 PM 2
Share

True, my bad, BundleVersionCode is kind of hidden:

 PlayerSettings.Android.bundleVersionCode  = 1;

avatar image

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.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Do you leave the checkmark on Development Build when building your final signed apk file for upload to Android Market? 1 Answer

Access AndroidTargetDevice (PlayerSettings) from code 1 Answer

How to fix bugs that only appear in the build? 0 Answers

Distribute terrain in zones 3 Answers

Android gradle build error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges