Creating a mobile game is a fascinating process that begins with choosing the right engine, and Unity here is the undisputed industry leader. The platform Android occupies more than 70% of the global smartphone market, so porting your project to this OS becomes a priority for most developers. Despite the apparent complexity, the process of setting up the environment and assembling the first installation file does not take much time if you know the exact sequence of actions.

You do not need to be an expert in programming or system administration to successfully assemble a project. Modern versions of the engine automate many processes, but a basic understanding of file structure and operating system requirements is critical. In this article we will look in detail at how to prepare Unity to work with Android, what modules need to be installed and how to avoid common compilation errors.

Before you start setting up, make sure that you have the latest version of the engine installed via Unity Hub. Older versions may not support the required Google APIs or may have bugs in the builder. It is also worth registering a developer account in advance if you plan to upload the project to Google Play, although this is not required for local testing yet.

Preparing the environment and installing modules

The first step in creating a cross-platform project is to install the necessary components for the target platform. By default Unity it is installed only with PC support, so to work with mobile devices you need to download additional modules. This can be done through Unity Hub in the settings section or by modifying the existing version of the engine.

You will need to find the item Android Build Support and be sure to check the associated components: Android SDK & NDK Tools and OpenJDK. Without these libraries, the engine will not be able to compile the code into a format understandable by the smartphone operating system. The download process may take time depending on the speed of your Internet connection.

๐Ÿ“Š What level of experience with Unity do you have?
Beginner (first project)
Basic (know the interface)
Intermediate (wrote scripts)
Pro (assembling complex projects)

After installing the modules, you need to switch the platform in the project settings. To do this, go to the menu File โ†’ Build Settings and select Android in the list of platforms, then press the button Switch Platform. The engine will rebuild the assets for the new architecture, which may take several minutes.

โš ๏ธ Attention: Make sure that the paths to the installed SDK and NDK do not contain Cyrillic characters or spaces. This is a common cause of compilation errors when the builder cannot find the necessary files.
  • โœ… Open Unity Hub and go to the Installs section.
  • โœ… Click on the gear next to your version of Unity and select Add Modules.
  • โœ… Find in the list Android Build Support and install all child components.
  • โœ… Restart the editor after installation is complete.

Configuring Player Settings and Manifest

After switching platforms, you need to correctly configure the settings of your application. This data will be stored in AndroidManifest.xml is a file that tells the system how to run your game and what permissions it requires. The main settings are located in the window Project Settings โ†’ Player in the Android tab.

The key parameter is Package Name (Package name). This is a unique identifier for your application in the format com.companyname.gamename. It must be unique across the entire Google Play store, so use the reverse notation of the domain name or come up with an original combination. Changing this field after publishing the application will make it impossible to update an already installed version.

It is also important to set the minimum API version (Minimum API Level). It is recommended to set the value to at least Android 7.0 (API Level 24) to cover most active devices, but not to support very old and slow smartphones. It is better to leave the graphics API OpenGLES3 or switch to Vulkan for more modern projects.

๐Ÿ’ก

Use a company prefix in the package name to avoid conflicts with other developers if you plan to publish the project in open sources.

In the section Other Settings pay attention to the field Scripting Backend. For Android, it is recommended to use IL2CPP instead of Mono, as this provides better performance and support for 64-bit architecture, which is required for publishing on Google Play. Here you can also configure the screen orientation and application icon.

Parameter Recommended value Description
Package Name com.myname.mygame Unique application ID
Minimum API Level Android 7.0 'Nougat' (API Level 24) Minimum OS version
Target API Level Android 13.0 'Tiramisu' (API Level 33) Target version for optimization
Scripting Backend IL2CPP Backend for code compilation

Touch input and interface management

Transferring control from the keyboard and mouse to the touchscreen is one of the most important stages of adapting the game to Android. Unlike on PC, where the cursor is always visible, on a mobile device the player interacts with objects directly with their fingers. Unity provides a built-in system Input Systemthat allows you to flexibly configure reactions to touches.

For simple projects, it is often enough to use standard events OnTouch or OnMouseDownthat automatically adapt to the touch interface. However, for more complex games, especially shooters or platformers, you will need to create virtual joysticks and buttons. You can find them in the Asset Store or implement them yourself using a UI canvas and images.

How to test multi-touch?

To test multi-touch control on a PC, use emulation. In the Game View settings, enable mobile device simulation and use multiple keystrokes or an input emulator to simulate multiple fingers at the same time.

