Unity iOS on Windows: Deploying to iPhone from within Unity Editor on Windows machine, using VMWare

Here is an aid for developing Unity iOS apps on Windows machine. Using VMWare, one can run a shell script on a local virtual machine to automate the entire process of deploying Unity apps from Editor to iPhone via USB. The process is click-and-wait basis and each build should take about 5 minutes. This article proposes some components to manage the automation.

Note: This is a “poor man’s” method and potentially wastes your resource in a long run if you could just buy a Macbook in the first place. Also, please read through and do your own research before fully committing, because there may be some hardware requirements.

Disclaimer: Running any macOS on non-Apple hardware is against the Apple EULA. Please acknowledge the risk and proceed on your own responsibility.

System Overview

So, as long as the script is running on VM, user can press the “Build” button in Unity Editor and hands-free wait until iPhone opens the app automatically.

Setting up Shared Folder

Setting up xcodebuild

Setting up ios-deploy

Setting up Unity C# Post-process Script

Whenever user hits the “Build” button, Unity Editor will compile the project into an XCode project, then this script will update the timestamp.

The build path must be set to inside the Shared Folder.

Setting up Shell Script

The script may be set to login item so that it automatically starts running. The process can be halted it by closing the terminal window.

The Shared Folder is named __transfer_ in the script which may be changed, as well as project name (MyProject) and app name (foo.app). Those names must match with build settings in Unity Editor.

By default, commands like cd and cp can’t access inside Shared Folder (“no such file or directory”). So, the script mounts it in the local drive prior to any other commands:

mkdir -p <target directory path>
sudo mount -t vmhgfs .host:/ <target directory path>

Also, XCode can’t build inside Shared Folder regardless of mounting. So the script works around that by copying the project to desktop and building off there.

Unity projects have a specific format in file names, so some arguments like project/target names can be hard-coded. This command will start the build, print out all the logs and save the product in build directory:

cd <project root>
xcodebuild -project Unity-iPhone.xcodeproj\
-target Unity-iPhone\
-configuration Debug build

Finally the script will deploy the build to a connected iPhone via USB:

cd <project root>/build/debug-iphoneos
ios-deploy --uninstall -- noninteractive --debug --bundle foo.app

Unity’s remote profiler feature does work, as long as Windows and iPhone are connected to the same WiFi. User can also make a use of runtime logs printed out to terminal by ios-deploy.

With all set, user can press the “Build” button in Unity Editor and observe the shell script reacting to it as soon as Unity finishes composing the project in Shared Folder. Then the script will start building and deploying to connected iPhone. The script will go back in the main loop as soon as the app is closed or crashes on the device.

Conclusion

Software engineer specialized in 3DCG and mobile app development using game engines.