How to change the Minimum SDK version in Flutter
When using certain packages in your Flutter project, you may encounter error messages like the following: "uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:device_info_plus]". This error message indicates that you need to adjust the minimum SDK version for your application. The minimum SDK version determines the oldest Android version that your Flutter application can support. In this post, we will go over the steps of changing the minimum SDK version in a Flutter project.
1. Locate the build.gradle file
In the root directory of your Flutter project, navigate to the android
directory. Inside the android
directory, you will find the app
directory. Open the build.gradle
file located at android/app/build.gradle
.

2. Find the defaultConfig section
Within the build.gradle
file, locate the defaultConfig
section. This section contains various configurations for your Android application, including the minimum SDK version.
defaultConfig {
applicationId "com.example.codeonwards_demo"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
3. Update the minimum SDK version
Inside the defaultConfig
section, you will find a line that specifies the minSdkVersion
. By default, it is set to a value of flutter.minSdkVersion
which is 16
as of now. To change the minimum SDK version, update this value to your desired version.
defaultConfig { applicationId "com.example.codeonwards_demo" minSdkVersion 19 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName }
Now when you rebuild your application the error message will no longer appear and you will see that we have successfully changed the minSdkVersion
.
Step 4: Device support considerations
When increasing the minSdkVersion
, ensure that your application still functions on older devices unless you intentionally choose not to support them anymore. Keep in mind that each device has a limited number of Android versions it can be upgraded to. If your minSdkVersion
is higher than the supported Android version on older devices, they will not be able to use your application.
Conclusion
In this post, we went over the necessary steps to change the minimum SDK version in a Flutter application. By modifying the build.gradle
file, specifically the minSdkVersion
property within the defaultConfig
section, you can set the minimum Android version required for your Flutter application. This allows you to use packages that require a higher minimum SDK version. Remember to consider device support implications when adjusting the minSdkVersion
and its potential impact on your application's accessibility and user base.