Flutter项目qrcode_reader依赖Gradle同步报错求助
qrcode_reader: ^0.4.4 in Flutter Hey there, let's tackle this Gradle Sync issue you're facing with the qrcode_reader: ^0.4.4 dependency. The error message spells out exactly what's going on: this library requires a minimum Android SDK version (minSdk) of 16, but your project's minSdk is set to a lower value. Even though flutter run works (likely because your test device runs a newer Android version), Gradle's sync process enforces dependency compatibility checks, hence the error. Here are two reliable fixes:
Solution 1: Upgrade Your Project's minSdk Version (Recommended)
This is the safest approach, as it aligns your project with the library's requirements and avoids potential runtime crashes on older devices (most modern apps target minSdk 16+ anyway, so this is usually a no-brainer).
- Open the file
android/app/build.gradlein your Flutter project. - Find the
defaultConfigblock, then locate theminSdkVersionline. - Change its value from your current setting to
16. It should look like this:defaultConfig { // ... other existing configs minSdkVersion 16 // ... rest of your configs } - Save the file and re-run Gradle Sync. This should resolve the conflict without any tradeoffs.
Solution 2: Force Usage with tools:overrideLibrary (Use With Caution)
If you absolutely need to keep your project's minSdk below 16, you can force Gradle to ignore the version mismatch. Important note: This can lead to runtime failures on devices running Android versions lower than 16, since the library might use APIs that aren't available on older OS versions.
- Open
android/app/src/main/AndroidManifest.xml. - First, add the
toolsnamespace to the rootmanifesttag if it's not already present:<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.your.package.name"> - Then, add the
tools:overrideLibraryattribute to theapplicationtag, specifying the library's package name:<application tools:overrideLibrary="com.matheusvillela.flutter.plugins.qrcodereader" // ... other application attributes and content > - Save the file and re-run Gradle Sync. The error should disappear, but be prepared for possible crashes on older devices.
内容的提问来源于stack exchange,提问作者user10082972

