Search Unity

Pre-Export Method Failure with no details

Discussion in 'Unity Build Automation' started by acastenmiller, Aug 9, 2017.

  1. acastenmiller

    acastenmiller

    Joined:
    Sep 15, 2016
    Posts:
    4
    I attempted an iOS build using Unity Cloud Build successfully. I then attempted to add in a Pre-Export Method, but it keeps failing with no explanation.

    Code (CSharp):
    1. 29602: [Unity] ERROR: preExportMethod 'UnityCloudBuild.OnPreExportIOS' failed, aborting.
    After reading previous topics related to this, I believe the reason may be because the method can't be found, but I'm not sure why that is. I don't receive any of the Debug logs I manually added, which is another reason I think it can't be found.

    My code is as follows:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4.  
    5. public class UnityCloudBuild : MonoBehaviour
    6. {
    7.     public static void OnPreExportIOS()
    8.     {
    9.         Debug.Log("UnityCloudBuild - OnPreExportIOS started");
    10.  
    11.         FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/Bundles");
    12.         FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/Bundles.meta");
    13.         Debug.Log("UnityCloudBuild - Going to Refresh");
    14.         AssetDatabase.Refresh();
    15.     }
    16. }
    17.  
    18.  
    This is saved within a script in my project, under Assets/Scripts/UnityCloudBuild/UnityCloudBuild.cs

    And in the Advanced Options > Pre-Export I enter it as: UnityCloudBuild.OnPreExportIOS

    The build has failed after about 2 hours both times, so it's a bit frustrating not knowing why. Any suggestions would be great.
     
  2. dannyd

    dannyd

    Unity Technologies

    Joined:
    Jun 3, 2014
    Posts:
    785
    ChernyakAG likes this.
  3. acastenmiller

    acastenmiller

    Joined:
    Sep 15, 2016
    Posts:
    4
    Thank you. That was my exact error. Not sure how I missed that when reading through the documentation!
     
  4. Desoxi

    Desoxi

    Joined:
    Apr 12, 2015
    Posts:
    195
    The docs also state that you optionally can add a parameter of type "UnityEngine.CloudBuild.BuildManifestObject",
    But i cant seem to be able to use that CloudBuild namespace. Any news about this?
    On the cloud build page it uses the same example, which is a bit irritating.
     
  5. HaakonL

    HaakonL

    Joined:
    Mar 13, 2014
    Posts:
    123
    You need to wrap the whole class in a compiler directive, the BuildManifestObject is only available on the cloud build servers apparently.

    For example

    #if UNITY_CLOUD_BUILD
    using UnityEngine;
    using UnityEditor;
    using System;

    public class CloudBuildHelper : MonoBehaviour
    {
    public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest)
    {
    PlayerSettings.bundleVersion = $"1.0.{manifest.GetValue("buildNumber", "unknown")}";
    }
    }
    #endif
     
    Desoxi likes this.
  6. NonPlayerCorey

    NonPlayerCorey

    Joined:
    Aug 13, 2015
    Posts:
    14
    Hi friends, does that manifest provide the build number specifically listed in the cloud build history? Or is it whatever is set within the project. I would prefer to automatically use the cloud build numbering system.
     
  7. dannyd

    dannyd

    Unity Technologies

    Joined:
    Jun 3, 2014
    Posts:
    785
    Yes the manifest provides the build number that will match the number in the Unity Cloud Build history. It's available as "buildNumber" in the manifest.
     
    NonPlayerCorey likes this.
  8. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Just going to assume assembly definition files don't work with this. Because that would appear to be the case.

    Edit: Actually nevermind, cloud build just randomly failed, building again succeeded
     
    Last edited: Mar 31, 2018
  9. elaine_unity694

    elaine_unity694

    Joined:
    Oct 12, 2020
    Posts:
    26
    Hi friends, I attempted to add Pre-Export method to retrieve the build number from the cloud build. But I keep receiving build failed.

    Below are the errors
    upload_2021-2-15_21-1-30.png

    upload_2021-2-15_21-2-7.png


    In both iOS and android
    Advanced Options > Pre-Export I enter it as: AutoIncrementVersionCodeInCloudBuild.PreExport

    Below are my codes
    Code (CSharp):
    1.  
    2. #if UNITY_CLOUD_BUILD
    3. using System;
    4. using UnityEngine;
    5. using UnityEditor;
    6. using System.Collections;
    7. using System.Collections.Generic;
    8.  
    9. public class AutoIncrementVersionCodeInCloudBuild : MonoBehaviour
    10. {
    11.     public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest)
    12.     {
    13.         string buildNumber = "";
    14.         buildNumber = manifest.GetValue<String>("buildNumber");
    15.         Debug.LogWarning("Prebuild launched build number to " + buildNumber);
    16.         DebugTool.ClientLog("Setting build number to " + buildNumber);
    17.     }
    18. }
    19. #endif
    Any suggestions would be appreciate.
     
  10. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
    Your pre-export function can't be in a class that's derived from a MonoBehaviour. If you remove the MonoBehaviour part it should work ok.
     
  11. elaine_unity694

    elaine_unity694

    Joined:
    Oct 12, 2020
    Posts:
    26
    Thanks for the advice, I also remove the DebugTool.ClientLog, and the build can work fine without having any errors
     
    tonemcbride likes this.