1

When clicking "Build and Run" for an iOS project, Unity generates an Xcode project, fires up Xcode, builds the project, and runs it on the device. I'd like to run a shell script after Xcode finishes building but before it runs. If this were a mere Xcode project, I could simply add a "Run Script" entry to the Build Phases tab, but since this project is auto-generated by Unity I'm not sure how to proceed.

(I'm running OS X Yosemite, if it matters.)

Cœur
  • 37,241
  • 25
  • 195
  • 267
blahpers
  • 23
  • 1
  • 4

1 Answers1

3

Depends on how much work you want to put into this.

Solution A: Using Unity's PostProcess

You could use Unity's PostProcess, to modify the Xcode project accordingly. Just mark a static method with the [PostProcessBuild] annotation, and Unity will execute it after the Unity build.

Example:

[PostProcessBuild]
static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
     // modify the Xcode project here, or run the shell script directly (if it is ok to do this already here)
}

Sources:

Solution B: Append the Xcode Project

You could modify your Xcode Project accordingly, and afterwards just use Append when starting the next build and Unity asks what to do, when detecting that the folder already exists.

Solution C: Do it manually

  • Use Build instead of Build And Run
  • Modify the Xcode project after Unity finished it's build
  • Manually Run on the Device using Xcode

Solution D: Run the build in batchmode / use CI like Jenkins

You can invoke the build from the command line (terminal), and do what ever you want during/between the different build steps. But as this is a lot of work, I'd recommend to take a look at a CI like Jenkins. It comes with an installer for Mac OS X and is not that hard to set up. I guess there is a lot of documentation and Q&As about it.

Jenkins: http://jenkins-ci.org


I hope there's something that fits your needs. Just let me know if you need some more help or information. Cheers.

Community
  • 1
  • 1
d4Rk
  • 6,622
  • 5
  • 46
  • 60
  • Thanks, this is a pretty exhaustive list. The likely course in this case is probably using option A to inject a "Run Script" build phase by editing the project file. Unfortunately, the Python library doesn't support adding build phases, but I took a stab at doing it manually and it was no real difficulty. Cheers! – blahpers Jul 27 '15 at 18:25