The development of mobile applications requires constant adaptation to different versions of the operating system. Developers often need to test their code on older or, conversely, the latest versions of the platform to ensure compatibility. In the environment Android Studio this process is implemented flexibly, but for beginners it may seem confusing due to the abundance of settings and terminology.

Changing the Android version in this context usually involves working with two main entities: the settings of the project itself (compileSdk, minSdk) and the configuration of the virtual device (emulator). Misunderstanding the difference between these concepts often leads to build errors or the inability to run the application on a test device.

In this article we will look in detail at how to manage platform versions, install the necessary components through the SDK Manager and configure emulators to simulate work on specific versions of Android. You will learn to switch between API levels and understand what changes this makes to the development process.

Differences between SDK versions and system image

Before you start changing settings, it is important to clearly distinguish between concepts. SDK Platform is a set of libraries and tools necessary for the compiler to build your application for a specific version of Android. It is this parameter that is indicated in the file build.gradle as compileSdkVersion.

On the other hand, System Image is actually the firmware, an operating system image that is loaded into the emulator (AVD). Without System Image installed, you will not be able to launch a virtual device with the desired version of Android, even if SDK Platform is installed.

โš ๏ธ Attention: Installing SDK Platform does not automatically install System Image for the emulator. These are two different components that need to be loaded separately through the SDK manager.

Often developers are faced with a situation where a project is built for a new API, but the emulator runs on the old one. This leads to the application crashing on startup if functionality that is not available in the old version is used. Therefore, synchronizing these components is a critical task.

To manage all these components, Android Studio has a built-in tool. It allows you to view installed packages, download new ones and remove outdated ones. It is accessed through the main menu or the interface toolbar.

Installing new versions of the platform via SDK Manager

To add support for a new version of Android to your project or install an image for the emulator, you must use SDK Manager. This tool is the central hub for downloading all the necessary binary files from Google.

Open the settings by going to the menu Tools โ†’ SDK Manager (or clicking on the exclamation mark icon in the toolbar). In the window that opens, you will see the SDK Platformstab. Here is a list of all available versions of Android, from the oldest to the latest preview versions.

  • ๐Ÿ“ฆ Android 14 (API 34) โ€”the latest stable version at the moment, recommended for new projects.
  • ๐Ÿ“ฑ Android 13 (API 33) โ€”a widely used version, required for testing most applications.
  • ๐Ÿค– Android 12 (API 31/32) โ€”still current to ensure backward compatibility.
  • โš™๏ธ Android 11 and below โ€”are necessary if your application should work on outdated devices.

To install the desired version, simply check the box next to the appropriate item and press the button Apply or OK. The manager will download the necessary files, including platforms, system images and debugging tools. The process may take some time depending on the speed of your Internet connection.

๐Ÿ’ก

If the download freezes or is very slow, try changing the proxy settings in the HTTP Proxy section or using a repository mirror if your organization's policy allows it.

Once the installation is complete, new versions will be available for selection when creating a project or setting up an emulator. The list of available target versions in the build configuration will also be updated.

Setting the target version in the Build Gradle file

After installing the necessary platforms, you need to tell the project which version to use for compilation. This is done in the assembly configuration file build.gradle (module level, usually app/build.gradle).

In the block android find the parameters compileSdk and targetSdk. The parameter compileSdk determines which version of Android will be used against your code will compile. Using a newer version allows accessing new APIs, but does not affect where the application can be run.

android {

compileSdk 34

defaultConfig {

applicationId "com.example.myapp"

minSdk 24

targetSdk 34

versionCode 1

versionName "1.0"

}

}

The parameter minSdk indicates the minimum version of Android on which your application is capable of running. If you set it too high, users with older phones will not be able to install the application from Google Play.

โ˜‘๏ธ Checking the Gradle configuration

Done: 0 / 5

The parameter targetSdk tells the system that the application has been tested for this version. This affects the behavior of some compatibility features. Google requires that this parameter be updated regularly to publish applications in the store.

Creating and changing the emulator version (AVD)

To test an application on a specific version of Android without having a physical device, you can use Android Virtual Device (AVD). You cannot change the version of a running emulator on the fly, but you can create a new one with the necessary parameters or edit the configuration of an existing one by replacing the system image.

