flutter:修改flutter的Android的minSdkVersion(Flutter 3.29.2)

 一,报错信息

Your project is configured with Android NDK 26.3.11579264, but the following plugin(s) depend on a different Android NDK version:
- audioplayers_android requires Android NDK 27.0.12077973
- flutter_sound requires Android NDK 27.0.12077973
- path_provider_android requires Android NDK 27.0.12077973
Fix this issue by using the highest Android NDK version (they are backward compatible).
Add the following to /Users/liuhongdi/StudioProjects/demo3/android/app/build.gradle.kts:

    android {
        ndkVersion = "27.0.12077973"
        ...
    }

/Users/liuhongdi/StudioProjects/demo3/android/app/src/debug/AndroidManifest.xml Error:
	uses-sdk:minSdkVersion 21 cannot be smaller than version 24 declared in library [:flutter_sound] /Users/liuhongdi/StudioProjects/demo3/build/flutter_sound/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml as the library might be using APIs not available in 21
	Suggestion: use a compatible library with a minSdk of at most 21,
		or increase this project's minSdk version to at least 24,
		or use tools:overrideLibrary="xyz.canardoux.fluttersound" 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 21 cannot be smaller than version 24 declared in library [:flutter_sound] /Users/liuhongdi/StudioProjects/demo3/build/flutter_sound/intermediates/merged_manifest/debug/processDebugManifest/AndroidManifest.xml as the library might be using APIs not available in 21
  	Suggestion: use a compatible library with a minSdk of at most 21,
  		or increase this project's minSdk version to at least 24,
  		or use tools:overrideLibrary="xyz.canardoux.fluttersound" 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 8s

┌─ Flutter Fix ─────────────────────────────────────────────────────────────────────────────────┐
│ The plugin flutter_sound requires a higher Android SDK version.                               │
│ Fix this issue by adding the following to the file                                            │
│ /Users/liuhongdi/StudioProjects/demo3/android/app/build.gradle:                               │
│ android {                                                                                     │
│   defaultConfig {                                                                             │
│     minSdkVersion 24                                                                          │
│   }                                                                                           │
│ }                                                                                             │
│                                                                                               │
│ Following this change, your app will not be available to users running Android SDKs below 24. │
│ Consider searching for a version of this plugin that supports these lower versions of the     │
│ Android SDK instead.                                                                          │
│ For more information, see: https://flutter.dev/to/review-gradle-config                        │
└───────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1

 

二,解决:

进入安装目录,例如:

/Users/liuhongdi/soft/flutter/packages/flutter_tools/gradle/src/main/groovy

编辑:

vi flutter.groovy

如下:

  50     /** Sets the minSdkVersion used by default in Flutter app projects. */
  51     //public  final int minSdkVersion = 21
  52     public  final int minSdkVersion = 24

指定 public  final int minSdkVersion 的值为 24

posted @ 2025-03-29 09:01  刘宏缔的架构森林  阅读(1302)  评论(0)    收藏  举报