Don't forget to adapt the interface to different screen aspect ratios. There's a huge variety of displays on Android, from sleek modern flagships to older 4:3 tablets. Use the component Canvas Scaler and anchors (Anchors) in the UI so that the interface elements do not go beyond the visible area.

  • ๐Ÿ“ฑ Set UI Canvas to mode Scale With Screen Size.
  • ๐Ÿ“ฑ Use Safe Area for accounting camera cutouts and notches.
  • ๐Ÿ“ฑ Test the game at different resolutions in the window Game.

Optimizing graphics and performance

Mobile devices, even flagship ones, have limitations on power consumption and heat dissipation that do not exist on PCs. Therefore, optimization becomes a critical step before assembly. First of all, you should pay attention to the number of polygons in the models and texture resolution. For mobile games, textures of size 1024x1024 or 2048x2048are considered standard, and the use of compression ASTC can significantly reduce the weight of the APK.

In the quality settings (Project Settings โ†’ Quality) it is recommended to create a separate profile for Android with a reduced level of detail. Here you can turn off heavy effects such as complex shadows, post-processing or dynamic lighting in favor of baked light (Baked Lighting). This will drastically increase FPS on weak devices.

โš ๏ธ Attention: Always test the game on a real device, and not just in an emulator. Emulators often show incorrect performance and can hide problems with overheating or memory consumption.

It is also worth minimizing the number of Draw Calls. Combine static objects using the Static Batchingfunction, marking them with the Static flag in the inspector. This will allow the engine to render many objects in one pass, which will significantly relieve the smartphone processor.

๐Ÿ’ก

The main goal of optimization is stable 60 FPS on mid-class devices, and not maximum graphics on top smartphones.

Building APK and AAB files

When the project is configured and optimized, the moment comes truth - assembly of the installation file. In the window Build Settings you can select the output file format. Traditionally, the format was used APK, which is convenient for local installation and testing. However, Google Play requires a format Android App Bundle (AAB) to publish to the store.

To create an APK, simply click the button Build and select a folder to save. If you want to build AAB, you must first install the plugin Google Play Asset Delivery or simply select the appropriate checkbox in the build settings, if it is available in your version of Unity. The compilation process can take from several minutes to an hour depending on the power of the PC and the size of the project.

โ˜‘๏ธ Final check before assembly

Completed: 0 / 4

After successful assembly, you will receive a file that can be transferred to your smartphone. To install an APK file directly (sideloading), you may need to allow installation from unknown sources in your Android security settings. AAB files are primarily intended for uploading to the Google Play developer console.

Debugging and publishing to Google Play

The last stage is testing and publishing. Connect your Android smartphone to your computer via a USB cable and enable mode USB Debugging in the developer menu. In Unity, in the window Window โ†’ General โ†’ Device and Scan you will see the connected device and will be able to run the game directly on it with the ability to view logs in real time.

If red errors (Exceptions) appear in the logs, they must be corrected before release. Pay attention to yellow warnings - they may indicate potential performance issues. After eliminating the bugs, you can create a release build with the option enabled Development Build (disabled for release) and send the project for moderation.

Publishing to Google Play Console requires creating an application, filling out a description, uploading screenshots and setting up pricing. Remember that the first application undergoes a more thorough review, which can take up to 7 days. Compliance with community rules and the absence of bugs that cause crashes will speed up this process.

โš ๏ธ Attention: Google Play Rules and API requirements are updated regularly. Before each publication, check the official documents to ensure that your application is not rejected due to outdated permissions or policies.
  • ๐Ÿš€ Register in Google Play Console (one-time fee $25).
  • ๐Ÿš€ Create an application card and fill out metadata.
  • ๐Ÿš€ Upload the AAB file for internal testing.
  • ๐Ÿš€ After a successful test, send it to production.

Frequently asked questions (FAQ)

Do you need a Mac to build a game for Android in Unity?

No, to develop for Android, the Windows, Linux or macOS operating system is sufficient. A Mac is only required if you plan to simultaneously build the iOS version of the game.

Why does the game crash immediately after launching on the phone?

Most often this is due to the lack of necessary permissions, an error in the code that only appears on the device, or incompatibility of the SDK version. Check the logs via Logcat in Android Studio or the Unity window.

Is it possible to update an already published game?

Yes, to do this you need to increase the version number (Version) and the version code (Build Number) in the Player settings Settings, collect a new AAB file and upload it to the developer console as an update to an existing application.

What APK size is considered normal?

It is advisable to keep the APK size to 100-150 MB for quick downloading by users via the mobile data. If the game is more difficult, use Google Play resources to load additional data.