Unity for the win, on Bitrise too!

Unity on Bitrise! You can automate your games' building, testing and deployment too!

Did you know that you can automate your Unity builds on Bitrise?

The leading global game industry software Unity plays an important part in a booming global games market. More games are made with Unity than with any other game technology. More players play games made with Unity, and more developers rely on their tools and services to drive their business... Global gamers downloaded Unity-made games to nearly 2 billion unique mobile devices, in Q1 2016 alone. 34% of the top 1000 free mobile games are made with Unity. Unity customers include Coca-Cola, Disney, Electronic Arts, LEGO, Microsoft, NASA... From large and small studios to independent professionals, more and more developers are moving to Unity. Source

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...

...and choose a Xamarin stack.

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 Unity 5.5.0, this is how you download the editor and the two platform support packages (Android & iOS) :


#download unity pkg
curl -o ./unity.pkg http://download.unity3d.com/download_unity/38b4efef76f0/MacEditorInstaller/Unity-5.5.0f3.pkg

#download android support platform
curl -o ./android.pkg http://download.unity3d.com/download_unity/38b4efef76f0/MacEditorTargetInstaller/UnitySetup-Android-Support-for-Editor-5.5.0f3.pkg

#download iOSle support
curl -o ./ios.pkg http://download.unity3d.com/download_unity/38b4efef76f0/MacEditorTargetInstaller/UnitySetup-iOS-Support-for-Editor-5.5.0f3.pkg
Copy code


This is how you install them:


#install unity pkg
sudo -S installer -package ./unity.pkg -target / -verbose

#install unity android support pkg
sudo -S installer -package ./android.pkg -target / -verbose

#install unity iOS support pkg
sudo -S installer -package ./ios.pkg -target / -verbose
Copy code


After installation you will find Unity in the following location:


/Applications/Unity/Unity.app/Contents/MacOS/Unity
Copy code


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.


/Applications/Unity/Unity.app/Contents/MacOS/Unity -logfile &
sleep 15
sudo killall Unity
Copy code


License activation

You'll need to have a valid license key to build Unity projects. Sadly, 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:


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


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:


/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
Copy code


... and this for iOS:


/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
Copy code


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:


/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -logFile -returnlicense
Copy code

Set the step to Run even if previous Step failed otherwise you risk that it won't get deactivated if your build fails!

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

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.

Happy building, happy gaming! 🚀

No items found.
The Mobile DevOps Newsletter

Explore more topics

App Development

Learn how to optimize your mobile app deployment processes for iOS, Android, Flutter, ReactNative, and more

Bitrise & Community

Check out the latest from Bitrise and the community. Learn about the upcoming mobile events, employee spotlights, women in tech, and more

Mobile App Releases

Learn how to release faster, better apps on the App Store, Google Play Store, Huawei AppGallery, and other app stores

Mobile DevOps

Learn Mobile DevOps best practices such as DevOps for iOS, Android, and industry-specific DevOps tips for mobile engineers

Mobile Testing & Security

Learn how to optimize mobile testing and security — from automated security checks to robust mobile testing and more.

Product Updates

Check out the latest product updates from Bitrise — Build Insights updates, product news, and more.

The Mobile DevOps Newsletter

Join 1000s of your peers. Sign up to receive Mobile DevOps tips, news, and best practice guides once every two weeks.