API level is an integer value that uniquely identifies the framework API revision offered by a version of the Android platform. The Android platform provides a framework API that applications can use to interact with the underlying Android system. The framework API consists of:
- A core set of packages and classes.
- A set of XML elements and attributes for declaring a manifest file.
- A set of XML elements and attributes for declaring and accessing resources.
- A set of Intents.
- A set of permissions that applications can request, as well as permission enforcements included in the system.
Uses of API level in Android
The API level identifier serves a key role in ensuring the best possible experience for users and application developers:
- It lets the Android platform describe the maximum framework API revision that it supports.
- It lets applications describe the framework API revision that they require.
- It lets the system negotiate the installation of applications on the user’s device, such that version-incompatible applications are not installed.
Each Android platform version stores its API level identifier internally, in the Android system itself.
What is SdkVersion?
Applications can use a manifest element provided by the framework API – to describe the minimum and maximum API levels under which they are able to run, as well as the preferred API level that they are designed to support. The element offers three key attributes:
- minSdkVersion: Specifies the minimum API level on which the application is able to run. The default value is “1”.
- targetSdkVersion: Specifies the API level on which the application is designed to run. In some cases, this allows the application to use manifest elements or behaviors defined in the target API level, rather than being restricted to using only those defined for the minimum API level.
- maxSdkVersion: Specifies the maximum API level on which the application is able to run.
When the user attempts to install an application, or when revalidating an application after a system update, the Android system first checks the attributes in the application’s manifest and compares the values against its own internal API level. The system allows the installation to begin only if these conditions are met:
- If android:minSdkVersion attribute is declared, its value must be less than or equal to the system’s API level integer. If not declared, the system assumes that the application requires API level 1.
- If android:maxSdkVersion attribute is declared, its value must be equal to or greater than the system’s API level integer. If not declared, the system assumes that the application has no maximum API level.
How to change Android app SdkVersion
You can use Android Studio to change your Android app API level (SDK Version) with these two methods.
a. In build.gradle file
- Select “Project” in the Project View.
- Under app folder, select “build.gradle” file.
- You can now edit the minSdkVersion and targetSdkVersion displayed in the right panel.
- Once done, click on “Sync” on the top right corner of the “build-gradle” file.
b. In project structure dialog
- From the top menu, select File > Project Structure.
- In the Project Structure dialog, select “app” in the Modules list.
- Select “Flavors” tab in the right panel.
- Select your desired minSdkVersion and targetSdkVersion.
- Click “OK” to save the selection.
- From the top menu, click Build > Rebuild Project, to rebuild the Android project.
- The build.gradle file will be changed automatically.