bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
1.93k stars 825 forks source link

Build file '.pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle' line: 31 #1474

Closed nabtron closed 11 months ago

nabtron commented 1 year ago

I am getting this error when running flutter run

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/one/.pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle' line: 31

* What went wrong:
A problem occurred evaluating project ':audioplayers_android'.
> No signature of method: build_a63qjm1kfe3oz0etex305ie55.android() is applicable for argument types: (build_a63qjm1kfe3oz0etex305ie55$_run_closure2) values: [build_a63qjm1kfe3oz0etex305ie55$_run_closure2@16440ebf]

The flutter run --verbose shows this output:

 > Configure project :audioplayers_android
[        ] Evaluating project ':audioplayers_android' using build file '/Users/one/.pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle'.
[        ] Creating configuration androidTestUtil
[        ] FAILURE: Build failed with an exception.
[   +1 ms] * Where:
[        ] Build file '/Users/one/.pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle' line: 31
[        ] * What went wrong:
[        ] A problem occurred evaluating project ':audioplayers_android'.
[        ] > No signature of method: build_a63qjm1kfe3oz0etex305ie55.android() is applicable for argument types: (build_a63qjm1kfe3oz0etex305ie55$_run_closure2) values: [build_a63qjm1kfe3oz0etex305ie55$_run_closure2@5a21456d]
[        ] * Try:
[        ] Run with --debug option to get more log output. Run with --scan to get full insights.
[        ] * Exception is:
[        ] org.gradle.api.GradleScriptException: A problem occurred evaluating project ':audioplayers_android'.
[        ]      at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
[        ]      at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.lambda$apply$0(DefaultScriptPluginFactory.java:133)
[        ]      at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
[        ]      at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:136)
[        ]      at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:65)
[        ]      at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
[        ]      at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
.
.
.
.

Please guide how to proceed.

My pubspec.yaml file is:

name: pavlov_alarm
description: A new Flutter application.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.3
  intl: ^0.18.0
  # android_alarm_manager: ^2.0.2
  android_alarm_manager_plus: ^2.1.2
  shared_preferences: ^2.0.7
  url_launcher: ^6.0.10
  flutter_local_notifications: ^13.0.0
  flutter_local_notifications_platform_interface: ^6.0.0
  timezone: ^0.9.1
  rxdart: ^0.27.2
  flutter_native_timezone: ^2.0.0
  # flutter_datetime_picker: ^1.5.1
  # vibration: ^1.7.4-nullsafety.0
  vibration: ^1.7.6
  audioplayers: ^4.0.1
  # audioplayers: ^3.0.1
  # audioplayers: ^0.20.1
  future_progress_dialog: ^0.2.0
  flutter_credit_card: ^3.0.6
  flutter_stripe: ^9.0.0
  http: ^0.13.3
  hive: ^2.0.4
  hive_flutter: ^1.1.0
  path_provider: ^2.0.3
  flutter_picker: ^2.0.2
  hive_generator: ^2.0.0
  # hive_generator: ^1.1.1
  build_runner: ^2.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
  fonts:
    - family: JosefinSans
      fonts:
        - asset: assets/fonts/JosefinSans-Regular.ttf
  assets:
    - assets/sound1.wav

Thanks

Gustl22 commented 1 year ago

Plz use the issue template. Also did you try flutter pub cache cleanfollowed by flutter pub get. What OS? What flutter version?

ManuelFEMartinho commented 1 year ago

I have the same problem

I've tried your suggestion with flutter version 3.7.11, and android 9 and 12 and it doesn't work `FAILURE: Build failed with an exception.

BUILD FAILED in 1s Exception: Gradle task assembleDebug failed with exit code 1`

Thanks

wudiplk commented 1 year ago

I hava same problem: problem: FAILURE: Build failed with an exception.

BUILD FAILED in 1s

Android 13 Flutter (Channel master, 3.10.0-5.0.pre.1, on Microsoft Windows [版本 10.0.22621.1555], locale zh-CN) • Flutter version 3.10.0-5.0.pre.1 on channel master at D:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 954760829b (25 hours ago), 2023-04-12 22:42:12 -0400 • Engine revision 39ec48fd7e • Dart version 3.0.0 (build 3.0.0-437.0.dev) • DevTools version 2.23.1

andreclinio commented 1 year ago

Same problem here... (with Linux tryingo to build android)


> 
> $ flutter build appbundle --build-name=2.4.1 --build-number=020401 --release
> 
> 💪 Building with sound null safety 💪
> 
> 
> FAILURE: Build failed with an exception.
> 
> * Where:
> Build file '/home/macplinio/.pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle' line: 31
> 
> * What went wrong:
> A problem occurred evaluating project ':audioplayers_android'.
> > No signature of method: build_dqixdb5wjjyvp8dlev7u2si6w.android() is applicable for argument types: (build_dqixdb5wjjyvp8dlev7u2si6w$_run_closure2) values: [build_dqixdb5wjjyvp8dlev7u2si6w$_run_closure2@1f0f1c8e]
> 
> * 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.
m430 commented 1 year ago

