5
\$\begingroup\$

I am doing the iOS builds for a group of Unity (Unity3d) game developers.

After pulling the latest git updates, I start up the Unity editor on my Mac and choose "Build Settings", select the iOS target platform, press Build, specify a destination folder and that is it.

Can this exact process be done automatically via the terminal prompt?

\$\endgroup\$

1 Answer 1

12
\$\begingroup\$

Android and iOS are not directly supported by the command line utility. However, you can use the command line utility to run a script that will build for iOS. In the simplest form, it would be something like:

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

public static class AutoBuilder {

    static string GetProjectName()
    {
        string[] s = Application.dataPath.Split('/');
        return s[s.Length - 2];
    }

    static string[] GetScenePaths()
    {
        string[] scenes = new string[EditorBuildSettings.scenes.Length];

        for(int i = 0; i < scenes.Length; i++)
        {
            scenes[i] = EditorBuildSettings.scenes[i].path;
        }

        return scenes;
    }
    [MenuItem("File/AutoBuilder/iOS")]
    static void PerformiOSBuild ()
    {
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.iPhone);
        BuildPipeline.BuildPlayer(GetScenePaths(), "Builds/iOS",BuildTarget.iPhone,BuildOptions.None);
    }
}

Then, you would call this from the command line with

-executeMethod AutoBuilder.PerformiOSBuild
\$\endgroup\$
2
  • \$\begingroup\$ How do you change the build target? \$\endgroup\$
    – Ali
    Jan 19, 2018 at 14:35
  • 1
    \$\begingroup\$ @Ali Check out the BuildTarget enum in the BuildPlayer and SwitchActiveBuildTarget methods. \$\endgroup\$
    – House
    Jan 20, 2018 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .