How can I get "Bundle Version" and "Bundle Version Code" through script?

I need to show Bundle Version and Bundle Version Code in my application,
but looks like PlayerSettings class has no function to get these two.
Can I get this information like PlayerSettings.iPhoneBundleIdentifier for iPhone application?
Thanks in advance.

Until we add this information you will need to use need to use plugins to access Java to retrieve that info. I believe it’s not available on iPhone either. Please submit a bug report (‘feature request’) if you need this.

1 Like

Thank you.
I will submit a feature request. :slight_smile:

So, 5 years ago you did request this feature, is it available now? :slight_smile:
Seems like we still cannot get Bundle Version and Bundle Version Code in application?
It could be convenient, because now to show current version in game menu we have to set proper version by hands.

I’m new to Unity and currently stuck with this too. Anyone has solution?

I use a build script that saves the build info in a text file in a Resources folder, so I can read it during runtime.

What about

PlayerSettings.Android.bundleVersionCode
PlayerSettings.bundleVersion

Wouldn’t they work for what you want?

6 Likes

@CesarNascimento Those are only available from Editor scripts, not runtime.

3 years and this is one of the first results on Google when searching for this.

Anyway, using this:

Application.version

You can get a string with the Version of the app (set in PlayerSettings).
This works on Android and iOS, and I believe in PC too. But I don’t know yet a way to get the Bundle Package Version Code (or Bundle Version, in iOS) in runtime yet.

Maybe this can be usefull: c# - Get App Bundle Version in Unity3d - Stack Overflow

9 Likes

Hi, you can use this code to get Bundle version code or package name.

AndroidJavaClass up = new AndroidJavaClass(“com.unity3d.player.UnityPlayer”);

var ca = up.GetStatic(“currentActivity”);

AndroidJavaObject packageManager = ca.Call(“getPackageManager”);

var pInfo = packageManager.Call(“getPackageInfo”, Application.bundleIdentifier, 0);

Debug.Log(“versionCode:” + pInfo.Get(“versionCode”));

3 Likes

Hmm, that code doesn’t compile for me, even when building for Android;

Is there still no cross-platform way to get the bundle version?

@JoeStrout Unfortunately there’s not. Unity is considering an unified API call for this (response to non-public Case 1024033).
Since Unity 5.6.0b6 the API call you receive the error for has changed:

1 Like

It’s rather troubling that this feature has been requested 9 years ago and still nothing. I’m not certain of the volume of feature requests, but what is the rate of completion for feature requests anyway? Are those given any priority at all?

I feel like this could be a very easy change to make on UT’s side, can we get access to the bundle version code (Android) or build number (iOS) during runtime? The same way we now have access to the bundle identifier in Application.identifier - Can’t there be an Application.buildNumber ?

2 Likes

Bumping, have to set text files EVERY time I upload, just that extra stupid step ;/

1 Like

Agreed. This is hard for us to do, but easy for Unity, with no unpleasant side-effects that I can see… weird that we still don’t have it.

1 Like

Too bad we can’t access this feature. I am afraid I will forget to change the version code from the editor text.
But!!!
Texmeshpro versionText;
String version;

Void Awake()
{
version = Application.version
versionText. text = version;
}
//seems to work just fine.

1 Like

But it is available.

You can set your game version string via

PlayerSettings.bundleVersion

And you can set your bundleVersionCode for Android via

PlayerSettings.Android.bundleVersionCode

or for iOS

PlayerSettings.iOS.buildNumber
3 Likes

But PlayerSettings is in the UnityEditor namespace. It’s not available at runtime, is it?

2 Likes

In general, in cases like these, you could write a pre-build script/hook that, at build time, reads the info from PlayerSettings and generates a file (JSON, scriptableObject, whatever) that you can read at runtime to populate the text field with.

Details on how to do that would make an excellent blog or forum post!