Open Device Manager via the toolbar. To create a new device, click Create DeviceSelect a hardware profile (for example, Pixel 6), then at the stage of selecting the system image (System Image) select the desired API version.

Version name API Level Image type Recommendation
UpsideDownCake 34 Google APIs For testing new functions
Tiramisu 33 Google Play Standard for modern applications
Snow Cone 32 Default For checking compatibility
Red Velvet Cake 30 Google APIs Minimum limit for many services

If you want to change the version of an already created emulator, click on the three dots next to the device in the list and select Edit. In the editing window, click the button Change next to the item System Image and select another image from the list of downloaded ones.

โš ๏ธ Attention: Replacing the system image on the emulator will result in a complete data reset (wipe data). All installed applications and settings inside the emulator will be deleted.

Selecting an image with the mark Google Play allows you to use the emulator with pre-installed Google services, which is necessary for testing maps, logging in through your account and push notifications.

๐Ÿ“Š Which version of Android do you most often use for tests?
Android 14 (API 34)
Android 13 (API 33)
Android 11 (API 30)
Android 8 (API 26)
Other

Solving problems with version incompatibility

When changing SDK versions, build errors often occur due to the fact that the code uses methods that appeared only in the new version of the API, but minSdk is set to a low value.

In this case, Android Studio will highlight the problematic code in red and offer to add a version check. This is done using the design if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.X). This check ensures that the new code will only be executed on supported devices.

Another common problem is the absence of the required system image in the list. creating an emulator. Make sure that you are on the SDK Platforms tab in the manager and check the box next to the desired version. Sometimes you need to switch the view to Packageto see all the available options.

What to do if the emulator does not start after changing the image?

If after the change system image, the emulator freezes on the logo, try performing a cold restart (Cold Boot Now) in the device action menu. If this does not help, delete the emulator and create a new one with the same name, since the configuration files may have been damaged.

It is also worth remembering the difference between the images x86_64 and ARM. speed up work on a PC, always choose x86 architecture images if your processor supports virtualization. ARM images are much slower due to instruction emulation.

Updating build tools and platforms

In addition to Android versions, it is important to keep Android SDK Build-Tools and Platform-Tools. These components are located in the SDK Tools tab in the SDK manager. They are responsible for compiling code and running command line utilities such as adb.

Inconsistency between the version of the build tools and the compilation version can lead to strange linking errors or the inability to install the application on the device. It is recommended to always use the latest stable version, marked. as recommended in the list.

To update, just check the box next to the new version in the list of tools and apply the changes. Android Studio will automatically update the paths in the project configuration files.

โš ๏ธ Attention: The interface and available options in Android Studio may vary slightly depending on the version of the IDE itself (Giraffe, Hedgehog, Iguana, etc.). Always check the official documentation if you cannot find a familiar button.

๐Ÿ’ก

Regular updating of Build-Tools and Platform-Tools is critical for stable operation of the development environment and correct deployment of applications to physical devices.

Frequently asked questions (FAQ)

Can this be changed? version of Android on a physical device via Android Studio?

No, Android Studio is intended for developing and debugging applications, and not for flashing devices. Changing the OS version on a real phone requires unlocking the bootloader and using special utilities (for example, Odin for Samsung or fastboot for Pixel), which is not directly related to the functionality of the IDE.

Why does the project not build after updating the SDK?

Most often the problem is in the cache. Try running the command File โ†’ Invalidate Caches / Restart. Also check if the versions match compileSdk V build.gradle with the installed platform in the SDK Manager.

How to find out what version of Android is installed on the connected phone?

In Android Studio, open the tab Device Manager or look in window Logcat. You can also use the ADB command in the terminal: adb shell getprop ro.build.version.release.

Is it necessary to install all available versions of the SDK?

No, it will only take up disk space. Install only those versions that are specified in minSdk and targetSdk your projects, as well as one or two intermediate versions for testing compatibility.

What is Android Extension in SDK Manager?

These are additional packages, such as Google Play services, Intel x86 Emulator Accelerator or vendor-specific support. They are needed for advanced functionality of the emulator or specific application functions.