1

I am trying to build my project from the command line targeting iOS. When I build this from the editor, everything works! I have a PostProcess build script that I use.

When I try to build form the command line using the following command: /Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod BuildScript.BuildIOS -nographics -buildTarget iOS

I am getting an error from my PostProcess build script saying: Assets/Editor/MyBuildPostprocessor.cs(9,23): error CS0234: The type or namespace name Xcode' does not exist in the namespaceUnityEditor.iOS'. Are you missing an assembly reference?

The line that generates the error is a simple using clause:

using UnityEditor.iOS.Xcode;

So it seems that for some reason, the command line build mechanism does not recognise the UnityEditor.iOS.Xcode assembly, and my PostProcess build script cannot run.

Any ideas?

1 Answer 1

1

This is a known case when iOS project is built manually in Unity without errors and fails building on build-server (Unity cloud, Jenkins, TeamCity and others). I think that your case is similar with it. Because if you take a look at the build-server process of building Unity app you'll see that it also uses command line command

/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod BuildScript.BuildIOS -nographics -buildTarget iOS

As for build-server issue, the solution is to put all your post-process scripts inside #if UNITY_IOS condition. And it's possible that you've misunderstood the error you get. Unity says that it doesn't understand XCode namespace while trying to include your post-process script inside your build. And of course, Unity can't include XCode namespace because it's available in Unity Editor only.

So try adding #if UNITY_IOS at the very beginning of your post-process source, even before using section and #endif the the very end of the source. In this case Unity won't compile post-process script during building phase, but will call your post-process script after XCode project will be created.

Unfortunately, I couldn't find any information why manual and command line build processes differ.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you @vmchar for answering. My post-process script already includes a #if UNITY_IOS condition around it, so it's not that..
I found that the parameter -buildTarget iOS was the only way to make Unity actually define UNITY_IOS. Without it, the define was not there and our builds would fail because of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.