uses-sdk:minSdkVersion 16不能小于声明在库中的版本23。

18

我想使用Flutter包“audioplayers”,但当我运行代码时出现了这个错误

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.gradle中的minSdkVersion 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

如何解决它?


https://github.com/luanpotter/audioplayers/issues/720 - Pris0n
3个回答

33

您需要编辑位于项目目录内的build.gradle文件,例如:your_project_folder\android\app\build.gradle,找到并编辑此行:minSdkVersion 16,将其改为minSdkVersion 23,然后保存该文件,使用 flutter clean 命令清理一下,并运行它。

build.gradle文件中的defaultConfig应该长成这样:

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
    }
希望上述解决方案可行。或者更好的方法是使用旧版本的audioplayers。在你的 pubspec.yaml 文件中进行编辑。
dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  audioplayers: ^0.10.0

1
使用这个版本.. audioplayers: ^0.10.0 - dipakbari4
也适用于React Native :) - Aman Deep

2

我遇到了类似的问题,在build.gradle中更改SDK版本并不能解决问题。我只是将audioplayers降级到0.17.0,确保在0之前删除^。这对你应该有效。


无法解决问题,要么在我的情况下。它说:因为audioplayers> = 0.16.2 <0.18.0依赖于uuid ^ 2.2.2和feeddy_flutter依赖于uuid ^ 3.0.4,所以禁止使用audioplayers> = 0.16.2 <0.18.0。 因此,由于feeddy_flutter依赖于audioplayers 0.17.0,版本解析失败。 在feeddy_flutter中运行“flutter pub get”... pub get失败(1;因此,由于feeddy_flutter依赖于audioplayers 0.17.0,版本解析失败。) - Reinier Garcia

0

我添加了这些行,没有意识到它们已经存在于gradle.build中,所以最终出现了:

  minSdkVersion 23
  targetSdkVersion 30
  minSdkVersion flutter.minSdkVersion
  targetSdkVersion flutter.targetSdkVersion

所以这两个属性可能被替换为NULL或其他内容。

解决方案:在项目的根目录下添加一个local.properties文件,添加以下内容:

flutter.minSdkVersion=23
flutter.targetSdkVersion=30

同时保留gradle.build文件的原始内容:

  minSdkVersion flutter.minSdkVersion
  targetSdkVersion flutter.targetSdkVersion

并在下面添加

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

以下内容:

def minSdkVersion = localProperties.getProperty('flutter.minSdkVersion')

def targetSdkVersion = localProperties.getProperty('flutter.targetSdkVersion')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接