How to publish to Android

Tutorial

·

Beginner

·

+10XP

·

10 mins

·

(181)

Unity Technologies

How to publish to Android

Publishing for Android is a lot like publishing a build for Windows, Mac OS, and Linux. In certain cases, there are no required changes at all. For example, in a mobile game that uses finger gestures to interact with game elements, this can be accomplished with the same code as its desktop counterpart. Mobile touch input is beyond the scope of this workflow, so it’s assumed that the game is complete and ready for distribution.

Languages available:

1. How to publish to Android

This tutorial has been verified using Unity 2019 LTS


Publishing for Android is a lot like publishing a build for Windows, Mac OS, and Linux. In certain cases, there are no required changes at all. For example, in a mobile game that uses finger gestures to interact with game elements, this can be accomplished with the same code as its desktop counterpart. Mobile touch input is beyond the scope of this workflow, so it’s assumed that the game is complete and ready for distribution.


2. Preparing Unity

Before Unity can build for Android, you need to install the Android Build Support modules from the Unity Hub.


1. In the Unity Hub, choose either the current version (or with a new install,) select the Add button, to install additional modules (Figure 01).


Figure 01: The Unity Hub, Install additional modules to existing, or Add a new install button.

Figure 01: The Unity Hub, Install additional modules to existing, or Add a new install button.


2. Select Android Build Support, also selecting a checkmark to include both Android SDK & NDK Tools, and OpenJDK (Figure 02). After installation, you may need to perform a restart.


Figure 02: Installing Android Build Support through the Unity Hub.

Figure 02: Installing Android Build Support through the Unity Hub.


3. Preparing your project

For this introduction, we will cover the basic steps necessary to prepare your project for publishing to the Google Play store. Rather than exporting to a final build of an .exe file, (Windows) or an .app file, (macOS), Android binaries use the file-type called an Android App Bundle, using the extension of an .aab file. When Unity builds an application for Android, the output package exports to an .aab file, for ease of uploading and hosting to the Google Play store environment.


Technical Steps:


1. In the Unity Editor, from the File dropdown, select Build Settings. In the Platforms window, select Android, and select the Switch Platform button, if Android has not already been selected (Figure 03).


Figure 03: Android Build settings in the Unity Build Settings window, with the Switch Platform button highlighted.

Figure 03: Android Build settings in the Unity Build Settings window, with the Switch Platform button highlighted.


2. At the lower-left corner of the Build Settings window, select the Player Settings button.


3. At the top of the Inspector, fill out your company and product names. For the final distribution, it is recommended that you create an icon for your game to replace the default Unity launcher icon. Depending on the nature of your game, you may also wish to override the default mouse cursor. By default, the cursor hotspot is at position (0,0), in the upper left corner of the cursor image (Figure 04).


Figure 04: Assigning Company, Product name, Default Icon, Default Cursor, and Cursor Hotspots in the Project Settings window.

Figure 04: Assigning Company, Product name, Default Icon, Default Cursor, and Cursor Hotspots in the Project Settings window.


4. In the bottom half of the Project Settings window, select Resolution and Presentation (Figure 05).


Figure 05: Assigning Resolution and Presentation settings in the Project Settings window.

Figure 05: Assigning Resolution and Presentation settings in the Project Settings window.


5. Set your game’s default and allowed orientations (Figure 06). For most purposes, “Default Orientation” is best set to Auto Rotation. Most apps and games are designed to run either in landscape or portrait mode, rather than both.


Figure 06: Assigning Auto Rotation as the orientation default.

Figure 06: Assigning Auto Rotation as the orientation default.


6. Select Resolution and Presentation at the top of this section to close it, then select Other Settings (Figure 07).


Figure 07: Selecting Other Settings in the Project Settings window.

Figure 07: Selecting Other Settings in the Project Settings window.


7. In Other Settings, for this introduction, we are only concerned with the Package Name for our mobile project. The Package Name is also known as the Application ID or bundle identifier. The bundle identifier must be unique, and cannot be reassigned to another project once the game or app has been published. Name your project (Figure 08).


Figure 08: Assigning a Package Name in the Other Settings dialog box.

Figure 08: Assigning a Package Name in the Other Settings dialog box.


8. Select the Other Settings section, to close this section.


9. Next, before an Android app can be distributed on the app stores, it must be signed with a unique key. Select Publishing Settings to open that section (Figure 09).


Figure 09: The Publishing Settings section of the Project Settings window.

Figure 09: The Publishing Settings section of the Project Settings window.


10. A Keystore Manager is exactly what it sounds like: To create and organize keys for one or more applications. If you’ve previously created a Keystore and want to publish your application using the custom Keystore, select to enable the Custom Keystore checkbox, under the Project Keystore option. You will then be prompted to browse for your existing key location folder. Otherwise, select the Keystore Manager Button, to create a new Keystore (Figure 09).


11. In the Keystore Manager window, select the Keystore dropdown, and then select Create New > Anywhere, (or In Dedicated Location) (Figure 10), and Navigate to the location of the new folder. It’s a good idea to keep the Keystore separate from your projects where it will be both secure and easy to find. If you want to use an existing Keystore location, select from the dropdown: Keystore > Select Existing. If creating a new Keystore, give it a name and then Save. Otherwise, select the existing Keystore and select Open. For security purposes, the password is not stored with the Keystore. If you lose the password, you’ll need to publish a new application with a new bundle identifier.


Figure 10: The Keystore Manager window, from within the Publishing Settings of the Project Settings window.

Figure 10: The Keystore Manager window, from within the Publishing Settings of the Project Settings window.


12. Next, we’ll create the key in our Keystore for our Android application. In the Keystore Manager window, fill out the required information fields, confirming the password, and select the Add Key Button (Figure 11). Be sure to store your Keystore and passwords in a safe place.


Figure 11: Adding a new key in the Keystore Manager

Figure 11: Adding a new key in the Keystore Manager


13. Confirm by selecting the Yes button, to assign the new key to your project’s Keystore Manager’s settings (Figure 12).


Figure 12: Confirmation dialogue window, assigning new key to the Keystore Manager.

Figure 12: Confirmation dialogue window, assigning new key to the Keystore Manager.


14. The Publishing Settings section of the Project Settings window are now updated to reflect the changes to your project’s new Keystore (Figure 13).


Figure 13: The Publishing Settings show the newly created Keystore, with the Custom Keystore checkbox marked.

Figure 13: The Publishing Settings show the newly created Keystore, with the Custom Keystore checkbox marked.


15. You are now ready to create the .apk file for distribution. You may close out of the Project Settings window. In the Unity Editor, from the FIle dropdown, select Build Settings. Select Android in Platforms if it is not already highlighted, and select the Build button (Figure 14).


Figure 14: Publishing for Android in the Build Settings window.

Figure 14: Publishing for Android in the Build Settings window.


16. Choose a name and location for your .aab file and select Save.


4. Next Steps

Your Android application is now ready for distribution. Uploading your .aab file to the Google Play Store app marketplace, and setting up the store page, is beyond the scope of this workflow. Please consult the help resources for those sites for assistance with that process.


Complete this tutorial