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.
- minSdkVersion: This is the minimum version of android os that your app support.
- targetSdkVersion: This is the android os version that your app actually executed.
- 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.
- Select Project in android studio Project view.
- Edit <project-name>/app/build.gradle file.
- 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.
- Click the android studio menu ” File —> Project Structure “.
- In the Project Structure dialog, select the app item in the Modules list on the left side.
- Select the tab Flavors on the right panel, click the defaultConfig item in the dialog center list area.
- Then you can select your desired android Min Sdk Version and Target Sdk Version from the related dropdown list on the right side.
- Click the OK button to save the selection.
- Click the ” Build —> Rebuild Project ” menu item to rebuild the android project.
- 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.
- Recently, when I open android studio to develop an android project, I find a red underline in the layout.xml file(2022/05/24).
- When I hover the mouse over the redline, it shows the message that a minimum API level of 18 is required.
- So I need to change the minimum Android SDK version to 18 in the android studio.
- I tried to change it in the manifest.xml file like the below code
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="26" />
- But when I rebuild the android project, the error still exists.
- 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.
- The error only happens when I update the existing android project minimum SDK version number in the manifest.xml file.
- How can I do it in android studio?
2.2 Answer1.
- If you want to update an existing android project minSdkVersion number, you can not update it in the manifest.xml file.
- 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.
- Edit the minSdkVersion value in the Gradle Scripts/build.gradle(Module: your_app) file defaultConfig section like below.
defaultConfig { ...... minSdkVersion 18 targetSdkVersion 26 ...... }
- Click the Sync Now button on the build.gradle file top right corner to make the change take effect.
- Or you can click the Tools —> Android —> Sync Project with Gradle Files to sync the changes.
- Then you can rebuild the android project and find the error has been fixed.
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.
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.
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.
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.
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.
thank you so much dude. your page helped me a lot.?