361

I was trying to start a flutter project for an App using Bluetooth to communicate. For that, I was using flutter blue.

Unfortunately, when trying to run (on an Android device) the first example I created I was met with the following error:

FAILURE: Build failed with an exception.

  * What went wrong:
  Execution failed for task ':app:processDebugManifest'.
  > Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:flutter_blue] /home/maldus/Projects/flutter/polmac/build/flutter_blue/intermediates/manifests/full/debug/AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
            or increase this project's minSdk version to at least 19,
            or use tools:overrideLibrary="com.pauldemarco.flutterblue" to force usage (may lead to runtime failures)

If I were on Android Studio, I'd know how to bump up the Android minSdkVersion, but on a Flutter project (using VSCode) I was a little lost.

Is it possible to increase the minSdkVersion with Flutter, and how?

Karma
  • 1
  • 1
  • 3
  • 9
Maldus
  • 10,548
  • 4
  • 24
  • 36
  • Background info on minSdkVersion that may be helpful: https://developer.android.com/ndk/guides/sdk-versions#minsdkversion – Mark Gavagan Jan 08 '21 at 19:25
  • This might be useful: https://stackoverflow.com/questions/70485898/where-is-the-value-of-flutter-minsdkversion-in-flutter-project-initialized – Ryan Jul 12 '22 at 22:42

25 Answers25

502

It is indeed possible to increase minSdkVersion, but it took me way too much time to find it out because google searches mostly yields as result discussions about the absolute minimum Sdk version flutter should be able to support, not how to increase it in your own project.

Like in an Android Studio project, you have to edit the build.gradle file. In a flutter project, it is found at the path ./android/app/build.gradle.

The parameter that needs to be changed is, of course, minSdkVersion 16, bumping it up to what you need (in this case 19).

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.projectname"
    minSdkVersion 19 //*** This is the part that needs to be changed, previously was 16
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Seems obvious now, but took me long enough to figure it out on my own.

