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

Flutter项目Android SDK版本不兼容问题求助

Flutter Android版本冲突问题解决

问题详情

Flutter项目编译时出现Android SDK版本不兼容错误:images_picker插件要求minSdkVersion至少为21,但项目当前minSdkVersion为16。按照提示修改C:\Users\gewidydr\AndroidStudioProjects\carebuddy_version3\android\app\build.gradle中的minSdkVersion为21后,仍触发相同的Manifest合并错误。尝试升级Flutter导致Android Studio和模拟器崩溃,需在不重装Android Studio的前提下解决问题。

原始错误日志

One or more plugins require a higher Android SDK version.
Fix this issue by adding the following to C:\Users\gewidydr\AndroidStudioProjects\carebuddy_version3\android\app\build.gradle:
android {
  compileSdkVersion 33
  ...
}

C:\Users\gewidydr\AndroidStudioProjects\carebuddy_version3\android\app\src\debug\AndroidManifest.xml Error:
    uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:images_picker] C:\Users\gewidydr\AndroidStudioProjects\carebuddy_version3\build\images_picker\intermediates\merged_manifest\debug\AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
        or increase this project's minSdk version to at least 21,
        or use tools:overrideLibrary="com.chavesgu.images_picker" to force usage (may lead to runtime failures)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:images_picker] C:\Users\gewidydr\AndroidStudioProjects\carebuddy_version3\build\images_picker\intermediates\merged_manifest\debug\AndroidManifest.xml as the library might be using APIs not available in 16
    Suggestion: use a compatible library with a minSdk of at most 16,
        or increase this project's minSdk version to at least 21,
        or use tools:overrideLibrary="com.chavesgu.images_picker" to force usage (may lead to runtime failures)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 24s

┌─ Flutter Fix ─────────────────────────────────────────────────────────────────────────────────┐
│ The plugin images_picker requires a higher Android SDK version.                               │
│ Fix this issue by adding the following to the file                                            │
│ C:\Users\gewidydr\AndroidStudioProjects\carebuddy_version3\android\app\build.gradle:          │
│ android {                                                                                     │
│   defaultConfig {                                                                             │
│     minSdkVersion 21                                                                          │
│   }                                                                                           │
│ }                                                                                             │
│                                                                                               │
│ Note that your app won't be available to users running Android SDKs below 21.                 │
│ Alternatively, try to find a version of this plugin that supports these lower versions of the │
│ Android SDK.                                                                                  │
│ For more information, see:                                                                    │
│ https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration                 │
└───────────────────────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1

修改minSdkVersion后仍报错的日志

C:\Users\gewidydr\AndroidStudioProjects\carebuddy_version3\android\app\src\debug\AndroidManifest.xml Error:
uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:images_picker] C:\Users\gewidydr\AndroidStudioProjects\carebuddy_version3\build\images_picker\intermediates\merged_manifest\debug\AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="com.chavesgu.images_picker" to force usage (may lead to runtime failures)

项目pubspec.yaml依赖

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  get: ^4.6.5
  connectivity_plus: ^2.3.6
  shared_preferences: ^2.0.15
  cached_network_image: ^3.2.1
  flutter_svg: ^1.1.6
  carousel_slider: ^4.0.0
  smooth_page_indicator: ^1.0.0+2
  flutter_svg_provider: ^1.0.3
  intl: ^0.17.0
  permission_handler: ^10.0.0
  images_picker: ^1.2.11

解决方案

  • 确认build.gradle修改位置
    确保修改的是android/app/build.gradle中defaultConfig节点下的minSdkVersion,而非其他配置段。正确配置示例:

    android {
        defaultConfig {
            minSdkVersion 21
            // 其他配置(如targetSdkVersion、versionCode等)
        }
    }
    

    同时检查是否有构建变体(如flavor)或其他gradle脚本覆盖了该值。

  • 清理项目缓存
    执行以下命令清除旧的构建缓存,避免配置残留:

    flutter clean
    cd android && gradlew clean
    cd .. && flutter pub get
    
  • 强制Manifest合并(风险提示)
    若无法升级minSdkVersion,可在项目android/app/src/main/AndroidManifest.xml中添加tools:overrideLibrary属性强制合并,但低版本Android设备运行时可能崩溃:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="你的应用包名">
    
        <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="33"
            tools:overrideLibrary="com.chavesgu.images_picker"/>
        <!-- 其他Manifest内容 -->
    </manifest>
    
  • 降级images_picker插件
    查找images_picker历史版本中支持minSdkVersion=16的版本,修改pubspec.yaml中的依赖版本后执行flutter pub get。例如可尝试1.1.x系列版本(需自行验证兼容性)。

内容的提问来源于stack exchange,提问作者ge widydr

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 09:55:24