Application development for a mobile operating system requires flexibility in choosing the target platform. There is often a need to test code on older devices or, conversely, to use the latest features of recent releases. In the environment Android Studio this process does not come down to simply switching a toggle switch, but requires an understanding of the SDK architecture and the interaction between the project components.
Many novice developers confuse the version of the development tool itself and the version of the operating system on which the application will run. It is important to clearly distinguish between these concepts, since the change API Level affects available libraries, code compilation, and emulator behavior. Incorrect configuration can lead to build errors or the inability to run the application on a physical device.
In this guide, we will examine in detail the process of changing platform versions both for the project itself and for virtual devices. You'll learn how to manage packages through the SDK Manager, edit configuration files, and avoid common compatibility errors. A deep understanding of these mechanisms will allow you to create more stable and versatile applications.
Managing packages through SDK Manager
The first step to changing the Android version is to install the necessary platform components. The built-in package manager allows you to download system images, build tools, and documents for various API levels. Without the corresponding package in the local storage, the project will not be able to compile for the selected version.
To access the manager, you need to go to the menu Tools โ SDK Manager. In the window that opens, you will see a list of available platforms, sorted by API numbers. Already installed versions are marked with check marks, and missing versions are marked with a cross. Here you can select specific components, such as Android SDK Platform or System Image.
Please note that downloading system images for the emulator takes up a significant amount of disk space. If your goal is only to compile a project for old Android, it is enough to install the platform itself without a system image. However, for full testing, the presence of the image is critical.
โ ๏ธ Warning: Removing old versions of the SDK may lead to build errors in projects that are strictly tied to a specific API level in the configuration file. Before wiping the disk, check the dependencies of all active projects.
After selecting the desired versions, click the button Applyto start downloading. The process may take time depending on the speed of the Internet connection and the size of the packets. Once the installation is complete, the components will be available for selection in the project settings and when creating virtual devices.
Use the "SDK Tools" tab in the manager to update the emulator and debug tools, as they often receive critical fixes regardless of the platform version.
Setting the version in the build.gradle file
The main place where The Android version for a specific application is recorded, which is the file build.gradle (module level). This is where the minimum supported version and the target SDK version for which the application is optimized are indicated. Changing these parameters directly affects which system calls will be available to your code.
In the block android you will find two key directives: compileSdk and minSdk. The first determines which version of Android your code will compile against, allowing you to use new APIs. The second sets the lower limit of compatibility, below which the application simply will not be installed on the device.
android {
compileSdk 34
defaultConfig {
applicationId"com.example.myapp"
minSdk 24
targetSdk 34
versionCode 1
versionName"1.0"
}
}
Changing the parameter targetSdk is also important. It tells the system that the application has been tested on this version and may use new security behaviors or interface changes. Google Play requires you to specify an up-to-date targetSdk to publish new applications and updates.
After making changes to the Grad file, you need to synchronize the project. Usually the environment offers to do this automatically, displaying a banner at the top of the editor. If this does not happen, use the button Sync Now or the command File โ Sync Project with Gradle Files.
Create an emulator with the desired OS version
To test the application on a specific version of Android without having a physical device, an emulator is used. Device Manager allows you to create virtual devices with any system images installed in SDK Manager. This makes it possible to test the operation of the interface and logic in an isolated environment.
To create a new emulator, open Tools โ Device Manager and click the create a new device button. At the first stage, a physical form factor is selected (phone, tablet, wearable device). At the second stage, in the section System Image, the Android version is selected.
- ๐ฑ Recommended images: usually marked with a checkmark and containing Google Play Services, which is convenient for testing maps and services.
- ๐ค Regular images: contain a clean system without Google services, suitable for testing the basic functionality.
- ๐บ Images for Android TV: necessary for developing applications for TVs and set-top boxes.
- โ Images for Wear OS: used when creating applications for smart watches.
If the image you need does not appear in the list, return to SDK Manager and make sure it is loaded. It is also worth paying attention to the processor architecture: for modern computers, it is preferable to choose images marked Google APIs ARM64 or x86_64, as they provide better performance.
โ๏ธ Check before starting the emulator
After selecting the image and completing the setup, the emulator will appear in the list of devices. The launch is made by pressing the Play button. The first power-up may take several minutes as the system performs initial setup and data decoding.
Switching the active device for debugging
Having multiple configured emulators or connected physical devices requires the correct selection of the target machine to run. Android Studio allows you to flexibly manage this process, prompting you to select a device before each build or remembering the choice for the current session.
When you click the start button Run (green triangle), a dialog box opens Select Deployment Target. This list shows all available devices, including their status (online/offline) and Android version. Selecting a specific device sends a compiled APK file to it.
To speed up the work, you can configure the behavior of the environment in the settings. Go to Run/Debug Configurations and find the section Deployment Target Options. Here you can set the mode Show Prompt for manual selection or Open Device Selector for automatic selection.
| Parameter | Description | Impact on the process |
|---|---|---|
minSdkVersion |
Minimum version OS | Blocks installation on old devices |
targetSdkVersion |
Target OS version | Defines system behavior and access rights |
compileSdkVersion |
Version for compilation | Gives access to new APIs during development |
buildToolsVersion |
Build tools version | Affects the speed and methods of compilation |
Sometimes a situation arises when the application does not see the connected device. In this case, check the USB debugging mode on the smartphone itself and make sure that the drivers are installed correctly. Restarting the ADB server using the command adb kill-server i adb start-server often solves the detection problem.
Features of working with Preview and Beta versions
Developers who want to try out the features of future versions of Android can install pre-release builds. Such versions are marked as Developer Preview or Beta and require a separate download through the SDK Manager. Working with them has its own characteristics and risks.
To install the version, go to the SDK Platforms tab in the manager and enable the display of old or preliminary versions if they are hidden. They are usually at the end of the list. After installation, this version will be available for selection as compileSdk and for creating emulators.
โ ๏ธ Attention: Applications compiled for Preview versions of the SDK may not run on stable versions of Android. Do not use such assemblies for release versions of your product.
Using beta versions of the emulator allows you to detect compatibility bugs in advance. However, it is worth remembering that system images can be unstable, contain interface errors or lead to crashes of the emulator itself. It is recommended to use them in isolated projects for experiments.
Where can I download drivers for the emulator?
In most cases, Android Studio automatically installs the necessary drivers for emulation. If you are experiencing graphics problems, make sure you have the latest drivers installed for your graphics card (NVIDIA, AMD, or Intel) and hardware virtualization is enabled.
Solving compatibility and dependency issues
Changing Android versions often entails problems with libraries and dependencies. Some third-party SDKs may not support new API levels, or, conversely, require updates to work with old ones. Conflicts of allegiance are a common problem when migrating projects.
When increasing targetSdk the system may begin to be stricter about permissions and background processes. For example, starting with Android 13, the approach to issuing rights to notifications has changed, and Android 14 has tightened the requirements for Broadcast Receiver registration. Code that worked previously may no longer function correctly.
To diagnose problems, use the tab App Inspection and logs Logcat. Filtering logs by your application tag will help you quickly find exceptions related to SecurityException or ClassNotFoundException. Often the solution lies in updating the versions of the libraries in the file dependencies.
- ๐ Check the manifest: make sure that all necessary rights are declared and requested at runtime.
- ๐ฆ Update libraries: use the latest stable versions of dependencies that are compatible with your API.
- ๐ Clear cache: command
Invalidate Caches / Restarthelps eliminate old configuration artifacts.
If the project uses native code (C/C++), make sure that NDK also updated to a version that supports the selected API level. Incompatibility between NDK and SDK versions can lead to linking errors or application crashes when loading native libraries.
Always test the application on the minimum supported version (minSdk) after any configuration changes to ensure backward compatibility.
Is it possible to change the Android version on an already connected physical phone through Android Studio?
No, Android Studio does not have the ability to reflash physical devices or change the version of their operating system. It can only install applications and debug them. To change the Android version on your phone, you need to use official updates from the manufacturer or third-party firmware (Custom ROM), which is done outside the development environment.
What to do if the emulator does not start after changing the image version?
Try creating a new virtual device instead of editing the old one. Often the configuration files of the old emulator conflict with the new image. Also check if virtualization (VT-x / AMD-V) is enabled in your computer's BIOS, as this is a mandatory requirement for the emulator to work.
Does the compileSdk version affect the size of the final APK file?
The compile version itself has a slight effect on the size. The main weight is added by the libraries and resources used. However, using new APIs may require the inclusion of additional compatibility libraries (AndroidX), which may slightly increase the size of the application.
How to rollback the Gradle version of a plugin in case of errors after an update?
Open the file build.gradle (project level) and find the line with the declaration of the Android Gradle Plugin dependency class. Change the version number to the previous stable version (for example, from 8.2.0 to 8.1.0) and synchronize the project.
Do you need to remove old versions of the SDK to free up space?
Yes, if you are sure that you do not support old devices and do not run legacy projects. Old images of systems and platforms can occupy tens of gigabytes. It is safe to remove them via SDK Manager, but at least one version lower than the current one for testing compatibility.