Flutter错误: uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared

前言

今天要做蓝牙通信的功能,我使用了flutter_reactive_ble这个库,但是在运行的时候发现一下错误

Launching lib/main.dart on AQM AL10 in debug mode...

/Users/macbook/Desktop/test/flutter/my_app/android/app/src/debug/AndroidManifest.xml Error:

``uses-sdk:minSdkVersion ``16 cannot be smaller than version ``21 declared in library [:reactive_ble_mobile] /Users/macbook/Desktop/test/flutter/my_app/build/reactive_ble_mobile/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.signify.hue.flutterreactiveble" 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 [:reactive_ble_mobile] /Users/macbook/Desktop/test/flutter/my_app/build/reactive_ble_mobile/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.signify.hue.flutterreactiveble" 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 4s

┌─ Flutter Fix ─────────────────────────────────────────────────────────────────────────────────┐

│ The plugin reactive_ble_mobile requires a higher Android SDK version. │

│ Fix ``this issue by adding the following to the file │

│ /Users/macbook/Desktop/test/flutter/my_app/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-gradle-build-configuration │

└───────────────────────────────────────────────────────────────────────────────────────────────┘

Exception: Gradle task assembleDebug failed with exit code ``1

Exited

问题原因

自己项目的minSdkVersion比三方SDK的的minSdkVersion低,即版本不一致导致的。

解决办法

方法一

前往项目------>android------>app------>build.gradle文件搜索defaultConfig,将minSdkVersion修改成固定值即可

方法二

进入flutter环境安装目录/packages/flutter_tools/gradle(这里的flutter是环境变量中配置的flutter路径),搜索minSdkVersion,将值改为需求的版本即可(我这里改成21)

相关推荐
灰灰勇闯IT8 小时前
Flutter for OpenHarmony:图标与 Asset 资源管理 —— 构建高性能、可维护的视觉资源体系
flutter
子春一9 小时前
Flutter for OpenHarmony:构建一个 Flutter 记忆翻牌游戏,深入解析状态管理、动画交互与经典配对逻辑
flutter·游戏·交互
2601_9498477511 小时前
Flutter for OpenHarmony音乐播放器App实战13:歌手列表实现
flutter
雨季66611 小时前
破界与共生:HarmonyOS原生应用生态全景图谱与PC时代三重变局
flutter·华为·harmonyos
西西学代码12 小时前
Flutter---电流电压横向滑动折线图
flutter
2601_9498095912 小时前
flutter_for_openharmony家庭相册app实战+通知设置实现
android·javascript·flutter
mocoding14 小时前
使用鸿蒙化Flutter图片选择、相机拍照、多图选择三方库image_picker实战教程示例
flutter·前端框架·harmonyos·鸿蒙
一起养小猫15 小时前
Flutter for OpenHarmony 实战:电子英汉词典完整开发指南
flutter·harmonyos
wYb123_45616 小时前
Flutter for OpenHarmony软件开发助手app实战学习统计分析实现
学习·flutter
灰灰勇闯IT17 小时前
Flutter for OpenHarmony:深色模式下的 UI 优化技巧 —— 构建舒适、可读、无障碍的夜间体验
flutter·ui