skip to Main Content

How can I change the minimum SDK in an Android (Studio) project with recent (2020+) versions of Android Studio and Gradle?

During the creation of a new Android Studio project the wizard ask for the minimum SDK required.

Android Studio project creation wizard

Since the wizard generates a lot of boilerplate files and code, I assume that the boilerplate code is tailored to the minimum SDK chosen. My first objective is to generate a modern, lean, forward-compatible (Kotlin) app, so I chose API 31 (most recent non-beta on 29 Dec 2021). However, once the app (which is simple) is working, I would like to lower the minimum SDK to include as many devices as possible (without adding legacy dependencies, code, etc.). Is this a correct way to think about the relation between the choice of minimum SDK and the boilerplate code?

There are existing questions on older (2013) versions of Android Studio (and Gradle), e.g. here, but these do not work in modern versions of Android Studio and Gradle (I have only one build.gradle file and it does not mention any SDK, adding this gives errors).

EDIT: see below an image of the folder tree, as suggested.

folder tree

2

Answers


  1. Chosen as BEST ANSWER

    Based on the comments by Ricky Mo.

    The problem is that the default is the "Project View", which contains a build.gradle file that that defines the Kotlin version and the Android Studio Gradle plugin version.

    The build.gradle file that defines the minSDK is found in the app folder (screenshot).

    app build.gradle file

    Alternatively you can switch from the "Project View" to Android. From the dropdown menu that open when you click "Project" (screenshot, highlighted).

    View dropdown menu


  2. I believe all you need to do is set minSdkVersion like provided by this answer. The problems you may encounter are going to be massively different based on what you’re going to be doing, but mostly it should be OK. Of course, more you lower minSdkVersion, the more problems you will encounter, but it should be mostly ok to at least version 23.

    However, minSdkVersion is usually chosen at the beginning. You should probably set it to 21 (which covers 98% of devices) and start from there (industry standard is currently at 23, which covers 94.1% of devices).

    You should not be afraid of the app not being forward compatible because changes are usually quite small and there are ways to support different versions with ease and minSdkVersion doesn’t even affect forward compatibility. Also, supporting multiple versions does not make the final size of the app any larger. Code that is not called for a specific version gets deleted at build time, so you don’t have to fear having the app not lean because of lower SDK support. There is some build time performance penalty, but for a simple app, this is not noticeable. And in case there’s a blocker with SDK version being too low, it’s easier to raise it than lower it.

    Bottom line here I’d say is, that it is easy to set a low minSdkVersion from the beginning. The amount of possible issues you’ll encounter when lowering that version are probably not worth it and are also harder to fix than supporting a low SDK version from the beginning. And it all massively depends on the actual code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search