Adjusting MinSdkVersion in Flutter for Android: 2 Simple Approaches [2023]

3 min read

Integrating external packages into your app can significantly streamline development, allowing you to focus on your app’s core functionality. However, sometimes this process triggers a requirement to increase the Android minSdkVersion due to the plugin’s demands. This scenario applies to projects created both before and after the Flutter 2.8 update. In this comprehensive tutorial, we’ll delve into how to modify the Android 'minSdkVersion' '(flutter.minsdkversion)' in Flutter, covering two distinct approaches for different project timelines.

Ways to Change Android MinSdkVersion in Flutter

Let’s explore the two methods to modify the Android minSdkVersion. The first method applies to projects initiated prior to the Flutter 2.8 update, while the second is tailored for projects commenced after the update.

For Projects Created Before Flutter 2.8 Update

For projects established prior to the 2.8 update, follow these steps to adjust the 'minSdkVersion' in your Flutter app:

  1. Locate the 'build.gradle' File: Navigate to the 'android/app directory' within your Flutter project. Inside this directory, locate and open the 'build.gradle' file using a text editor.

  2. Update the minSdkVersion: Inside the 'build.gradle' file, locate the 'defaultConfig' section. Modify the 'minSdkVersion' field to match your desired Android API level. For instance, to set the minimum API level to 21 (Android 5.0 - Lollipop), make the adjustment as follows:

Copy
defaultConfig {
    applicationId "com.example.common_project"
    minSdkVersion 21 // Update this line
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    // ... other configurations ...
}

Screenshot: Adjusting MinSdkVersion in Flutter for Android: 2 Simple Approaches [2023] - Mihir Pipermitwala

  1. Clean and Re-run: Save the 'build.gradle' file and execute the 'flutter clean' command in your terminal. Afterward, re-run your Flutter app.

For Projects Created After Flutter 2.8 Update

For projects initiated after the Flutter 2.8 update, altering the Android 'minSdkVersion' involves modifying the 'local.properties' file and referencing the new variable in the 'build.gradle' file. Here’s how:

  1. Locate the 'local.properties' File: Within your Flutter project, find and open the 'local.properties' file situated in the android directory.

  2. Add the 'flutter.minSdkVersion' Line: Inside the 'local.properties' file, add the following line to set the 'flutter.minSdkVersion' variable:

Copy
flutter.minSdkVersion=21
  1. Update the 'build.gradle' File: Open the 'build.gradle' file located in the 'android/app' directory. Within the 'defaultConfig' section, update the 'minSdkVersion' using the value from 'localProperties.getProperty('flutter.minSdkVersion').toInteger()'
Copy
defaultConfig {
    applicationId "com.example.sample_project"
    minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    // ... other configurations ...
}

Screenshot: Adjusting MinSdkVersion in Flutter for Android: 2 Simple Approaches [2023] - Mihir Pipermitwala

  1. Clean and Re-run: As before, save the 'build.gradle' file and execute the 'flutter clean' command in your terminal. Then, re-run your Flutter app.

Conclusion

This tutorial provided an in-depth exploration of adjusting the Android minSdkVersion (flutter.minsdkversion) in Flutter. By following the detailed steps and practical examples, you can seamlessly tailor the minimum Android API level to meet the requirements of your project. Whether you’re dealing with projects predating the Flutter 2.8 update or ones initiated thereafter, you now possess the knowledge to navigate this crucial aspect of app development.

Curious about other insightful Flutter tutorials? Explore our collection to further enhance your Flutter development expertise.

0 Comments
Related Recommended Videos

Yubikey - The Ultimate Beginner Guide (How to Setup & Use)

The YubiKey is a hardware authentication device manufactured by Yubico to protect access to computers, networks, and online services that supports one-time passwords, public-key cryptography, and authentication, and the Universal 2nd Factor and FIDO2 protocols developed by the FIDO Alliance.

AUTHENTICATIONCRYPTOGRAPHYHARDWARESECURITYYOUTUBE

Master Flutter in Just 8 Hours | Full Course Hindi

Learn Flutter from basics to advanced in just 8+ hours. This covers everything related to UI, Data, Model, API, State Management, Navigator 2.0 and more.

ANDROIDANIMATED CONTAINERAPP BAR THEMEBUILD CONTEXTCARD

Flutter Master Class Travel App | Flutter 3.13.0 for Beginners to Advanced | iOS & Android Cubit

From this tutorial we build a flutter cubit / bloc state management app. We will build it step by step. We will also build the ui and do api request. We will cover http get request and load the data using flutter cubit or bloc. We will also see how to use bloc-provider and bloc-builder for state update. This covers building the model and API request. (not speed code, not the flutter way). So this is a travel app. It's also very beginners friendly app.

ANDROIDBLOCBLOC BUILDERBLOC CONSUMERBLOC LISTENER

Docker Tutorial for Beginners

Docker Tutorial for Beginners - Learn Docker for a career in software or DevOps engineering. This Docker tutorial teaches you everything you need to get started.

BEGINNERSDEV OPSDEVELOPMENTDOCKERPROGRAMMING LANGUAGE