Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Automatic application verison using Pre-Export method in UCB

Discussion in 'Unity Build Automation' started by peetonn, Jul 9, 2018.

  1. peetonn

    peetonn

    Joined:
    Jul 24, 2017
    Posts:
    5
    I have three types of clients for the same app: Android, macOS and Windows.
    I need to set application build version based on source control commit id and UCB build number, like

    X.<build#>.<SCM-commit-id>

    where X is major version number set by a developer.
    I followed this link - https://docs.unity3d.com/Manual/UnityCloudBuildManifestAsScriptableObject.html and used PlayerSettings.bundleVersion however, it did not work for Android app.
    I then added this code for CloudBuildHelper :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5. using System;
    6.  
    7. public class CloudBuildHelper : MonoBehaviour
    8. {
    9. #if UNITY_CLOUD_BUILD
    10.     public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest)
    11.     {
    12.         string buildVersion = String.Format("0.{0}.{1}",
    13.                                         manifest.GetValue("buildNumber", "unknown"),
    14.                                         manifest.GetValue("scmCommitId", "unknown"));
    15.         PlayerSettings.bundleVersion = buildVersion;
    16.         PlayerSettings.macOS.buildNumber = buildVersion;
    17.         PlayerSettings.iOS.buildNumber = buildVersion;
    18.     }
    19. #endif
    20. }
    However, it doesn't work either.
    How can I set up build version programmatically using Pre-Export method for Unity Cloud Build?
     
  2. Robert_231Play

    Robert_231Play

    Joined:
    Jun 13, 2016
    Posts:
    6
    We have almost the same problem. We use our own buildmaschine, on which we run Unity in batchmode with commandlinearguments.

    We are setting the PlayerSettings.bundleVersion and PlayerSettings.Android.bundleVersionCode with some values
    and doing a build with BuildPipeline.BuildPlayer(buildPlayerOptions);

    After the build the ProjectSettings.asset is correctly updated, unfortunately the builded APK is not reflecting the changes made to bundleVersion and bundleVersionCode.

    In Unity 2017 it has worked, but in Unity 2018.1.9f1 it seems not to work correctly...
     
  3. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    For android you need to set the PlayerSettings.Android.bundleVersionCode, which is an integer, that you will have to generate . So you may be in trouble with your scmCommitId ...
    For me setting this value works well in the PreExport .
     
  4. ttermeer-reboundcg

    ttermeer-reboundcg

    Joined:
    Jul 12, 2017
    Posts:
    62
    If your end goal is to display in your app a formatted version number that includes letters, I strongly suggest using the UnityCloudBuildManifest.json which is automatically added to your app. It contains all information including the commit ID.
     
    freyes_unity likes this.
  5. pfleetwood22

    pfleetwood22

    Joined:
    Jun 6, 2016
    Posts:
    28
    We also are seeing a breaking change going from 2017 to 2018. It appears the issue could be a subtle change in the documentation for PlayerSettings.Android.bundleVersionCode. Note the additional part about the value constraint. Our bundleVersionCodes (for an already shipping game that requires increases to this value) is greater than 1 million.

    2017.4 documentation: https://docs.unity3d.com/2017.4/Doc...PlayerSettings.Android-bundleVersionCode.html
    2018.2 documentation: https://docs.unity3d.com/ScriptReference/PlayerSettings.Android-bundleVersionCode.html

    We see our PreExport method run, and we see that PlayerSettings.Android.bundleVersionCode returns the value that we set into it. We also see logging that says:

    [Unity] Will not override android bundleVersionCode - already set in player settings: 6010141
    Finally, once the APK is built, when I run aapt badge on it, it shows the following:

    versionCode='' versionName=''
    EDIT:
    After investigating more, we realized that the note about the constraint on versionBundleCode was new in 2018.2 (and not in the docs for 2018.1, which we are using). Our problem turned out to be changes in the mainTemplate gradle file for 2018.1, which now sets version code and version name in gradle, instead of wherever that was happening before.
     
    Last edited: Sep 26, 2018