How to change Android minSdkVersion in Flutter Project?

To change the minSdkVersion for an Android app in a Flutter project, you need to modify the android/app/build.gradle file.

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.

For the Project Created Before Flutter 2.8 Update

Here are the steps to change minSdkVersion in Flutter for the project created before 2.8 update:

  1. Locate the build.gradle file under the project_folder/android/app/build.gradle 
  2. Find the defaultConfig section update the minSdkVersion to the new version.
  3. Inside the terminal, run the flutter clean command.
  4. Re-run your app.
defaultConfig {
    applicationId "com.example.common_project"
    minSdkVersion 21 // <-- SEE HERE
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

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.

Here are the steps:

  1. Locate the local.properties file under the project_folder/android/local.properties
  2. Inside the local.properties file, add the line as flutter.minSdkVersion=21
  3. Now, open the build.gradle file under the project_folder/android/app/build.gradle
  4. Find the defaultConfig section update the minSdkVersion to the localProperties.getProperty(‘flutter.minSdkVersion’).toInteger().
  5. Inside the terminal, run the flutter clean command.
  6. Re-run your app.

After making these changes, your Android app will have its minSdkVersion set to the specified value. Remember that setting minSdkVersion to a higher value means your app won’t be compatible with devices running older Android versions. Always consider the trade-offs and the target audience when choosing the minSdkVersion for your Flutter app.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More