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.

๐Ÿ“Š What version of Unity are you using?
2020 LTS
2021 LTS
2022 LTS
2023+
I donโ€™t know

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 Apply and 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

Done: 0 / 4

2. Setting up the project for Android

Now switch the build platform to UnityTo do this:

  1. Select File โ†’ Build Settings
  2. Click Android and click Switch Platform
  3. 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 Space to Linear (for realistic lighting) or Gamma (for 2D games).
  • ๐Ÿ–ผ๏ธ B Quality Settings turn off unnecessary effects (for example, Soft Particles or Real-time Reflections).
  • ๐Ÿ“ฑ B Player Settings โ†’ Resolution and Presentation enable Resize on Orientation Change to support screen rotation.

For 3D games it is critical to configure Level of Detail (LOD) i Occlusion Culling:

  • ๐Ÿ—๏ธ Use LOD Group for objects with high number of polygons.
  • ๐Ÿ‘๏ธ Turn on Occlusion Culling in Window โ†’ 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:

  1. Select all sprites in the folder Assets.
  2. Right-click and select Sprite Atlas โ†’ Create.
  3. 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:

  1. Open Player Settings โ†’ Resolution and Presentation.
  2. Install Default Orientation in Portrait or Landscape (depending on the game).
  3. 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 Scaler to the main Canvas.
  • ๐Ÿ”ข Install UI Scale Mode to Scale With Screen Size.
  • ๐Ÿ“ฑ Set Reference Resolution (for example, 1080x1920 for 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:

  1. Open File โ†’ Build Settings.
  2. Select the scenes that should be included in the build (checked).
  3. Install Build App Bundle (Google Play).
  4. Click Build, specify the save path (for example, MyGame.aab).
  5. Wait for completion (may take from 1 to 10 minutes depending on the project).

For assembly .apk:

  1. Uncheck Build App Bundle.
  2. Select Build And Runif you want to immediately test on the connected device.
  3. If an error occurs Failed to re-package resources, clear the folder Library in the project and repeat the build.

โ˜‘๏ธ Before assembly

Done: 0 / 4

If the build completed with an error, check:

  • โŒ CommandInvokationFailure: Gradle build failed โ€” update Gradle in Player 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:

  1. Open a terminal and run the command:
    keytool -genkey -v -keystore mygame.keystore -alias mygame -keyalg RSA -keysize 2048 -validity 10000
  2. Fill in the data (name, organization, city, etc.).
  3. Save the file to a safe place (loss of keystore = inability to update game!).

Now set up the signature in Unity:

  1. Open Player Settings โ†’ Publishing Settings.
  2. Install Keystore Manager in Custom Keystore.
  3. Specify the path to .keystore, enter passwords and alias.

For publication in Google Play Console:

  1. Upload the .aabfile to the section Production โ†’ App bundles.
  2. Fill in information about the game (description, screenshots, video).
  3. Indicate the category, age rating and policy confidentiality.
  4. 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 Level devices.
  • ๐Ÿ”‹ 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 (ASTC or ETC2).
  • ๐Ÿงน Removing unused assets (Assets โ†’ Right-click โ†’ Find References in Project).
  • ๐Ÿ“ฆ Split Application Binary in Player 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, INTERNET or WRITE_EXTERNAL_STORAGE).
  • ๐Ÿ”Œ Problems with plugins (check compatibility with IL2CPP).
  • ๐Ÿ“ฑ Incompatibility from API Level devices.

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