Unity Automated / Command Line Build fails to output iOS / Xcode Project

So I have a CI build system setup for a unity project, however it seems that I am doing something wrong the I go to build the project from the command line. The doesn’t error out, but it also doesn’t generate the expected iOS files.

So for starters I am using CircleCI as my build platform, using their OS X build machines. If I run the build script locally it works, it’s only when I run it from the CI box that it fails. By fails I mean does not output anything. There appear to be no explicit errors in the log.

I have the machine setup as follows:

machine:
  environment:
    GYM_CODE_SIGNING_IDENTITY: "iPhone Distribution: Acme Inc. (FAKEVALUE)"
    XCODE_SCHEME: "Unity-iPhone"
    XCODE_PROJECT: "Unity-iPhone.xcodeproj"

  pre:
    - curl -o Unity.pkg http://netstorage.unity3d.com/unity/960ebf59018a/MacEditorInstaller/Unity-5.3.5f1.pkg
    - curl -o Unity-iOS.pkg http://netstorage.unity3d.com/unity/960ebf59018a/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-5.3.5f1.pkg
    - sudo installer -dumplog -package Unity.pkg -target /
    - sudo installer -dumplog -package Unity-iOS.pkg -target /

  xcode:
    version: "7.3"

test:
  override:
    - mkdir -p Unity/Builds/iOS
    - /Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -quit -nographics -projectPath $PWD/Unity/MyProject -logFile /dev/stdout -executeMethod CommandLineBuild.iOSBuild

I’m omitting the deployment configuration as it always fails since the CommandLineBuild.iOSBuild fails to output the iOS project.

Here is the contents of that build script, first the short version:

using UnityEngine;
using UnityEditor;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.IO;

public static class CommandLineBuild {

    [MenuItem("File/CommandLineBuild/iOS")]
    static void iOSBuild ()
    {
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.iOS);
        var scenes = { "Assets/Scenes/SplashScreen.unity" };
        var opts = BuildOptions.None;
    
        BuildPipeline.BuildPlayer(scenes, "../Builds/iOS", BuildTarget.iOS, opts);
    }
}

This didn’t work in it’s simple form, again the problem is that the iOS Xcode project is not output.

So then I tried to get fancier, and add additional options thinking that was the issue:

using UnityEngine;
using UnityEditor;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.IO;

//0 - ARMv7
//1 - ARM64
//2 - Universal

// http://forum.unity3d.com/threads/4-6-ios-64-bit-beta.290551/page-9#post-1948394
enum ArchitectureValue {
    ARMv7,
    ARM64,
    Universal
}

public static class CommandLineBuild {

    [MenuItem("File/CommandLineBuild/iOS")]
    static void iOSBuild ()
    {
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.iOS);

        PlayerSettings.companyName = "MyCompany";
        PlayerSettings.productName = "MyProject";
        PlayerSettings.bundleVersion = "1.0";
        PlayerSettings.iOS.buildNumber = "101";
        PlayerSettings.statusBarHidden = true;
        PlayerSettings.useAnimatedAutorotation = true;
        PlayerSettings.bundleIdentifier = "com.mycompany.MyProject";
        PlayerSettings.iPhoneBundleIdentifier = "com.mycompany.MyProject";

        PlayerSettings.iOS.targetDevice = iOSTargetDevice.iPhoneAndiPad;
        PlayerSettings.iOS.appInBackgroundBehavior = iOSAppInBackgroundBehavior.Suspend;
        PlayerSettings.iOS.sdkVersion = iOSSdkVersion.DeviceSDK;
        PlayerSettings.iOS.targetOSVersion = iOSTargetOSVersion.iOS_6_0;
        PlayerSettings.iOS.allowHTTPDownload = true;
        PlayerSettings.iOS.requiresFullScreen = true;

        // http://forum.unity3d.com/threads/4-6-ios-64-bit-beta.290551/page-9#post-1948394
        PlayerSettings.SetPropertyInt(
            "ScriptingBackend",
            (int)ScriptingImplementation.IL2CPP, 
            BuildTargetGroup.iOS
        );

        PlayerSettings.SetPropertyInt(
            "Architecture",
            (int)ArchitectureValue.Universal, 
            BuildTargetGroup.iOS
        );

        string[] scenes = { "Assets/Scenes/SplashScreen.unity" };
        var opts = BuildOptions.Il2CPP;
    
        BuildPipeline.BuildPlayer(scenes, "../Builds/iOS", BuildTarget.iOS, opts);
    }
}

Anyway, under both build scripts the result is the same. It runs, no errors are in the logs, but also not Xcode Project is output.

Hi @aventurella/ @nephenmaat,

This is more or less a copy/paste of the response on the CircleCI forums, but figured this might help out the people who check this here instead of there. I also won’t check this as often as the CircleCI forums :p.

Sorry for taking so long to respond to this. I recently went through and created a sample project to highlight your issues and had the same problem. You are right that you need to remove the -nographics as I believe iOS builds require a graphics driver of some sort. After removing -nographics, I got the following two errors in the log files:

Building a player for 'iPhone' (9) target is not supported in this Unity build

Switching to iOSSupport is disabled

It turns out that Unity requires a pro license in order to build iOS projects. I don’t believe there is any other way. After adding in my serial,username,and password the builds worked great. You can see my example project here: GitHub - GERey/Simple-Mobile-Application: unity build and test runner. Let me know if you have any further questions!

Best,
George

ok, so it seems like -nographics maybe have been the problem. Now however it wants me activate a license?

This may be me just misunderstanding the difference between Pro/Personal. I guess they don’t want you to do automated builds on Personal?

DisplayProgressbar: Unity license
Cancelling DisplayDialog: Failed to activate/update license. Missing or bad username and password. Please try again using valid credentials or contact support@unity3d.com
This should not be called in batch mode.
 
(Filename: /Users/builduser/buildslave/unity/build/Editor/Platform/OSX/EditorUtility.mm Line: 729)

I can pass my -username and -password (no -serial) and it still fails (assuming I need that serial).

Anyway is that the issue here, only Pro lets you do automated builds? Is there a way to activate unity with a personal license from the command line?

the same problem, i have not found how to fix this yet, so bad.