gradle Flutter apk build failed due to audio_players

s2j5cfk0  于 2023-04-06  发布在  Flutter
关注(0)|答案(1)|浏览(294)

我的应用程序使用audio_players播放音频。它在ios模拟器上运行良好,但当我尝试构建apk以在物理设备上运行应用程序时,我得到以下错误:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/Users/joshua/.pub-cache/hosted/pub.dev/audioplayers_android-2.0.0/android/build.gradle' line: 29

* What went wrong:
A problem occurred evaluating project ':audioplayers_android'.
> Failed to apply plugin [id 'de.mannodermaus.android-junit5']
   > android-junit5 plugin requires Gradle 6.1.1 or later

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* Where:
Script '/Users/joshua/Documents/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 463

* What went wrong:
A problem occurred configuring project ':audioplayers_android'.
> Failed to notify project evaluation listener.
   > Cannot invoke method substring() on null object
   > compileSdkVersion is not specified.

* 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 1m 56s
Running Gradle task 'assembleRelease'...                          118.0s
Gradle task assembleRelease failed with exit code 1
11dmarpk

11dmarpk1#

该错误消息表明有两个问题阻止您为应用构建APK。第一个问题与android-junit 5插件相关,该插件需要较新版本的Gradle。第二个问题与audioplayer_android插件相关,由于缺少compileSdkVersion,该插件无法配置项目。
要解决第一个问题,您可以更新项目中的Gradle版本。您可以通过修改项目根目录中的build.gradle文件并更新Gradle插件的类路径来完成此操作。例如:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.0.2' // the gradel is updated to 8.0.2
        classpath 'de.mannodermaus.gradle.plugins:android-junit5:1.7.1.1'
    }
}

要解决第二个问题,您需要在build.gradle文件中为audioplayers_android插件指定compileSdkVersion。例如:

android {
    compileSdkVersion 31
    ...
}

相关问题