2 min read

Adding external packages to your app can make things easier for you and allows you to focus on the mission-critical feature of your app. But sometimes when you add the packages, you may face an issue that asks you to increase the Android minSdkVersion. This happens because the plugin requires a higher android sdk version for projects that were created before and after Flutter 2.8 update. So in this tutorial, we’ll see how to change Android minSdkVersion in Flutter.

Here’s what we’ll cover:

Ways to Change Android minSdkVersion in Flutter

There are two ways you can change Android minSdkVersion. The first one is for the projects that are created before Flutter 2.8 update and the second one is for the projects created after the Flutter 2.8 update.

For the Project Created Before Flutter 2.8 Update

To change minSdkVersion in Flutter for the project created before 2.8 update, you directly make changes inside the build.gradle file.

Steps 

Step 1: Locate the build.gradle file under the project_folder/android/app/build.gradle 

Step 2: Find the defaultConfig section update the minSdkVersion to the new version.

Step 3: Inside the terminal, run the flutter clean command.

Step 4: Re-run your app.

Code Example

defaultConfig {
    applicationId "com.example.common_project"
    minSdkVersion 21 // <-- SEE HERE
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

Screenshot

change android minsdkversion for projects before flutter 2.8. update

For the Projects Created After Flutter 2.8 Update

To change Android minSdkVersion in Flutter for the project created after the 2.8 update, you have to make changes in the local.properties file and then reference the new variable from the local.properties file inside the build.gradle file.

Steps

Step 1: Locate the local.properties file under the project_folder/android/local.properties

Step 2: Inside the local.properties file, add the line as flutter.minSdkVersion=21

Step 3: Now, open the build.gradle file under the project_folder/android/app/build.gradle

Step 4: Find the defaultConfig section update the minSdkVersion to the localProperties.getProperty(‘flutter.minSdkVersion’).toInteger().

Step 5: Inside the terminal, run the flutter clean command.

Step 6: Re-run your app.

Code Example

Under local.properties file
sdk.dir=/Users/pinkeshdarji/Library/Android/sdk
flutter.sdk=/Users/pinkeshdarji/Data/Development/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=20 #new
-----------------------------
Under build.gradle file
defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.sample_project"
    minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

Screenshot

change android minsdkversion for projects after flutter 2.8. update

Conclusion

In this tutorial, we saw how to change Android minSdkVersion in Flutter with practical examples. We explored both ways to change the SDK version in Android for the projects created before and after Flutter 2.8 update.

Would you like to check other interesting Flutter tutorials?