skip to Main Content

I started with flutter last week and I got this problem with the audioplayer package. I am doing a Flutter Development Bootcamp with Dart at Udemy. I followed almost everything at the video, but I recived a huge error message that I can’t solve.

This is my code:

import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
void main() => runApp(XylophoneApp());

class XylophoneApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.lightBlue,
        body: SafeArea(
          child: Container(
            child: Center(
              child: TextButton(
                onPressed: (){
                  final player = AudioCache();
                  player.play('assets/note1');
                },
                child: Text(
                  'click me'
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

This is the error message that i get:
Running Gradle task ‘assembleDebug’…
e: Incompatible classes were found in dependencies. Remove them from the classpath or use ‘-Xskip-metadata-version-check’ to suppress errors
e: C:/Users/victo/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15… (The message is much more larger than this)

  • What went wrong:
    Execution failed for task ‘:audioplayers:compileDebugKotlin’.

Compilation error. See log for more details

  • 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 21s
Exception: Gradle task assembleDebug failed with exit code 1

I’ve seen this message The binary version of its metadata is 1.5.1, expected version is 1.1.15, but I dont know what to do with it or how I can solve it.

This is my pubspec.yaml:

name: xylophone
description: A new Flutter application.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  audioplayers: ^0.19.1
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


flutter:

  uses-material-design: true

  assets:
    - assets/

5

Answers


  1. You can look into error log Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15 but try to 1.3.50, i have app with audioplayer i am using this version if it doesn’t work use 1.1.15 or the suggested version after changing version uninstall app and run flutter clean and run again

    Try downgrade to a lower kotlin version in build.gradle

    buildscript {
        ext.kotlin_version = '1.3.50'
        repositories {
            google()
            jcenter()
        }
    
    }
    

    Also refer this answers also if doesn’t work in case

    Login or Signup to reply.
  2. In gradle files, go to build.gradle (Project: YourApp). Then, change the following code (in buildscript):

    from

    ext.kotlin_version = '1.3.50'
    

    to

    ext.kotlin_version = '1.4.32'
    

    or what ever the latest version of Kotlin available and make sure to update Kotlin version on Android Studio as well

    After following the instructions, your error will be resolved.

    Login or Signup to reply.
  3. Migration Guide

    dependencies:
    audioplayers: ^0.x.x

    to

    dependencies:
    audioplayers: ^1.0.1

    https://github.com/bluefireteam/audioplayers/blob/main/migration_guide.md

    try with this
    [1]: https://i.stack.imgur.com/jR5PG.png

    AudioCache is dead, long live Sources
    One of the main changes was my desire to "kill" the AudioCache API due to the vast confusion that it caused with users (despite our best efforts documenting everything).

    We still have the AudioCache class but its APIs are exclusively dedicated to transforming asset files into local files, cache them, and provide the path. It however doesn’t normally need be used by end users because the AudioPlayer itself is now capable of playing audio from any Source.

    What is a Source? It’s a sealed class that can be one of:

    UrlSource: get the audio from a remote URL from the Internet
    DeviceFileSource: access a file in the user’s device, probably selected by a file picker
    AssetSource: play an asset bundled with your app, normally within the assets directory
    BytesSource (only some platforms): pass in the bytes of your audio directly (read it from anywhere).
    If you use AssetSource, the AudioPlayer will use its instance of AudioCache (which defaults to the global cache if unchanged) automatically. This unifies all playing APIs under AudioPlayer and entirely removes the AudioCache detail for most users.

    Login or Signup to reply.
  4. If you are using the latest version of audioplayers in my case ^1.0.1 then your code should look like this instead

    onPressed: () async {
                    final player = AudioPlayer();
                    await player.play(AssetSource('note1.wav'));
                  },
    

    Wishing you all the best in your learning

    Login or Signup to reply.
  5. According to the latest stable releases, the AudioCache() was not dealing well instead you can try this

    ElevatedButton(
      onPressed: () {
        final player = AudioPlayer();
        player.play(AssetSource('s1.wav'));
      },
      child: const Text(
        'Click Me',
      ),
    ),
    

    Note : In player.play(AssetSource('s1.wav')) – in the place of s1.wav just give the filename instead giving the whole path like assets/s1.wav

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search