Unity3d Commandline Autobuild not running postbuild

2.2k Views Asked by At

I'm building for iOS and using the FacebookSDK. And I want to automate thru Jenkins. Now when I "build and Run" in the editor, It builds the xcode project correctly. But when I run it thru the commandline the postbuildprocess never gets run. I can't find anything online about this issues. Anyone have any ideas? Or need any other info to come up with a theory?

Here is the autobuild code:

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

and here is my commandline args:

/Applications/Unity/Unity.app/Contents/MacOS/Unity -projectPath "/Users/USERNAME/Desktop/Work/PROJECTNAME/Unity/"  -executeMethod AutoBuilder.PerformiOSBuild -quit -batchmode
2

There are 2 best solutions below

0
On

I was able to get around this by calling Facebook's PostProcess manually. Here's my build script:

using System;
using UnityEngine;
using UnityEditor;
using UnityEditor.FacebookEditor;

class BuildScript
{
    static void PerformBuild ()
    {
        string[] scenes = { "Assets/monster_island.unity" };
        string buildPath = System.IO.Directory.GetCurrentDirectory() + "/iOS";
        BuildOptions opt = BuildOptions.None;
        BuildTarget target = BuildTarget.iPhone;

        // Run Xcode project build
        BuildPipeline.BuildPlayer(scenes, buildPath, target, opt);

        // Run Facebook's post-processing script
        XCodePostProcess.OnPostProcessBuild(target, buildPath);
    }
}

Keep in mind I'm new to Unity, so if something in here looks gross feel free to say so.

0
On

just found this and the same question at Unity forums, so I'll paste here the same answer that I gave there, one could check through this link.

Hello, sorry to revive this old post but in 2019 it still is one of the top links in Google.

Just had the same problem and what @Brentonb said is still valid, today it is documented in this link for SwitchActiveBuildTarget and it states:

Note: This method is not available when running the Editor in batch mode. This is because changing the build target requires recompiling script code for the given target which cannot be done while script code is executing (not a problem in in the editor as the operation is simply deferred but batch mode will immediately exit after having executed the designated script code). To set the build target to use in batch mode, use the buildTarget command-line switch.

Then I checked here, in the Command line arguments page in the manual, and added -buildTarget Android and -buildTarget iOS for each of the methods of the CI build process.

Now my PostBuild script for iOS executes in batch mode as well.