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

ios
osx
unity

#1

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.


#2

Hi @aventurella,

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. After adding in my serial,username,and password the builds worked great. You can see my example project here: https://github.com/GERey/Simple-Mobile-Application. Let me know if you have any further questions!

Best,
George


#3