494

I want to change the minimum SDK version in Android Studio from API 12 to API 14. I have tried changing it in the manifest file, i.e.,

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />

and rebuilding the project, but I still get the Android Studio IDE throwing up some errors. I presume I have to set the min SDK in 'project properties' or something similar so the IDE recognizes the change, but I can't find where this is done in Android Studio.

Laurel
  • 5,965
  • 14
  • 31
  • 57
James B
  • 8,975
  • 13
  • 45
  • 83
  • 1
    what is that some errors? we can't help you without logcat – Arash GM Oct 19 '13 at 10:46
  • 1
    They aren't compilation errors. It is the IDE giving a red underline when I'm trying to use `GridLayout' in the layout xml, i.e., telling me that a minimum API level 14 is required. Therefore, there must be somewhere in Android Studio where you can set the minimum API level after you have created the project. I have seen similar posts for Eclipse, but not for Android Studio. – James B Oct 19 '13 at 10:50
  • Have you instaled the API level 14 SDK package? – ramaral Oct 19 '13 at 11:34
  • If I start a new project and select API level 14 from the outset I have no problem developing in Android Studio, i.e., I must have API Level 14 SDK installed. However, if I simply want to update an existing project to use API 14 as minimum, I can't work out where in the Android Studio GUI IDE that I tell it to do this. – James B Oct 19 '13 at 11:42
  • Post your `Logcat`. and to change the `MinSDKVersion` this is the very simplest solution which u have already tried.. i.e.change in `Manifest` – Mitesh Shah Oct 19 '13 at 12:23
  • seems like this is a bug from Android Studio – GusDeCooL Dec 07 '13 at 18:12
  • You can update your API via wizard, see this link: http://stackoverflow.com/questions/21449947/how-do-i-set-the-minimum-api-level-for-projects-in-android-studio/25481715#25481715 – AsfK Aug 25 '14 at 08:19
  • @ArashGM Logcat is unnecessary, it has nothing to do with what he's asking, he's just asking how to change the API, not about the errors. (This was after the post was edited) – Devealte Jan 31 '19 at 11:17

16 Answers16

663

When you want to update your minSdkVersion in an existing Android project...

  1. Update build.gradle (Module: YourProject) under Gradle Script and
    make sure that it is NOT build.gradle (Project: YourProject.app).

An example of build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.2"

    defaultConfig {
        applicationId "com.stackoverflow.answer"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dependencies {
    androidTestCompile 'junit:junit:4.12'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
  1. Sync gradle button (refresh all gradle projects also works).

enter image description here
or
enter image description here

  1. Rebuild project

After updating the build.gradle's minSdkVersion, you have to click on the button to sync gradle file ("Sync Project with Gradle files"). That will clear the marker.

Updating manifest.xml, for e.g. deleting any references to SDK levels in the manifest file, is NOT necessary anymore in Android Studio.

Terry
  • 989
  • 8
  • 29
Sotti
  • 14,089
  • 2
  • 50
  • 43
  • 7
    My project's build.gradle is empty? What is the syntax to update? --- Ooops, there are two build.gradle files. I found the one in -> src has the versions, etc. – mobibob Dec 27 '13 at 18:00
  • 4
    Using this advice, I managed to get things to sync, but I had to EXIT Android Studio before the compile was error free. I performed many little steps, so I don't know what was really the necessary step. – mobibob Dec 28 '13 at 02:26
  • 5
    why have they made it such a ball ache? seem to remember in eclipse I only had to do this in one place... – Dean Wild Jun 10 '14 at 15:35
  • 1
    @DeanWild In Android Studio is as well in one place. Forget about API levels in the manifest file. – Sotti Jul 26 '14 at 09:37
  • 1
    Is it possible to make it use the manifest instead? Also, is it possible to make it always use the latest build-tools that are available? – android developer Jan 09 '15 at 15:42
  • 1
    As of now, you can find two build.gradle inside Gradle Scripts folder, I needed to go for the one having Module:app. – inquisitive May 19 '15 at 12:20
  • 1
    @androiddeveloper Gradle overrides the manifest, so just delete it from the gradle file and add it to your manifest file. I DO NOT recommend this tho, Gradle is the way to go and there are reasons why they went from manifest to gradle. – Sotti Jul 21 '15 at 09:21
  • @Sotti Thank you. Didn't know this. What's the benefit of putting it on the gradle file? – android developer Jul 21 '15 at 18:55
  • 1
    @Quantumdroid That is because you are using the Android view. I don't like that view and don't use it. – Sotti Sep 28 '15 at 21:21
  • 2
    For beginners in Android Studio "Sync gradle button" is located in `Tools -> Android -> Sync Project with Gradle Files` "Rebuild project" `Build -> Rebuild Project` – CGR Jun 28 '17 at 22:32
  • ... but then you need to build a signed APK to upload to Google Play. And chances are you get a "njet" message. Certain features that have become (an often) integral part of your application will prevent a "down-grade" of your min SDK. So, think twice about you min SDK wen starting a new project. – Steven Sep 19 '21 at 14:01
  • I found in the current version of Android Studio, the _Sync Project with Gradle Files_ is an option in the _File_ menu – ExploWare Jan 31 '22 at 09:43
196

Update 2022

For Android Studio users:

  1. Right click the App directory and
    Choose the "Open Module Settings" (F4) option Right click App then choose Open Module Settings

  2. Change the "Min SDK Version" in the Default Config tab
    Choose Min SDK Version NOTE:
    You might also want to change;
    the "Target SDK Version" in the Default Config tab and
    the "Compile SDK Version" in the Properties tab Choose Compile SDK Version

  3. Click Apply, then OK, and Gradle should automatically be synced


For users of older Android Studio versions:

  1. Right click the App directory and
    Choose the "Module Setting" (F4) option
  2. Change the ADK Platform to what you need
  3. Click OK and Gradle should automatically be synced
Ola Ström
  • 4,136
  • 5
  • 22
  • 41
user3291001
  • 1,969
  • 1
  • 11
  • 3
  • 6
    The above solution given is, to me, the best way to go. Let the tool do all the necessary changes iso you yourself fiddling with different files, taking the risk of screwing things or forgetting important details. – GeertVc Jul 22 '14 at 07:35
  • 2
    This doesn't work in Studio 0.8.2. You can change settings and press aplly, but studio ignore this.
    Solution: - Close Android Studio - Edit "/app/build.gradle" - change SDK-MinVersion entry - restart Android Studio Gradle syncs automatically
    – Martin Aug 05 '14 at 09:43
  • In Studio 1.4 you need to look in the "Flavors" tab. See priyankvex's answer. – Yannick Oct 25 '15 at 13:09
  • In Studio 3.5, you need to click the "Default Config" tab. Flavors tab doesn't appear to exist any more. – Sum None Sep 08 '19 at 17:26
142

As now Android Studio is stable, there is an easy way to do it.

  1. Right click on your project file
  2. Select "Open Module Settings"
  3. Go to the "Flavors" tab.

enter image description here

  1. Select the Min SDK Version from the drop down list

PS: Though this question was already answered but Android Studio has changed a little bit by its stable release. So an easy straight forward way will help any new answer seeker landing here.

Isuru
  • 30,617
  • 60
  • 187
  • 303
priyankvex
  • 5,760
  • 5
  • 28
  • 44
  • 1
    Editing the gradle files didn't work for me, but this did. Thanks! – Al0x Sep 05 '15 at 09:45
  • 2
    This has changed again: The "Flavors" tab is no more. Instead, on step 3, in the Project Settings area click Modules then use the Project Level drop down box to select the API version. This isn't the same as setting the min API version, but rather the version which will be used to build the app. – hamx0r Nov 12 '15 at 23:31
  • 3
    I only get api 23 in the dropdown... I need api 10 – Reign.85 Mar 07 '16 at 14:50
  • 1
    little bit? this fking IDE changes a lot between versions causing a lot of breaks in running old code. Very very pathetic compared to the legacy of backward compatibility that is exemplified by Microsoft. – user30478 Aug 31 '18 at 07:40
  • Accepted answer and the second most "accepted" answer didn't work for me, lots of errors on build, this is the right solution for me! thanks – Seichi Sep 13 '18 at 16:24
10

In android studio you can easily press:

  1. Ctrl + Shift + Alt + S.
  2. If you have a newer version of android studio, then press on app first. Then, continue with step three as follows.
  3. A window will open with a bunch of options
  4. Go to Flavors and that's actually all you need

You can also change the versionCode of your app there.

Daniel
  • 45
  • 1
  • 9
Salah Klein
  • 380
  • 3
  • 12
6

According to this answer, you just don't include minsdkversion in the manifest.xml, and the build system will use the values from the build.gradle file and put the information into the final apk.

Because the build system needs this information anyway, this makes sense. You should not need to define this values two times.

You just have to sync the project after changing the build.gradle file, but Android Studio 0.5.2 display a yellow status bar on top of the build.gradle editor window to help you

Also note there at least two build.gradle files: one master and one for the app/module. The one to change is in the app/module, it already includes a property minSdkVersion in a newly generated project.

Community
  • 1
  • 1
Meier
  • 3,858
  • 1
  • 17
  • 46
6

In build.gradle change minSdkVersion 13 to minSdkVersion 8 Thats all you need to do. I solved my problem by only doing this.

defaultConfig {
    applicationId "com.example.sabrim.sbrtest"
    minSdkVersion 8
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
}
Sabri Meviş
  • 2,231
  • 1
  • 32
  • 38
6

For the latest Android Studio v2.3.3 (October 11th, 2017) :
1. Click View on menu bar
2. Click Open Module Settings
3. Open Flavors tab
4. Choose Min Sdk version you need
IDE Project Structure Window 6. Click OK

AnneTheAgile
  • 9,932
  • 6
  • 52
  • 48
Rido
  • 717
  • 4
  • 10
  • 23
5

If you're having troubles specifying the SDK target to Google APIs instead of the base Platform SDK just change the compileSdkVersion 19 to compileSdkVersion "Google Inc.:Google APIs:19"

Juan Reyes
  • 404
  • 5
  • 9
4

As well as updating the manifest, update the module's build.gradle file too (it's listed in the project pane just below the manifest - if there's no minSdkVersion key in it, you're looking at the wrong one, as there's a couple). A rebuild and things should be fine...

Chris Rolliston
  • 4,788
  • 1
  • 16
  • 20
3

In Android studio open build.gradle and edit the following section:

defaultConfig {
    applicationId "com.demo.myanswer"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}

here you can change minSdkVersion from 12 to 14

nstCactus
  • 5,141
  • 2
  • 30
  • 41
3

File>Project Structure>Modules you can change it from there

Wisam Atil
  • 91
  • 1
  • 9
2

When you want to change minimum SDK you should take care of minSdkVersion[About] in module build.garadle

android {
  defaultConfig {
    minSdkVersion 21
  }
}
yoAlex5
  • 29,217
  • 8
  • 193
  • 205
1

Changing the minSdkVersion in the manifest is not necessary. If you change it in the gradle build file, as seen below, you accomplish what you need to do.

defaultConfig {
   applicationId "com.demo.myanswer"
   minSdkVersion 14
   targetSdkVersion 23
   versionCode 1
   versionName "1.0"
}
Chris Deck
  • 146
  • 2
  • 9
1

To change the minimum SDK version in Android Studio just...

1). Right click on "app" in the "Project" panel and choose "Open Module Settings"

Right click on "app"

2). Select the new "Min SDK Version" on the "Default Config" tab

Choose the new "Min SDK Version" on the "Default Config" tab

3). Click on "OK" and the project will now resync with the new Gradle settings.

Ola Ström
  • 4,136
  • 5
  • 22
  • 41
Snostorp
  • 544
  • 1
  • 8
  • 14
0

For me what worked was: (right click)project->android tools->clear lint markers. Although for some reason the Manifest reverted to the old (lower) minimum API level, but after I changed it back to the new (higher) API level there was no red error underline and the project now uses the new minimum API level.

Edit: Sorry, I see you were using Android Studio, not Eclipse. But I guess there is a similar 'clear lint markers' in Studio somewhere and it might solve the problem.

Jamppa
  • 11
  • 2
0

Gradle Scripts ->
build.gradle (Module: app) ->
minSdkVersion (Your min sdk version)

Hubert Hubert
  • 77
  • 3
  • 14