You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目qrcode_reader依赖Gradle同步报错求助

Fixing Gradle Sync Error for 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:

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.gradle in your Flutter project.
  • Find the defaultConfig block, then locate the minSdkVersion line.
  • 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 tools namespace to the root manifest tag 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:overrideLibrary attribute to the application tag, 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:17:57