androidflutterdartdart-pub

Set Android minSdkVersion for Flutter & Pub


Is it possible to configure a Flutter app with a minimum Android SDK Version such that pub wont try and install dependency that require a higher android sdk version?

I've cloned a few repositories such as https://github.com/stonega/tsacdop and https://github.com/Teifun2/nextcloud-cookbook-flutter.

These have dependencies in pubspec.yaml like

dependencies:
  flutter:
    sdk: flutter

  #for app key
  url_launcher: ^6.0.3

When I execute flutter run I end up with error messages like:

Warning: The plugin path_provider_android requires Android SDK version 31.
Warning: The plugin url_launcher_android requires Android SDK version 31.
One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to /projects/sandbox/tsacdop/android/app/build.gradle:
android {
  compileSdkVersion 31
  ...
}

In my case I want to use the app on Android 11 (SDK Version 30), so updating the minimum version isn't the solution I'm looking for. Though I did follow How to change Android minSdkVersion in flutter project, but configuring android/app/src/build.gradle as suggested did not work:

defaultConfig {
   // setting these did NOT fix the compile errors
   minSdkVersion flutter.minSdkVersion
   targetSdkVersion flutter.targetSdkVersion
}

I've tried setting dependency to an explicit version in the pubspec.yaml file, which fixes some of the dependencies as a one-off, but it would be nice to find a universal solution.


Solution

  • Just assign your required SDK versions Like below. this will solve your compile error.

    defaultConfig {
      minSdkVersion 31
      targetSdkVersion 31
    }
    

    or you can change flutter.minSdkVersion and flutter.targetSdkVersion directly from flutter>packages>Flutter_tools>gradle>flutter.gradle https://stackoverflow.com/a/71440248/10936691