I want to use a flutter package 'audioplayers' but when I run my code I have this error

C:\Users\Utilisateur\AndroidStudioProjects\xylophone_flutter\android\app\src\debug\AndroidManifest.xml Error:
    uses-sdk:minSdkVersion 16 cannot be smaller than version 23 declared in library [:audioplayers] C:\Users\Utilisateur\AndroidStudioProjects\xylophone_flutter\build\audioplayers\intermediates\library_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 23,
        or use tools:overrideLibrary="xyz.luan.audioplayers" to force usage (may lead to runtime failures)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 23 declared in library [:audioplayers] C:\Users\Utilisateur\AndroidStudioProjects\xylophone_flutter\build\audioplayers\intermediates\library_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 23,
        or use tools:overrideLibrary="xyz.luan.audioplayers" to force usage (may lead to runtime failures)

当我在myApp/android/app/build.gradleminSdkVersion 16改成23时,我又犯了一个错误

e: C:\Users\Utilisateur\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (181, 52): Expecting a parameter declaration
e: C:\Users\Utilisateur\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (231, 38): Expecting an argument
e: C:\Users\Utilisateur\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\ByteDataSource.kt: (8, 37): Expecting a parameter declaration
e: C:\Users\Utilisateur\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedMediaPlayer.kt: (10, 39): Expecting a parameter declaration
e: C:\Users\Utilisateur\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (168, 32): Expecting a parameter declaration
e: C:\Users\Utilisateur\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (205, 26): Expecting an argument
e: C:\Users\Utilisateur\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\audioplayers-0.17.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (46, 77): Type inference failed. Expected type mismatch: inferred type is List<???> but MutableList<WrappedSoundPool> was expected

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':audioplayers:compileDebugKotlin'.
> Compilation error. See log for more details

How to solve it?

推荐答案

您需要编辑位于项目目录内的build.gradle文件,如your_project_folder\android\app\build.gradle,并找到并编辑第minSdkVersion 16minSdkVersion 23行,然后使用flutter clean命令和runit保存该文件.

The defaultConfig should look like this inside the build.gradle file

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.your_package_name_here"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

希望上述解决方案能奏效.

Or better use the old version of audioplayers. Edit in your pubspec.yaml file

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  audioplayers: ^0.10.0

Kotlin相关问答推荐

如何在Kotlin中模拟www.example.com()?

为什么onEach不是挂起函数,而Collect是?

如何让Gradle8+在编译Kotlin代码之前编译Groovy代码?然后把它们混合在一个项目中?

哪个更好? Integer.valueOf(readLine()) 或 readLine()!!.toInt()

合并状态流

为什么Kotlin不用static inner class来实现带有object关键字的单例呢?

如何在 Jetpack Compose 中启动和停止动画

Flow.state In() 未从其来源接收新值

Kotlin 编译器在构造函数中报告未使用的表达式,以便构建器采用 vararg lambda

Kotlin 具体类从抽象类和接口扩展而来,接口使用抽象类中实现的方法

从字符串列表构建字符串

类型不匹配:Required: Context, Found: Intent

如何在 kotlin 中通过反射设置委托属性值?

找不到引用的类 kotlin.internal.annotations.AvoidUninitializedObjectCopyingCheck

禁用 Android 12 默认启动画面

在用Kotlin编写的Android库公共API中处理R8+JvmStatic Annotation+Lambda

如何使用kotlin中的反射查找包中的所有类

如何为kotlin异常生成SerialVersionId?

使用主构造函数时使用Kotlin getter/setter

Kotlin中的函数接口