How To Change Minimum Sdk Version In Android Studio

When you use the android widget in layout XML or java code, you may encounter error messages like Call requires API level 23 (current min is 17):. This means your current android minimum SDK version is 1.7, which is too low to use this widget. You need to change it to 23. This article will show you how to change it in android studio.

First, we should know the below two terms about the android SDK version.

  1. minSdkVersion: This is the minimum version of android os that your app support.
  2. targetSdkVersion: This is the android os version that your app actually executed.
  3. Your app should compatible with all the android os versions between minSdkVersion and targetSdkVersion.

1. Change Android SDK Version In Android Studio.

There are two methods that can change the android SDK version in android studio.

1.1 Change in the android studio project build.gradle File.

  1. Select Project in android studio Project view.
  2. Edit <project-name>/app/build.gradle file.
  3. Change minSdkVersion and targetSdkVersion in the right panel. You can search for it if you can not find it immediately.

1.2 Change in android studio project structure dialog.

  1. Click the android studio menu ” File —> Project Structure “.
  2. In the Project Structure dialog, select the app item in the Modules list on the left side.
  3. Select the tab Flavors on the right panel, click the defaultConfig item in the dialog center list area.
  4. Then you can select your desired android Min Sdk Version and Target Sdk Version from the related dropdown list on the right side.
    android-project-structure-dialog
  5. Click the OK button to save the selection.
  6. Click the ” Build —> Rebuild Project ” menu item to rebuild the android project.
  7. This time the build.gradle file will be changed by android studio automatically.

2. How To Change Android Studio Minimum Android SDK Version In Existing Android Project.

2.1 Question.

  1. Recently, when I open android studio to develop an android project, I find a red underline in the layout.xml file(2022/05/24).
  2. When I hover the mouse over the redline, it shows the message that a minimum API level of 18 is required.
  3. So I need to change the minimum Android SDK version to 18 in the android studio.
  4. I tried to change it in the manifest.xml file like the below code
    <uses-sdk
    android:minSdkVersion="18"
    android:targetSdkVersion="26" />
  5. But when I rebuild the android project, the error still exists.
  6. I also find that if I create a new android project in android studio and make the new project use android SDK version 18 as the minim SDK version, there is no error.
  7. The error only happens when I update the existing android project minimum SDK version number in the manifest.xml file.
  8. How can I do it in android studio?

2.2 Answer1.

  1. If you want to update an existing android project minSdkVersion number, you can not update it in the manifest.xml file.
  2. You should update the Gradle Scripts/build.gradle(Module: your_app) file in the android studio, make sure not to edit the Gradle Scripts/build.gradle(Project: your_project) file.
  3. Edit the minSdkVersion value in the Gradle Scripts/build.gradle(Module: your_app) file defaultConfig section like below.
    defaultConfig {
          ......
          minSdkVersion 18
          targetSdkVersion 26
          ......
    }
  4. Click the Sync Now button on the build.gradle file top right corner to make the change take effect.
  5. Or you can click the Tools —> Android —> Sync Project with Gradle Files to sync the changes.
  6. Then you can rebuild the android project and find the error has been fixed.

6 thoughts on “How To Change Minimum Sdk Version In Android Studio”

  1. Please add the date the article was written in an obvious spot. Android studio tutorials become obsolete quickly but still come up in search results.

  2. I am new to android coding, and recently I just create a new android project in android studio, and I want to change the project minimum SDK and target SDK version, and this article just tell me how to do it, thanks a lot.

  3. This error occurred when I go to the google play store console to upload my android app. The google play store console said my android app API level must be 27 or higher, and my app API level is just 21.

  4. My android studio displays a red line under my layout xml code and prompt a minimum API level 19 is required error, My current android studio minimum SDK version is 12 and I want to change it to version 19 in the android project manifest file like below. But after I change it in the android project and rebuild the project, the error still exist.

    <uses-sdk
       android:minSdkVersion=”19″
       android:targetSdkVersion=”19″ />

    Finally I find this article and follow the steps in this article and fixed this issue. I am very happy, too many thanks to the article author.

  5. I’ve been working on this issue for two days. THANK YOU! Everywhere showed solution 1.1 and it just wasn’t working for me. Although my screen looks a lot different on Mac, I was able to follow 1.2 and resolve.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Clicky