# Building on Unity with Bitrise

**URL:** https://discuss.bitrise.io/t/building-on-unity-with-bitrise/23185
**Category:** Building on Unity
**Created:** [August 15, 2023, 6:23pm UTC](https://discuss.bitrise.io/t/building-on-unity-with-bitrise/23185 "2023-08-15T18:23:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MadsRoothman](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/madsroothman/32/4489_2.png) [@MadsRoothman](https://discuss.bitrise.io/u/MadsRoothman)
#### Post date: [August 15, 2023, 6:23pm UTC](https://discuss.bitrise.io/t/building-on-unity-with-bitrise/23185/1 "2023-08-15T18:23:27Z")

</div>

![blog_bitrise_unity_2400x1060 (1)](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/1/1c1b8a449be5329b59bfcf8c296a43d114a10255.jpeg)

You can automate your Unity builds on Bitrise.

## How to add your Unity project to Bitrise?

Unity is not supported 1-on-1 on Bitrise, but there is a way to setup your projects and then to test, build and release your games as fast as any other apps of a different project type. As this is a cross-platform project, in the end you’ll get an IPA and an APK too, hooray! It is really easy to release them, innit? Let us give you a hand to get there. 🖐

When you set up your project, don’t use the scanner but choose the other/custom option…

 ![606127b95af6eb41b982b929_unity-skip-scanner](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/9/9235dcaef3841e129721a88bb29be1051bf9f0c8.png)

…and choose a iOS stack.

 ![6481bf1dceaac1f822d1f8de_3cc1e177](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/9/933aa2a007c62edb94a99cb01d177b4781b37154.png)

### Download and install

This is a script that downloads the version of Unity you choose, so you can choose whichever matches your project. Install the editor and then you’ll need its Android and iOS platforms too.

Let’s see an example: if you want to use Unity2021.3.12f1, you need to look up the package hash at [Download Archive](https://unity.com/releases/editor/archive). Look for the download link under the installer:

 ![6481c048cf1982531ba76136_8f9af872-1](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/4/45d703b3c4c6ba4f4e0a310e4eb0de320d630b20.png)

Example on how to install the editor and the two platform support packages (Android & iOS):

```auto
#workaround for .NET issue https://github.com/dotnet/runtime/issues/64103
export COMPlus_ReadyToRun=0
envman add --key COMPlus_ReadyToRun --value 0

#download unity pkg for Apple Silicon
curl -o ./unity.pkg http://download.unity3d.com/download_unity/8af3c3e441b1/MacEditorInstallerArm64/Unity-2021.3.12f1.pkg

#download android support platform
curl -o ./android.pkg http://download.unity3d.com/download_unity/8af3c3e441b1/MacEditorTargetInstaller/UnitySetup-Android-Support-for-Editor-2021.3.12f1.pkg

#download iOSle support
curl -o ./ios.pkg http://download.unity3d.com/download_unity/8af3c3e441b1/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-2021.3.12f1.pkg

```

If you would like to use the rosetta supported unity MacEditorInstaller for compatibility with slower performance, use this command to install it:

```auto
#download unity pkg for Apple Silicon with Rosetta support
curl -o ./unity.pkg http://download.unity3d.com/download_unity/8af3c3e441b1/MacEditorInstaller/Unity-2021.3.12f1.pkg

```

After installation you will find Unity in the following location:

```auto
/Applications/Unity/Unity.app/Contents/MacOS/Unity

```

For running Unity we need Cacerts.pem to be placed at the right location. Unity will generate this file for us, so let’s run it for the first time.

```auto
/Applications/Unity/Unity.app/Contents/MacOS/Unity -logfile &
sleep 15
sudo killall Unity

```

### License activation

You’ll need to have a valid license key to build Unity projects. Only paid plans are working through the command line - and therefore in Bitrise.

> _Running the Personal (free) version needs activation through the UI and using your personal serial number._

To activate your license key use the following code, which will activate the license and link the VM with your account:

```auto
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -serial "$UNITY_SERIAL" -username "$UNITY_EMAIL" -password "$UNITY_PW" -logfile

```

### Building your project

Now let’s jump to a more interesting part, building your app!

By inserting this script to your workflow you can start building your Unity apps. In the end it will generate an APK for your Android app and an IPA for your iOS app.

You’ll need this for Android:

```auto
/Applications/Unity/Unity.app/Contents/MacOS/Unity -nographics -quit -batchmode -logFile -projectPath "$BITRISE_SOURCE_DIR" -executeMethod BitriseUnity.Build -androidSdkPath "$ANDROID_HOME" -buildOutput "$BITRISE_DEPLOY_DIR/mygame.apk" -buildPlatform android

```

… and this for iOS:

```auto
/Applications/Unity/Unity.app/Contents/MacOS/Unity -nographics -quit -batchmode -logFile -projectPath "$BITRISE_SOURCE_DIR" -executeMethod BitriseUnity.Build -buildOutput "$BITRISE_SOURCE_DIR/xcodebuild" -buildPlatform ios

```

An Xcode project will be generated, and that will have to be built in the usual way to obtain the IPA.

### Deactivation

We’ve already connected your license with the actual virtual machine, but we have to make sure it’s deactivated at the end, so you will be able to re-use it. If you fail to deactivate the license you can still contact Unity helpdesk and get it sorted out, but it is way simpler to do it here 😊

To make sure it’s deactivated add the following script step to your workflow:

```auto
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -logFile -returnlicense

```

Set the step to _Run even if previous Step failed_ otherwise you risk that it won’t get deactivated if your build fails!

![60612876d9ca4d65ae0ea913_run-if-prev-step-failed](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/a/afca43f778f76b7b0256b3e007f9ca4619489be6.png)

This is what a finished build looks like on Bitrise. Pretty cool, eh?

 ![Screenshot 2023-08-15 at 11.20.17](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/7/752f48892ab93b8a527e45b353b0ac30520eefc8.png)

As you can see there is an iOS.ipa and an Android.apk generated in one build! Next time you’ll use this, it’ll be as quick as all your other apps! 🙂

**Do you have any more questions?** [**There is a more detailed description of Unity projects available**](https://discuss.bitrise.io/t/how-to-build-a-unity-project/1317?utm_source=bitriseblog&utm_medium=web&utm_campaign=17w32unity) **.**

Happy building!

_This post originally appeared on our blog [here](https://bitrise.io/blog/post/unity-for-the-win-on-bitrise-too)._

---

<div class="post-metadata">

### Author: ![Nuvolore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/nuvolore/32/5276_2.png) [@Nuvolore](https://discuss.bitrise.io/u/Nuvolore)
#### Post date: [August 16, 2023, 3:26pm UTC](https://discuss.bitrise.io/t/building-on-unity-with-bitrise/23185/2 "2023-08-16T15:26:48Z")

</div>

Is there a missing step between “…and choose a iOS stack.” and " Download and install"?  
in the UI I do not see any terminal to write those commands when I select iOS.

---

<div class="post-metadata">

### Author: ![atanas-bitrise](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@atanas-bitrise](https://discuss.bitrise.io/u/atanas-bitrise)
#### Post date: [August 16, 2023, 5:28pm UTC](https://discuss.bitrise.io/t/building-on-unity-with-bitrise/23185/3 "2023-08-16T17:28:08Z")

</div>

Hello @Nuvolore,

Yes, there is a missing step. Once you choose an iOS Stack, you will have a minimal workflow added to your workspace. You can edit this workflow or create a new one with the workflow editor. You can add the commands in a Script Step. You should have it inserted in the minimal workflow already.

Best,  
Atanas

---

<div class="post-metadata">

### Author: ![Nuvolore](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/nuvolore/32/5276_2.png) [@Nuvolore](https://discuss.bitrise.io/u/Nuvolore)
#### Post date: [August 16, 2023, 5:57pm UTC](https://discuss.bitrise.io/t/building-on-unity-with-bitrise/23185/4 "2023-08-16T17:57:25Z")

</div>

Thanks, would the Script Step you are referring to be the “bitrise.yml”? In that case where would the “Download” command lines be inserted, at which point in the jobs?

---

<div class="post-metadata">

### Author: ![atanas-bitrise](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@atanas-bitrise](https://discuss.bitrise.io/u/atanas-bitrise)
#### Post date: [August 17, 2023, 8:33am UTC](https://discuss.bitrise.io/t/building-on-unity-with-bitrise/23185/5 "2023-08-17T08:33:06Z")

</div>

@Nuvolore,

You can modify the `bitrise.yml` file but it will be easier to add the script in the workflow editor. The workflow editor is a UI where you can add, remove and reorder Steps and scripts. If you make a change in the workflow editor, the `bitrise.yml` will be changed and the other way round.

 ![Screenshot 2023-08-17 at 09.24.40](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/2/297ee02509a6da23ea489be1ff91b23939ea83f7.png)

Please also check this page with a short video ~4m about how to use the workflow editor.

> **[Workflows](https://devcenter.bitrise.io/en/steps-and-workflows/introduction-to-workflows.html)**
>
> A Bitrise Workflow is a collection of Steps. When a build of an app is running, each Step will be executed in the order that is defined in the Workflow.

Best,  
Atanas