+1

AlexanderKostiev commented 1 year ago

I had audioplayers 1.0.1 integrated into my app. Then I updated to the latest (4.0.1) and got the same error. When I rolled back to 1.0.1 the error was gone.

I've tried cleaning project and pub cache Reopening VSCode Upgrading Dart and Flutter to the latest versions

Nothing helped. So, for now, keeping 1.0.1 and waiting for the resolution

CodeGather commented 1 year ago

**/.pub-cache/hosted/pub.flutter-io.cn/audioplayers_android-3.0.1/android/build.gradle

// apply plugin: 'com.android.library'

Gustl22 commented 1 year ago

Can someone post their build.gradle file in android/app folder? Seems like you aren't allowed to use compileKotlin in newer versions :) See: https://youtrack.jetbrains.com/issue/KT-45183

For a working template see: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/android/build.gradle

AlexanderKostiev commented 1 year ago

@Gustl22 , please find it attached.

android/app/build.gradle

```gradle def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion flutter.compileSdkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.my-app.id" minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } lintOptions { checkReleaseBuilds false } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } ```

Gustl22 commented 1 year ago

@AlexanderKostiev Thanks for providing the file. Seems nothing suspicious in it. Can you compare it with the file in our example project: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/android/app/build.gradle https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/android/build.gradle

Pay attention to the kotlin and Build gradle (and maybe Java compatibility?) version. classpath 'com.android.tools.build:gradle:7.3.1' (android/build.gradle)

If you still don't succeed, try executing our example, and compare step by step. You also can delete the android folder and recreate it with flutter create ., but this would delete some customization steps in Android of course.

skibos commented 1 year ago

To get rid off this problem you have to update gradle in your project to min 7.3. I also had to change to:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip

in gradle-wrapper

andreclinio commented 1 year ago

I have just changed the gradle configuration as stated before:

classpath 'com.android.tools.build:gradle:7.3.1'
distributionUrl=https://services.gradle.org/distributions/gradle-7.4-all.zip

And I could generate my app for Android in a Windows environment. I will check Linux and post the results here later! Thanks!

luomo-pro commented 1 year ago

Has there been any progress on this issue? I am having the same problem

Gustl22 commented 1 year ago

@luomo-pro plz try the solution right above your comment...

luomo-pro commented 1 year ago

I have successfully run my software and modified gradle to 7.3.1 as described above. However, after the modification, I also encountered a lot of problems, here to say, I hope it will help others:

  1. after gradle to 7.3.1, the use of kotlin version must be 1.5.20 and above. My software uses a lot of packages on pub, and the kotlin version of those packages are relatively low, I can only manually modify the build.gradle file of each package one by one. If these packages are subsequently upgraded, but the kotlin version is not modified, then I have to modify them again, which is very troublesome.
  2. there are some build.gradle configuration, in gradle7.0 or above is no longer, if you still include these configuration content, it will report an error, and the error is reported inexplicably, no detailed error message. For example, the most critical, in 7.0 and above, has been removed useProguard true If you still use this, it will compile with errors. In short, if your software is older and uses a lot of packages, then upgrading to gradle 7.3 will require a lot of modifications to work properly.
vbuberen commented 1 year ago

Such issue appears on projects with Android Gradle plugin < 4.2, but I would suggest to move to 7.x versions already, like the person above did.

Here is a discussion about an issue: https://github.com/flutter/flutter/issues/125181#issuecomment-1525894244

echarish commented 1 year ago

Even after setting distributionUrl=https://services.gradle.org/distributions/gradle-7.4-all.zip

still getting the error

-- Anyone has any suggestions how to fix the issue?

vbuberen commented 1 year ago

Even after setting distributionUrl=https://services.gradle.org/distributions/gradle-7.4-all.zip

You changed the version of your Gradle wrapper, which is also something that you need to do. Android Gradle Plugin version should be changed in build.gradle of Android folder of your project.

echarish commented 1 year ago

in my androig/build.gradle putting

 ext.kotlin_version = '1.7.10'
 and dependencies to classpath 'com.android.tools.build:gradle:7.3.1'

Has got rid of audio player issue but now I ran into another lib giving me trouble :D project ':flutter_config' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61

bardram commented 1 year ago

Had the same issue. But there is a solution on Stack Overflow to this, see

The solution is to remove

lint {
        disable 'InvalidPackage'
    }

from the .pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle gradle file.

vbuberen commented 1 year ago

Had the same issue. But there is a solution on Stack Overflow to this, see

The solution is to remove

lint {
        disable 'InvalidPackage'
    }

from the .pub-cache/hosted/pub.dev/audioplayers_android-3.0.1/android/build.gradle gradle file.

This is not a solution, don't mislead other users. Updating Android Gradle Plugin to >= 4.2.0 in android folder of your project is a solution that wouldn't require updating all packages.

GeekyROB96 commented 1 year ago

FAILURE: Build failed with an exception.

What could be the possible issue?

yoer commented 12 months ago

So, what is the standard solution?