Search Unity

Application version

Discussion in 'Web' started by agarcialeon, May 15, 2018.

  1. agarcialeon

    agarcialeon

    Joined:
    Sep 4, 2014
    Posts:
    8
    I've seen that WebGL platform doesn't contains the application version number in the Other settings section inside the Player Settings.

    I've tried to get Application.version from a script in a empty scene and I'm getting the 1.0 value.

    Is there any way to set the application version for my application and update it with scripts in Unity Editor so I can show the current version during runtime?

    Thanks
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    I think PlayerSettings.bundleVersion is what you are looking for.
     
  3. agarcialeon

    agarcialeon

    Joined:
    Sep 4, 2014
    Posts:
    8
    Sorry, but I already know about bundleVersion and it only works in the editor.

    I was thinking more in a field that I could show at runtime for WebGL builds. So with each build I can increment it and show the appropiate version to the user inside the browser.
     
  4. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
  5. agarcialeon

    agarcialeon

    Joined:
    Sep 4, 2014
    Posts:
    8
    @douglassophies Sorry for the late response, but I haven't checked the forums during a while.
    About a solution for the problem, I had to change manually the version number in a Text Mesh Pro uGUI component that I have on the first screen of my application. Without any change during the last versions of Unity (I'm currently on 2018.1.3 f1) I can only think in making a custom editor window that checks for the version number in a text component and update it whenever you make a new build or something similar.

    It should be easier if it was like on mobile platforms but I don't think they will take this as a priority.
     
  6. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    Thanks for the reply. I ended up doing just as you say. I wanted it automatically incrementing so i catch the build event and add to a value i store in a text file which is committed to Git so the team have it too. Still possible that a team member builds as i do and we get the same version but its good enough for our needs.
     
  7. kou_yeung

    kou_yeung

    Joined:
    Mar 24, 2016
    Posts:
    28
    my solution is create a file named "AppVersion.jslib.temp"
    Code (JavaScript):
    1. // Path:Assets/Plugins/WebGL/AppVersion.jslib.temp
    2. mergeInto(LibraryManager.library,
    3. {
    4.   BundleVersion: function ()
    5.   {
    6.     var returnStr = "{{BUNDLE_VERSION}}";
    7.  
    8.     var bufferSize = lengthBytesUTF8(returnStr) + 1;
    9.     var buffer = _malloc(bufferSize);
    10.     stringToUTF8(returnStr, buffer, bufferSize);
    11.     return buffer;
    12.   },
    13. });
    14.  
    next, write a custom IPreprocessBuildWithReport
    Code (CSharp):
    1. // Path : Assets/Editor/GenAppVersionBuildProcessor.cs
    2. using UnityEditor;
    3. using UnityEditor.Build;
    4. using UnityEditor.Build.Reporting;
    5. using UnityEngine;
    6. using System.IO;
    7. using System.Linq;
    8.  
    9. class GenAppVersionBuildProcessor : IPreprocessBuildWithReport
    10. {
    11.     public int callbackOrder { get { return 0; } }
    12.  
    13.     public void OnPreprocessBuild(BuildReport report)
    14.     {
    15.         var fn = Directory.GetFiles(Application.dataPath, "AppVersion.jslib.temp", SearchOption.AllDirectories).First();
    16.         var temp = File.ReadAllText(fn);
    17.         temp = temp.Replace("{{BUNDLE_VERSION}}", PlayerSettings.bundleVersion);
    18.         File.WriteAllText(Path.ChangeExtension(fn, null), temp);
    19.         AssetDatabase.Refresh();
    20.     }
    21. }
    this can replace the {{BUNDLE_VERSION}} from *.temp file and output a *.jslib

    and create a cs file to call WebGLPlugins
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Runtime.InteropServices;
    5.  
    6. public static class AppVersion
    7. {
    8. #if UNITY_WEBGL && !UNITY_EDITOR
    9.     [DllImport("__Internal")]
    10.     public static extern string BundleVersion();
    11. #else
    12.     public static string BundleVersion() { return "Only work on WebGL Build!!"; }
    13.  
    14. #endif
    15.  
    16. }
    17.  
    how to use
    Code (CSharp):
    1. var bundleVersion = gameObject.GetComponent<Text>();
    2. bundleVersion.text = AppVersion.BundleVersion();
    3.  
     
  8. afftar

    afftar

    Joined:
    Apr 18, 2014
    Posts:
    65
    I just updated to 2017.4.19f1 and found the same problem in the build on Android. Its critical bug - i cant post game to google store with elder application version.
     
  9. flashmandv

    flashmandv

    Joined:
    Mar 26, 2015
    Posts:
    156
    Same bug here! In editor the Application.version is OK, but in runtime android, it shows 1.0
    Unity 2019.1.3d1 (latest "stable").
    It is strange that if I start new blank project, it works OK...but even if I copy the ProjectSettints.asset file into my main project, the bug is still there..
     
  10. unity_91BnGyqxSYUPdQ

    unity_91BnGyqxSYUPdQ

    Joined:
    Aug 7, 2018
    Posts:
    25
    Guy Im getting the same error, I am using Unity version 2017.4.27f1. In Android runtime the version number changes to 1.0 in the editor its working fine.

    We figured out the solution is after exporting the Unity Android Project open the project in Android Studio and then in the Main AndroidManifest Update the following tags

    android:versionName="Your Version No" android:versionCode="Your Version Code".
     
    Last edited: May 29, 2019
    mizuguchi_jp17000 likes this.
  11. flashmandv

    flashmandv

    Joined:
    Mar 26, 2015
    Posts:
    156
    In my case it turned out that the mainTemplate.gradle file was missing:
    applicationId '**APPLICATIONID**'
    versionCode **VERSIONCODE**
    versionName '**VERSIONNAME**'


    It was strange because I copied this template from the latest Unity installation 2019.1.4
    Anyway, manually putting it in my gradle file fixed the problem
     
    mizuguchi_jp17000 likes this.
  12. bart42

    bart42

    Joined:
    Dec 29, 2014
    Posts:
    5
    UPDATE! this is an old thread. Application.version works in WebGL build!. It was probably an old bug that has been fixed many years ago. Please someone at Unity update this thread as it leads to false information at the moment if you don't read carefully like I did. Thanks