Symptoms
My game builds fine locally, but it fails in Unity Build Automation. I need to do a batchmode build test.
Causes
There could be a number of reasons why project builds fail only in Unity Build Automation while it works fine locally. But, first of all, we need to ensure the same problem does not reproduce in the local batchmode environment because Unity Build Automation runs all builds in batchmode, not via the Unity Editor's UI interface.
Resolution
First, you need to either delete the Library folder or check out the source code into a new fresh folder, forcing packages to be re-downloaded. This is to simulate our build server's behavior that checks out the source code on every build.
Here's a Windows and Mac version of the same command. Note that several of these flags are not required. If you do not want to run Unit Tests, you can skip the flags such as the -testPlatform, -testResults, and -runTests. Furthermore, the directories provided are the default installation folders for the Editor, please adjust them according to the correct path on your local machine.
Windows CMD Console:
Mac Terminal:
using UnityEditor;
class MyEditorScript
{
static void PerformBuild ()
{
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.scenes = new[] {"Assets/Scenes/MyScene.unity", ...};
buildPlayerOptions.target = BuildTarget.iOS; // More details on BuildTarget doc
buildPlayerOptions.options = BuildOptions.None;
buildPlayerOptions.locationPathName = "iOSBuild";
BuildPipeline.BuildPlayer(buildPlayerOptions);
}
}
More Information
To learn about all the flags available when running Unity via the command line, please check out our documentation on the Editor's Command-Line Arguments.