Maldus
  • 10,548
  • 4
  • 24
  • 36
  • 29
    The file-path was very helpful! I was looking at the build.gradle file under `android/` and couldn't figure out for the life of me how to get this minSdkVersion to be updated. – Adam May 12 '19 at 05:17
  • 2
    What if I do not want to change the minSdkVersion as I want to target the lower SDK versions? @Maldus – pblead26 Jun 18 '19 at 19:57
  • 1
    Then don't change it? I'm not sure I understand the question, I hit this issue because flutterblue did not work without changing the minSDKVersion. If you want to use flutterblue with a lower SDK version I'm afraid that's a problem of the flutter library. – Maldus Jun 20 '19 at 13:06
  • @pblead26 Facing the same issue. Seems no other way apart from increasing minSdkVersion. – Faizan Mubasher Feb 26 '21 at 05:21
  • 2
    Using this approach is not a good idea! The answers from Francis Nduba & (Mr Random & Jahidul Islam) provide two good approaches. Approach from (Mr Random & Jahidul Islam) should be used when you want to override the minSdkVersion for a particular project only and want to keep the default minSdkVersion unchanged. The approach from Francis Nduba should be used when you want to use a particular minSdkVersion for all of your flutter projects. Generally, you should not change the default flutter minSdkVersion for all projects unless required by any of your packages/features. – irshukhan Jan 28 '22 at 07:08
  • Check out [this](https://www.flutterbeads.com/change-android-minsdkversion-in-flutter/) article to update mindSdkVersion in flutter – Muhammad Afzal Jun 06 '22 at 08:56
261

Flutter 2.8 or Later

build.gradle update

Before Updating to Flutter 2.8

android {
    compileSdkVersion 30

defaultConfig {
    applicationId "com.example.app"
    minSdkVersion 21
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
}

After updating to Flutter 2.8:

android {
    compileSdkVersion flutter.compileSdkVersion

defaultConfig {
        applicationId "com.example.app"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

You should change from local.properties following instruction:

  1. First go to the android->local.properties

enter image description here

  1. And changes from here

enter image description here

  1. Change like this from build.gradle
android {
    compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()

defaultConfig {
    minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
    targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}
Jahidul Islam
  • 11,435
  • 3
  • 17
  • 38
  • 2
    do you know why it doesn't appear while i created new project? – Karin Dec 17 '21 at 02:33
  • Actually, it is generated by default, but if you don't get in the android folder then create it manually. – Jahidul Islam Dec 17 '21 at 05:49
  • 2
    It's not working for me – WebMaster Dec 20 '21 at 08:51
  • after setting sdk please restart your ide or manually set the value in build.gradle – Jahidul Islam Dec 20 '21 at 09:28
  • 5
    you cant directly read `flutter.minSdkVersion ` use `localProperties.getProperty('flutter.minSdkVersion')` check out my answer https://stackoverflow.com/questions/52060516/how-to-change-android-minsdkversion-in-flutter-project/70452027#70452027 – Mr Random Dec 22 '21 at 16:17
  • I get > Cannot invoke method toInteger() on null object Error when building for release – SwiftiSwift Jan 08 '22 at 11:48
  • 65
    `local.properties` file is normally not under [source control](https://github.com/flutter/flutter/blob/0ce527eb91a37ef31b60ed6d4a9613310f2107d4/.gitignore#L68). So I don't think is a good place where to have important non-local config like this. – David Miguel Feb 10 '22 at 08:38
  • again got an issue : > One or more issues found when checking AAR metadata values: Dependency 'androidx.core:core:1.9.0-alpha05' requires 'compileSdkVersion' to be set to 32 or higher. Compilation target for module ':app' is 'android-31' – JoelSebstn Jul 16 '22 at 19:48
  • @DavidMiguel See `@GelidGeorge` answer below for what i consider a much better solution with the recent default configuration. It considers the local.properties values but defaults to hardcoded props if unset. – Emile Nov 04 '22 at 10:43
  • @DavidMiguel then, where and how would you do it? – Guillem Poy Dec 18 '22 at 08:42
162

If you didn't know, Google Playstore only allows minSdkVersion to be 20 or above. But flutter has still set default minSdkVersion to 16. Can you see that you'll be always obliged to manually change for each new project?

All your suggestions above are good, but they are not the best, because you will be forced to temper with the build.gradle for each new project you create.

The best way is to modify the value of the global minSdkVersion variable from its source, so all projects, new or old, will adopt it. Remember flutter.minSdkVersion means that the variable is in flutter directory (with the sdk).

The file in question is flutter.gradle.

the address is flutter-directory/packages/flutter_tools/gradle/flutter.gradle

class FlutterExtension {
    /** Sets the compileSdkVersion used by default in Flutter app projects. */
    static int compileSdkVersion = 31

    /** Sets the minSdkVersion used by default in Flutter app projects. */
    static int minSdkVersion = 16

    /** Sets the targetSdkVersion used by default in Flutter app projects. */
    static int targetSdkVersion = 31

change the value of the minSdkVersion from 16 to 20 or above, and do not disturb the code in build.gradle.

If you want, you can watch a video I made on Youtube, explaining it under: flutter configure minSdkVersion from 16 to 20 or above

Francis Nduba Numbi
  • 2,499
  • 1
  • 11
  • 22
  • 9
    Thanks @Francis Nduba Numbi, this is by far the best answer. That way I don't have to make changes on every individual project. My approach is to always target higher versions by default and only do backward compatibility for certain projects. – paulobunga Jan 08 '22 at 15:05
  • 2
    Thank you. You can vote as the best answer and close it. it will very much help. – Francis Nduba Numbi Jan 08 '22 at 23:30
  • 11
    I would argue that you should change the build.gradle file. Changing the global variable only affects your own system, so if someone else on your team (or a CI/CD pipeline) clones the project, they will have trouble building it. – Jani Jan 20 '22 at 07:05
  • 2
    Nice point. Then, you should leave a note in ReadMe to inform of the minimum minSdkVersion – Francis Nduba Numbi Jan 23 '22 at 10:21
  • Good information about **flutter.gradle** file, thanks @FrancisNdubaNumbi – mohmdezeldeen Mar 09 '22 at 21:46
  • 42
    I'm sorry, this is an extremely bad answer. You shouldn't be changing the source of the tool if you want to change the project. This means a project in source control doesn't have its own build info defined (it won't compile the same on different computers), that EVERY project on one's computer will be using that version, and that upgrading Flutter will break it. The tool should be independent of the project. To be clear: this should NOT BE DONE under ANY CIRCUMSTANCE no matter how "easy" it looks. Anyone wanting to pin their build to a specific version should edit `build.gradle` directly. – zeh Mar 10 '22 at 03:52
  • Google Playstore requests that minSdkVersion be 20 or above, only that flutter has not updated it to meet the requirements. So what the need to keep it at 16 knowing that you will be obliged to manually change it for every project ? – Francis Nduba Numbi Mar 10 '22 at 08:12
  • /packages/............ – who-aditya-nawandar Mar 29 '22 at 10:44
  • 10
    I do not recommend using this answer. This should be set at the project level – Luke Pighetti Apr 20 '22 at 01:47
  • If you didn't know, Google Playstore only allows minSdkVersion to be 20 or above. But flutter has still set default minSdkVersion to 16. Can you see that you'll be always obliged to manually change for each new project? – Francis Nduba Numbi Apr 21 '22 at 08:09
  • Good point and this should be voted as the best answer - change once and use in all flutter projects – Kenneth N Jul 29 '22 at 12:31
  • 2
    NEVER adopt a solution which won't be reflected in your source code control. Any other dev should be able to install the tools, take your code, and compile as is... Flutter might be wrong to still specify rev 16, but again this should be worked around in your project files. Nice info on the default settings location though! – Will59 Aug 09 '22 at 10:24
  • 1
    Can you please back up your claim that 'Google Playstore only allows minSdkVersion to be 20 or above'. I can't find this mentioned anywhere in Google's documentation. I can only see targetSdkVersion mentioned in Google's documentation, but targetSdkVersion and minSdkVersion are different things. – Wes1324 Dec 13 '22 at 20:15
  • 1
    If you have ever deployed an app on Playstore, you will have noticed that requirement of minimum SDK version. I have stated it by experience, not by reading documentations. – Francis Nduba Numbi Dec 16 '22 at 23:26
  • It's completely incorrect that Google Play requires minSdkVersion to be high. Just sampling the apps on my phone, several perfectly good apps from the Play Store have minSdkVersion of 19 or less, some as low as 14. And there's zero reason why Google would make such a requirement. // What you are thinking of is the requirements on the *target* SDK version, which is a very different thing. Flutter defaults to a targetSdkVersion of 33, the latest version, as it should. – Greg Price Feb 22 '23 at 23:36
  • My friend. I have put many apps on playstore recently. if the minSdkVerison is less that 20, it will not pass. When you say it is incorrect, is it out of experience or out of assumptions ? older apps which are updated may still have minSdkVersion lower than 20. But newly put apps will not. – Francis Nduba Numbi Feb 25 '23 at 19:48
  • In fact for a better performance of your app, better set the minSdkVersion to 21. – Francis Nduba Numbi Feb 25 '23 at 19:58
  • In flutter version 3.13.0^, you should edit the file: flutter-directory\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy – Tim Kariuki Aug 22 '23 at 17:40
62

For flutter v2.8

Inside local.properties add

sdk.dir='<path>'
flutter.sdk='<path>'
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1

flutter.minSdkVersion=21
flutter.targetSdkVersion=30
flutter.compileSdkVersion=30

app-level build.gradle

defaultConfig {
    minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
    targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

Now you can use localProperties.getProperty() to read the value from the properties file.

Mr Random
  • 1,992
  • 7
  • 20
46

You can change the minSdkVersion in the file Project_Name/android/app/build.gradle , defaultconfig :

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.projectname"
    minSdkVersion 16 // <--- There
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Trect
  • 2,759
  • 2
  • 30
  • 35
Roger Cuesta
  • 902
  • 1
  • 8
  • 12
34

With the new Flutter projects (2.8.0), with the 'Flutter style', you able to change minimum sdk version in local.properties (instead of editing app/build.gradle file).

# android/local.properties

flutter.minSdkVersion=19

Look in android/app/build.gradle file, you'll see the variable constraint like this:

# android/app/build.gradle

android {

  defaultConfig {
    minSdkVersion flutter.minSdkVersion
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
  }
}
dphans
  • 1,543
  • 19
  • 20
30

Here the detailed solution for changing MinSdk /Minsdk version error, follow the steps.

Add following lines on android\local.properties

sdk.dir=
flutter.sdk=C:\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1

flutter.minSdkVersion=21
flutter.targetSdkVersion=31
flutter.compileSdkVersion=31

android\local.properties

Delete existing lines and paste it on app level build.gradle: android\app\build.gradle

       defaultConfig {
        applicationId "app-id"

        minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
        targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
}

enter image description here

Rahul Raj
  • 1,010
  • 9
  • 10
14

All answers are best. But the following way is best in changing SdkVersion after Flutter 2.8 :

Go to your root directory where flutter is installed. It should be like

C:\src\flutter\flutter

Then go to

packages>Flutter tools>gradle>

In Gradle, you will see many files, locate flutter.gradle . Right-click on it and edit it with text editor/notepad.

here you will find all SDK versions. Change them, save, and then you are ready to go

the complete path should be like this: (in my case)

C:\src\flutter\flutter\packages\flutter_tools\gradle

In the image you can see SDKs

Aizan Sagheer
  • 349
  • 3
  • 8
14

Add the following lines to android/local.properties file:

flutter.versionCode=1
flutter.versionName=0.0.1
flutter.flutterMinSdkVersion=24
flutter.flutterTargetSdkVersion=31

Add the following lines at the top-level in the file may be after "def versionName =" in the file android/app/build.gradle:

def flutterMinSdkVersion = localProperties.getProperty('flutter.flutterMinSdkVersion')
if (flutterMinSdkVersion == null) {
    flutterMinSdkVersion = '16'
}

def flutterTargetSdkVersion = localProperties.getProperty('flutter.flutterTargetSdkVersion')
if (flutterTargetSdkVersion == null) {
    flutterTargetSdkVersion = '31'
}

finally edit the section of the build.gradle that match as follows:

    defaultConfig {
        applicationId "do.main.subdomain" // Use your App ID
        minSdkVersion flutterMinSdkVersion.toInteger()
        targetSdkVersion flutterTargetSdkVersion.toInteger()
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

Once all this is done you are good to go. Next time you want to update something you only have to change one file.

Manuel Rauber
  • 1,583
  • 1
  • 17
  • 39
GelidGeorge
  • 375
  • 3
  • 6
  • 1
    This is absolutely the correct answer. Applying defaults for when local.properites are null. `local.properites` is not the correct place to put build versions and is just asking for trouble unless your testing for a specific release. – Emile Nov 04 '22 at 10:40
  • Agree - best answer. – Sneg Nov 20 '22 at 14:32
8

This is how I approached when I got this issue recently:

Inside <your-project>/android/app/build.gradle

Find android -> defaultConfig -> minSdkVersion and replace it with

minSdkVersion Math.max(flutter.minSdkVersion, 21)

21 here can be replaced by whatever minimum version you would want.

In case flutter start supporting 23 or some other higher version as the minimum version and you decide to upgrade flutter for your project, it would still work.

Rahul
  • 3,529
  • 1
  • 5
  • 19
6

Follow these steps to change the minSdkVersion problem.

First=> YouProject_name/android/app/build.gradle

Second=> defaultconfig { //you can find it inside build.gradle }

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.umair.product_details_using_crud"
        minSdkVersion 16 // here you can change minSdkVersison
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
Javad Dehban
  • 1,282
  • 3
  • 11
  • 24
Umair Afzal
  • 99
  • 1
  • 6
4

I found the best way to fix this so it performs globally across all of your future apps as well is by changing the setting in the flutter.gradle file located in your default build section. If you're using VSCode

  1. go to this location (or the location you've installed flutter) C:\src\flutter\packages\flutter_tools\gradle\
  2. drag the flutter.gradle file into VSCode
  3. update the min, compile, and/or target versions
  4. save
Payne Danger
  • 139
  • 1
  • 2
4
    **android/local.properties**
flutter.versionCode=1
flutter.minSdkVersion=21
flutter.targetSdkVersion=30
flutter.compileSdkVersion=31

  **android/app/build.gradle**
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()

targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
1

I encountered this problem setting up Auth0, flutter_appauth and flutter_secure_storage within my flutter app. After changing the minSdkVersion version, I got this error

C:\Users\myusername\AndroidStudioProjects\wole\android\app\src\debug\AndroidManifest.xml Error:
    Attribute data@scheme at AndroidManifest.xml requires a placeholder substitution but no value for <appAuthRedirectScheme> is provided.
FAILURE: Build failed with an exception.
  • What went wrong: Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute data@scheme at AndroidManifest.xml requires a placeholder substitution but no value for is provided.

The solution is adding manifestPlaceholders thus

view image

Chandan
  • 11,465
  • 1
  • 6
  • 25
1

Setting minSdkVersion, targetSdkVersion, and compileSdkVersion are a little bit different starting from Flutter 2.8. Now the gradle file in your_flutter_app/android/app/build.gradle path looks like this:

enter image description here

Just replace the current values with the version numbers you want, like this:

enter image description here

Now run your flutter project, and that's it.

sm_sayedi
  • 326
  • 2
  • 17
1

change local.properties file mentioned below.. because currently playstore update minimum target api version atleast 30

sdk.dir=/Users/sweetnandha/Library/Android/sdk
flutter.sdk=/Users/sweetnandha/FlutterDev/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.compileSdkVersion=32
flutter.minSdkVersion=21
flutter.targetSdkVersion=32

enter image description here

or

enter image description here

sweetnandha cse
  • 705
  • 7
  • 16
0

It's found inside the defaultconfig on [project_name]/android/app/build.gradle. defaultconfig

0

you can find out that folder with which flutter ( on mac or linux ) or in windows you can look here https://stackoverflow.com/a/304447/8122500 . then you can follow guide from @francis-nduba-numbi .

there is 2 type to change from

  1. from flutter.gradle ( recommendation change here for not spesifc/for future )
  2. or direct from build.gradle ( not recommended )
Yogi Arif Widodo
  • 563
  • 6
  • 22
0

Try this at android/app/build.gradel minSdkVersion 30 that should fix it but make sure you are at kotlin_version = '1.6.10' with your kotlin version.

ANORAK_MATFLY
  • 345
  • 3
  • 7
0

if you would like to set as global.

here is, just simple run flutter doctor -v and you will get your sdk location

, i think override sdk version in every projects is not good in the future.

➜  ~ flutter doctor -v
[✓] Flutter (Channel stable, 3.0.5, on macOS 13.5 22G74 darwin-arm, locale en-ID)
    • Flutter version 3.0.5 at /Users/yogiarifwidodo/dev/flutter

first

➜  ~ cd /Users/yogiarifwidodo/dev/flutter/

then

➜  flutter git:(stable) ✗ cd packages/flutter_tools/gradle

last

nano flutter.gradle

editing

ctrl + w , then type `compileSdk`
modif your sdk number
then `ctrl + x`
then `y`
then enter to save
Yogi Arif Widodo
  • 563
  • 6
  • 22
-1

app/build.gradle add this version code

Musfiq Shanta
  • 1,298
  • 13
  • 9
-1

In the current version of flutter (2.10.4) you should change it by going into Flutter sdk folder/packages/open flutter_tools open /gradle then open flutter.gradle and find static int minSdkVersion and change as per requirement

e.g: C:\Workspace\flutter\packages\flutter_tools\gradle\flutter.gradle

This is what you'll see in the flutter.gradle file

Apoorv Pandey
  • 2,118
  • 2
  • 11
  • 13
-1

defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.map" minSdkVersion 19 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName }

-3

Upgrade your compiled sdk version to 29 - higher

hope this will help you.

-4

first run flutter clean

then change the minSdkVersion in the file Project_Name/android/app/build.gradle , defaultconfig :