Changing API version in Android Studio


Introduction

First of all before changing an API (Application Programming Interface) Version we have to know what Android API is and what is its use. An Android API in an Application Program Interface which allows us to add specific functionality to our Android application. In simple language Android API are the set of tools used for developing Android Application. The API version is used by developers to ensure their applications are compatible with the current version of the Android operating system. It is also used by Android phones to determine which applications are compatible with their device.

The API version is an important part of the Android software development kit (SDK). When a developer creates an Android application, they must specify the API version they are targeting. This ensures the application will be compatible with devices running the specified version of the Android operating system. The API version also helps the device determine which applications are available for it to download.

API Version is the Android Version which tells the developer to which API Version they are targeting to run their application. As we are developing this Android application to get published on Google Play Store. And to publish this application we have to fulfill the requirements and one of them is setting an API Level For Changing the API Version the developer has to set minSdkVersion and targetSdkVersion.

  • minSdkVersion − Min SDK Version (Minimum Software Development Kit Version) is an important concept in the world of Android app development. It specifies the minimum version of the Android SDK (Software Development Kit) that the app was built with. It is important to understand this concept as it can affect how the app behaves on different devices. This means the minimum Android OS version that will support the app.

  • targetSdkVersion − The Target SDK Version is an important setting for Android developers to consider when developing applications for Android devices. In short, it is the version of the Android SDK that you have chosen to target your application for. The target SDK version is used to define the behaviors, appearance, and limitations of the application. This means the version for which the developers are actually developing their application.

There are two method which are used to change the API version of any android studio project which are as follows −

  • Changing the API version of the project from build.gradle file.

  • Changing API version of the project through Project Structure.

Method 1: Changing API version of project from build.gradle

Navigate to your android studio project. In the project in the left tab, you have to navigate to app>Gradle Scripts>build.gradle(app level). Inside this build.gradle file you will get to see a default config section in which you will get to see a target sdk version and a minimum sdk version. This is the android’s API version of the library which is currently being used by your project. You can change these both values to the latest available in the market or can downgrade it according to your requirement. Along with that sometimes you will also get to see suggestions for the latest available api version in the code itself. In the code for min sdk version and target sdk version you will see it is being highlighted with yellow color. You have to click on the yellow bulb which will tell you about the latest available API version for the project and then you can update it accordingly. Once you have updated the api version make sure to click on the Sync now option to sync your gradle file.

Method 2: Changing API version of project through project structure

Navigate to your android studio project. Inside the project Click on File which you can get to see in the top bar, then click on Project Structure. Once you click on it you will have to navigate to the Modules tab. Inside this modules tab select the app and then click on Default Config tab to view the default configurations. Inside this you will get to see target sdk version and minimum sdk version. From this you can change your sdk version according to your requirement. Once you have updated it simply click on Apply and OK to add those changes to your project. Your project will be synced and the API version for the project will be changed as mentioned.

Note − Note that changing the API Version may require updating your code to ensure compatibility with the new version. You may also need to update your dependencies to ensure that they are compatible with the new version.

Conclusion

In this article we have taken a look at How to change API version of the project in Android studio using two different methods.

Updated on: 08-May-2023

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements