Building a game in Unity under Android is a process that requires attention to detail. Even experienced developers run into problems, from compilation errors to device incompatibility. This article will help you avoid common mistakes and assemble the project as efficiently as possible.
We will look at the entire path: from preparing the development environment to generating the final file (.apk or .aab). We will pay special attention to settings that directly affect game performance on mobile devices. If you are a beginner, donโt worry - the instructions are suitable for any version Unity (starting from 2020 LTS), and we will explain complex points in simple language.
Important: the assembly process may differ depending on the version Unity and Android SDK. If you are using Unity 2023+, check that the settings are up to date in the official documentation.
1. Preparing the development environment
Before building the game, make sure that your computer and project are ready to work with Android. Without proper configuration, you will receive errors already at the export stage.
First, install Java Development Kit (JDK) version 11 or 17 (recommended OpenJDK). Unity requires it to compile the code under Android. You can download from the official website Oracle or through a package manager (for example, choco install openjdk17 for Windows).
Secondly, install Android Studio - it will automatically download the necessary components Android SDK and NDK. The Unity path to SDK is specified in the project settings:
- ๐ Open
Edit โ Preferences โ External Tools - ๐ง Specify the paths to JDK, Android SDK i NDK (if required)
- ๐ Click
Applyand restart Unity
If you have MacOS, the path to Android SDK usually is in /Users/[username]/Library/Android/sdk. On Windows โ in C:\Users\[username]\AppData\Local\Android\Sdk.
Also check that the module is installed in the project Android Build Support:
- ๐ ๏ธ Go to
Window โ Package Manager - ๐ Find Android Build Support and install it
- โ Check the boxes OpenJDK, Android SDK & NDK Tools
โ๏ธ Preparing for assembly
2. Setting up the project for Android
Now switch the build platform to UnityTo do this:
- Select
File โ Build Settings - Click
Androidand clickSwitch Platform - Wait for the process to complete (may take a few minutes)
After changing the platform, open Player Settings (Edit โ Project Settings โ Player) and configure key parameters:
| Parameter | Recommended value | Explanation |
|---|---|---|
Company Name |
Name of your studio | Displayed in Google Play Console |
Product Name |
Game name | Must match the title in Google Play |
Package Name |
com.yourstudio.gamename |
Unique identifier (cannot be changed after publication!) |
Minimum API Level |
Android 5.0 (API 21) or higher |
Below API 21 โrisk of incompatibility with modern devices |
Target API Level |
Android 13 (API 33) or higher |
Required for publication in Google Play from 2023 |
Please note on Scripting Backend. There are two options:
- ๐ Mono โeasier to set up, but slower and consumes more memory. Suitable for simple 2D games.
- โก IL2CPP โoptimized for performance, but requires additional configuration. Recommended for 3D projects.
What to choose
Mono or IL2CPP?: IL2CPP gives an FPS increase of 10-30%, but increases assembly time by 2-3 times. Mono is easier to debug, but can be slow on weak devices.
Critical setting for IL2CPP: if you use plugins (for example, Firebase or Unity IAP), make sure they are compatible with IL2CPP. Otherwise, the game will crash upon startup.
3. Optimization for mobile devices
Mobile devices have limited resources, so optimization is a mandatory step. Start with graphics settings:
- ๐จ Set
Color SpacetoLinear(for realistic lighting) orGamma(for 2D games). - ๐ผ๏ธ B
Quality Settingsturn off unnecessary effects (for example,Soft ParticlesorReal-time Reflections). - ๐ฑ B
Player Settings โ Resolution and PresentationenableResize on Orientation Changeto support screen rotation.
For 3D games it is critical to configure Level of Detail (LOD) i Occlusion Culling:
- ๐๏ธ Use
LOD Groupfor objects with high number of polygons. - ๐๏ธ Turn on
Occlusion CullinginWindow โ Rendering โ Occlusion Culling. - ๐๏ธ Delete unused assets via
Assets โ Right-click โ Select Dependencies.
Don't forget about texture atlas (Texture Atlas) for 2D games. It reduces the number of draw calls, which greatly affects FPS. To create an atlas:
- Select all sprites in the folder
Assets. - Right-click and select
Sprite Atlas โ Create. - Adjust the atlas parameters (size, compression format).
Graphics optimization can increase FPS by 50-100% on weak devices, but requires testing on different smartphone models.
4. Setting resolution and control
One โโof the key differences between mobile games is touch controls. If you are porting the game from a PC, replace the keyboard and mouse with:
- ๐ฎ Virtual joystick (Unity UI or plugins like Rewired).
- ๐ Gestures (swipe, tap) - are implemented via
Input.touches. - ๐น๏ธ Gyroscope (for games with tilt control).
To adjust the screen resolution:
- Open
Player Settings โ Resolution and Presentation. - Install
Default OrientationinPortraitorLandscape(depending on the game). - Enable
Run In Backgroundif the game should work when the application is minimized (for example, for music games).
For the game to be displayed correctly on all devices, use Canvas Scaler:
- ๐ Add the component
Canvas Scalerto the mainCanvas. - ๐ข Install
UI Scale ModetoScale With Screen Size. - ๐ฑ Set
Reference Resolution(for example,1080x1920for portrait mode).
To test the controls, use Unity Remote 5 โan application that allows you to control the game on a PC via a smartphone via Wi-Fi.
5. Assembling APK or AAB: step-by-step guide
When the project is ready, we proceed to assembly. You have two options for the final file:
- ๐ฆ APK โa universal format, but has size restrictions (maximum 100 MB for Google Play).
- ๐ฆ AAB (Android App Bundle) โa modern format that generates optimized APKs for each device. Required for new publications in Google Play.
Building instructions .aab:
- Open
File โ Build Settings. - Select the scenes that should be included in the build (checked).
- Install
Build App Bundle (Google Play). - Click
Build, specify the save path (for example,MyGame.aab). - Wait for completion (may take from 1 to 10 minutes depending on the project).
For assembly .apk:
- Uncheck
Build App Bundle. - Select
Build And Runif you want to immediately test on the connected device. - If an error occurs
Failed to re-package resources, clear the folderLibraryin the project and repeat the build.
โ๏ธ Before assembly
If the build completed with an error, check:
- โ
CommandInvokationFailure: Gradle build failedโ update Gradle inPlayer Settings โ Publishing Settings. - โ
Failed to run aaptโ reinstall Android SDK Build-Tools via Android Studio. - โ
Keystore password was incorrectโ make sure that the keystore password is entered right.
6. Signing the application and publishing it on Google Play
Before downloading to Google Play the application is necessary Sign. For this you need a .keystorefile. If it is not there, create it:
- Open a terminal and run the command:
keytool -genkey -v -keystore mygame.keystore -alias mygame -keyalg RSA -keysize 2048 -validity 10000 - Fill in the data (name, organization, city, etc.).
- Save the file to a safe place (loss of keystore = inability to update game!).
Now set up the signature in Unity:
- Open
Player Settings โ Publishing Settings. - Install
Keystore ManagerinCustom Keystore. - Specify the path to
.keystore, enter passwords and alias.
For publication in Google Play Console:
- Upload the
.aabfile to the sectionProduction โ App bundles. - Fill in information about the game (description, screenshots, video).
- Indicate the category, age rating and policy confidentiality.
- Submit for review (usually takes 1-3 days).
If you are testing the game on real users before release, use Closed Testing or Open Testing in Google Play Console.
After publication, follow the reviews and crashes in Google Play Console โ Android Vitals. If the game crashes on specific devices, check:
- ๐ฑ Compatibility with
API Leveldevices. - ๐ Memory consumption (use Unity Profiler).
- ๐ฎ Controller support (if the game supports gamepads).
7. Typical errors and their solutions
Even after successful assembly, problems may arise. Here are the most common ones:
| Error | Cause | Solution |
|---|---|---|
UnityException: AndroidJavaException |
Problem with plugins or permissions | Check AndroidManifest.xml for all permissions |
Out of memory at startup |
Textures or models are too large | Reduce the size of assets or use Addressables |
| The game slows down on weak devices | Too many objects in the scene | Enable Occlusion Culling and optimize shaders |
Failed to initialize Unity Ads |
Wrong Game ID in settings |
Check Services โ Ads in Unity Dashboard |
If the game does not launch on the device, but is built without errors:
- ๐ Check the logs via
adb logcat:adb logcat -s Unity - ๐ฑ Make sure that the device supports
API Level, specified in the settings. - ๐ Try building the project with disabled plugins (possibly a version conflict).
If Google Play rejects an application, the reasons are usually as follows:
- ๐ There is no privacy policy (mandatory from 2023).
- ๐ No age rating specified (ESRB or IARC).
- ๐ฑ The application is not optimized for
64-bit(required since 2019).
90% of deviations in Google Play are associated with missing documentation (privacy policy, rating) or technical requirements (64-bit, Target API Level).
8. Additional tools to simplify the build
To speed up the process, use these tools:
- ๐ ๏ธ Unity Cloud Build โautomatic build in the cloud. Suitable for team work.
- ๐ฆ Jenkins โcontinuous integration (CI/CD) system for automatic build when changes occur. code.
- ๐ง Fastlane โa utility for automating publication in Google Play.
- ๐จ Odin Inspector โa plugin to simplify work with the inspector (speeds up setting up the UI and scripts).
For debugging on real devices:
- ๐ฑ Unity Remote 5 โ controlling the game on a PC via a smartphone.
- ๐ฅ๏ธ Scrcpy โ broadcast of the Android screen to a PC with the ability to control.
- ๐ Unity Profiler โ performance analysis (FPS, memory, GPU).
If you work in a team, configure Unity Collaborate or connect the project to Git (for example, via GitHub or GitLab). This will help avoid conflicts when merging changes.
How to set up Git for Unity?
1. Set .gitignore for Unity (excludes Library, Temp, Build). 2. Use LFS for binary files (textures, models). 3. Commit changes in small portions.
FAQ: Frequently asked questions about building games in Unity for Android
Is it possible to build a game on a Mac for Android?
Yes, but you will need to install Android Studio and configure paths to SDK/NDK same as on Windows. The main difference is the path to JDK usually located in /Library/Java/JavaVirtualMachines.
How to reduce the size of APK/AAB?
Use:
- ๐๏ธ Texture compression (
ASTCorETC2). - ๐งน Removing unused assets (
Assets โ Right-click โ Find References in Project). - ๐ฆ
Split Application BinaryinPlayer Settings(splits the APK into parts).
Why does the game work in the editor, but crashes on the device?
Possible reasons:
- ๐ซ Missing permissions in
AndroidManifest.xml(for example,INTERNETorWRITE_EXTERNAL_STORAGE). - ๐ Problems with plugins (check compatibility with
IL2CPP). - ๐ฑ Incompatibility from
API Leveldevices.
Use adb logcat for diagnostics.
How to test the game on different devices without physical access?
Options:
- ๐ Firebase Test Lab โ testing on real devices in the cloud.
- ๐ฅ๏ธ Emulators Android Studio (but they do not always accurately simulate performance).
- ๐ค Launch Closed Testing in Google Play and invite testers.
Do I need to pay to publish a game on Google Play?
Yes, a one-time fee is $25 for registering a developer account. Payment is not required for test builds (Internal/Closed Testing).