Reputation: 12295
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.
Upvotes: 4
Views: 7459
Reputation: 11
In flutter 3.x.x need to locate file:
..\flutter\packages\flutter_tools\gradle\src\main\groovy\ flutter.groovy
Then edit this:
class FlutterExtension {
/** Sets the compileSdkVersion used by default in Flutter app projects. */
static int compileSdkVersion = 34
/** Sets the minSdkVersion used by default in Flutter app projects. */
static int minSdkVersion = 19
/**
* Sets the targetSdkVersion used by default in Flutter app projects.
* targetSdkVersion should always be the latest available stable version.
*
* See https://developer.android.com/guide/topics/manifest/uses-sdk-element.
*/
static int targetSdkVersion = 34
Upvotes: 1
Reputation: 911
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
Upvotes: 4