Difference between "min SDK version", "target SDK version" and "compile SDK" version?

shamnad sheriefshamnad sherief
5 min read

TLDR;

Min SDK Version: The min sdk version is the earliest release of the Android SDK that your application can run on. If you set your minsSdkVersion to 21 then the app can be installed on Android 5.0 (Lollipop) and above. Users with older devices, such as those running Android 4.4 (KitKat), won’t be able to install your app.

Target SDK Version: The version your application was targeted to run on. By setting the targetSdkVersion to 33, your app will behave as if it is optimized for Android 13 features when it is running on devices with Android 13. It may run on earlier or later releases, but this is what you were aiming for.

Compile SDK Version: This is the version of the Android SDK that the build system (like Gradle) uses to compile your app’s source code into an APK (or AAB). It dictates which APIs are available during the compilation of your code. The version of Android used by your IDE to build your app into an APK. This means you can use Android API features included in that version of the API (as well as all previous versions). If you try and use API 34 features but set compileSdkVersion to 33, you will get a compilation error. If you set compileSdkVersion to 34 you can still run the app on a API 33 device.

minSdkVersion <= targetSdkVersion <= compileSdkVersion

Usually the compile sdk version and the target sdk version are the same.

What is an SDK?

SDK stands for Software Development Kit. In Flutter, the SDK is a set of tools that you use to build apps for both Android and iOS. The Flutter SDK allows you to write your app in Dart, and it compiles your code to native machine code for both platforms.

Just like in native Android development, Flutter has different SDK versions associated with Android. Each version of Android is assigned an API level. Here’s a quick rundown:

  • Android 12 = API level 31

  • Android 11 = API level 30

  • Android 10 = API level 29

Key SDK Versions in Flutter Development

When you create a Flutter app, you’ll find certain SDK version settings in the configuration files. Here’s what you need to know:

1. minSdkVersion

  • What is it? The minSdkVersion indicates the lowest Android version your Flutter app can run on. This is important because users with devices running a version lower than your minSdkVersion won’t be able to install your app.

  • Why is it important? Setting the minSdkVersion correctly allows you to reach a broader audience while ensuring your app runs smoothly on older devices.

  • How to set it? You can find the minSdkVersion in your android/app/build.gradle file:

      android {
          ...
          defaultConfig {
              ...
              minSdkVersion 21  // This means your app supports Android 5.0 (API level 21) and above
              ...
          }
      }
    

2. targetSdkVersion

  • What is it? The targetSdkVersion tells the Android system the highest API level that your app is designed and tested against. This is important for optimizing your app’s behavior according to that particular Android features.

  • Why is it important? Keeping your targetSdkVersion up to date ensures that your app utilizes the newest Android features and adheres to current best practices. It also helps your app remain compliant with Google Play policies.

  • How to set it? In the same build.gradle file, you’ll set the targetSdkVersion like this:

      android {
          ...
          defaultConfig {
              ...
              targetSdkVersion 31  // This means your app is optimized for Android 12 (API level 31)
              ...
          }
      }
    

3. compileSdkVersion

  • What is it? The compileSdkVersion specifies the Android SDK version used to compile your app’s code. It determines which Android features you can use in your Flutter app.

  • Why is it important? Setting the compileSdkVersion correctly allows you to access the latest APIs. However, it does not affect the compatibility of your app.

  • How to set it? Again, in your build.gradle file, you would set it like this:

      android {
          ...
          compileSdkVersion 31  // This allows you to use features available in Android 12
          ...
      }
    

Putting It All Together

In a typical Flutter app, you’ll define these SDK versions in the android/app/build.gradle file. Here’s an example of what it might look like:

android {
    compileSdkVersion 31

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
    }
}

Other Important Terms in Flutter SDK

Max SDK Version

  • What is it? The maxSdkVersion can be used to specify the highest version of Android that your app supports. However, it's rarely used and not recommended because it limits the audience.

  • Example:

      android {
          ...
          defaultConfig {
              ...
              maxSdkVersion 29  // This means your app won't run on Android versions higher than 10
              ...
          }
      }
    

Best Practices for SDK Versions in Flutter

  1. Set Min SDK Responsibly: Choose a minSdkVersion that allows your app to reach the largest possible audience while ensuring it functions correctly. For instance, if most of your users are on Android 6.0 (API level 23) or higher, you can set the minSdkVersion to 23.

  2. Update Target SDK Regularly: Make it a habit to keep your targetSdkVersion up to date with the latest Android version. This ensures your app remains functional and compliant with Google Play Store policies.

  3. Test Your App on Multiple Versions: Test your app on different devices and emulators to ensure it works well across the versions you’ve set in minSdkVersion and targetSdkVersion.

Conclusion

Understanding SDK versions in Flutter is essential for developing apps that work well across different Android devices and versions. By managing your minSdkVersion, targetSdkVersion, and compileSdkVersion, you can ensure your app is functional, user-friendly, and compliant with modern Android standards.

Start with a suitable minSdkVersion to reach more users, keep your targetSdkVersion updated to utilize new features, and always test your app on various Android versions. Following these guidelines will help you build a robust Flutter application that meets user expectations. Happy coding!

0
Subscribe to my newsletter

Read articles from shamnad sherief directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

shamnad sherief
shamnad sherief

The future needs more programmers — follow me to learn more about my adventures as a programmer!