Pre-Export Method Failure with no details

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.

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:

using UnityEngine;
using UnityEditor;

public class UnityCloudBuild : MonoBehaviour
{
    public static void OnPreExportIOS()
    {
        Debug.Log("UnityCloudBuild - OnPreExportIOS started");

        FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/Bundles");
        FileUtil.DeleteFileOrDirectory("Assets/StreamingAssets/Bundles.meta");
        Debug.Log("UnityCloudBuild - Going to Refresh");
        AssetDatabase.Refresh();
    }
}

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.

As noted in the docs (Unity Build Automation) the script needs to exist in an Editor/ folder.

1 Like

Thank you. That was my exact error. Not sure how I missed that when reading through the documentation!

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.

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

1 Like

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.

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.

1 Like

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

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

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

Below are my codes

#if UNITY_CLOUD_BUILD
using System;
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;

public class AutoIncrementVersionCodeInCloudBuild : MonoBehaviour
{
    public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest)
    {
        string buildNumber = "";
        buildNumber = manifest.GetValue<String>("buildNumber");
        Debug.LogWarning("Prebuild launched build number to " + buildNumber);
        DebugTool.ClientLog("Setting build number to " + buildNumber);
    }
}
#endif

Any suggestions would be appreciate.

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.

Thanks for the advice, I also remove the DebugTool.ClientLog, and the build can work fine without having any errors

1 Like