DEV3 Technologies home

DEV3 Developer Forum

Flutter Android build fails: "uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library". What do I change?

Flutter helpSolved0 views
dev3 ·

I added a plugin and the Android build now stops with:

Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:some_plugin]

Where do I set minSdk in a recent Flutter project?

#flutter#android#gradle

0

1 reply

dev3 · Accepted answer

Meaning

Your app declares a lower minimum Android version than the plugin supports. Raise the app's minSdk to at least what the plugin needs (the number in the message).

Where to set it

Open android/app/build.gradle (Groovy) or android/app/build.gradle.kts (Kotlin DSL, default in newer templates).

Groovy:

android {
    defaultConfig {
        minSdkVersion 21        // or: minSdk = 21
        targetSdkVersion flutter.targetSdkVersion
    }
}

Kotlin DSL:

android {
    defaultConfig {
        minSdk = 23
    }
}

Recent Flutter templates default to flutter.minSdkVersion, whose value rises over time (it is 24 in current stable releases, older ones used 21). Replace it with a literal number only when a plugin needs more than the default; check the plugin README for its requirement.

After changing

flutter clean
flutter pub get
flutter run

Other build-config errors people hit at the same time

  • "Unsupported class file major version": Gradle or the Android Gradle Plugin does not match your JDK. Flutter's tooling expects the JDK bundled with Android Studio; check with flutter doctor -v and set flutter config --jdk-dir <path> if needed.
  • "Could not resolve all files for configuration": a network or repository issue; check settings.gradle has google() and mavenCentral().
  • Multidex: with minSdk 21 or higher multidex is built in, which is another reason to raise it.

Pitfall

Raising minSdk drops older devices. Check the Play Console device stats for your audience before raising it further.

0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.