3

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.

Philip Pittle
  • 11,821
  • 8
  • 59
  • 123
  • 3
    It isn't asking you to update your `minSdkVersion` or your `targetSdkVersion`, it is asking you to change your `compileSdkVersion` which is something [entirely different](https://medium.com/androiddevelopers/picking-your-compilesdkversion-minsdkversion-targetsdkversion-a098a0341ebd). – ianhanniballake Apr 11 '22 at 01:29
  • Setting `compileSdkVersion` was what I was missing, thank you kindly for the background! – Philip Pittle Apr 12 '22 at 06:20

1 Answers1

3

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

Kishan Busa
  • 821
  • 6
  • 14