Gradle build failed: Execution failed for task ':audioplayers:compileDebugKotlin'

793

After doing a bit of research, I came across an answer on Github. So to fix this issue you need to change ext.kotlin_version in build.gradle. To change that you need to right click on android folder from your project tree > click on Flutter > click on Open Android module in Android Studio > now you can open it in the same window or in a new one > click on Gradle Scripts from project tree> open build.gradle (the first file) > finally change the ext.kotlin_version parameter to the latest version in my case 1.5.30 and sync gradle project and you will be good to go.

Step 1

Step 2

Share:
793
Ninad Nautiyal
Author by

Ninad Nautiyal

Updated on December 31, 2022

Comments

  • Ninad Nautiyal
    Ninad Nautiyal over 1 year

    I was trying to build a simple xylophone app and needed to add an audio player for it. So I downloaded the best rated dart package to play local audio files: audioplayers. After adding it to pubsec.yaml and installing it when I stopped and rebuild my app it crashed and I think it has something to do with Kotlin and audioplayers version being incompatibe.

    Here's the main.dart:

    import 'package:flutter/material.dart';
    import 'package:audioplayers/audioplayers.dart';
    
    void main() {
      runApp(Xylophone());
    }
    
    class Xylophone extends StatefulWidget {
      const Xylophone({Key? key}) : super(key: key);
    
      @override
      _XylophoneState createState() => _XylophoneState();
    }
    
    class _XylophoneState extends State<Xylophone> {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            body: SafeArea(
              child: Center(
                child: TextButton(
                  onPressed: () {
                    final player = AudioPlayer();
                    player.play('note1');
                  },
                  child: Text('tap me'),
                ),
              ),
            ),
          ),
        );
      }
    }
    

    Pubsec.yaml:

    name: xylophone
    description: A new Flutter project.
    
    publish_to: 'none'
    
    version: 1.0.0+1
    
    environment:
      sdk: ">=2.12.0 <3.0.0"
    
    dependencies:
      flutter:
        sdk: flutter
    
      cupertino_icons: ^1.0.2
      audioplayers: ^0.19.1
    
    
    dev_dependencies:
      flutter_test:
        sdk: flutter
    
    flutter:
    
      uses-material-design: true
    
    assets:
      - assets/
    

    And this is the error:

    Launching lib\main.dart on SM T580 in debug mode...
    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/Ninad/.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.
    e: C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/77bab1911042ab2c6d5cc0b2e2ee053c/jetified-kotlin-stdlib-common-1.5.10.jar!/META-INF/kotlin-stdlib-common.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.
    e: C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/bd92f9b27f3f577322c07e31476e006e/jetified-core-ktx-1.6.0-api.jar!/META-INF/core-ktx_release.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.
    e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (18, 32): Unresolved reference: mutableMapOf
    e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (25, 9): Class 'kotlin.Unit' 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 class is loaded from C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
    e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (26, 9): Class 'kotlin.Unit' 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 class is loaded from C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
    e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (27, 9): Class 'kotlin.Unit' 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 class is loaded from C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
    e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (28, 17): Class 'kotlin.Unit' 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 class is loaded from C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
    e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (34, 13): Class 'kotlin.Unit' 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 class is loaded from C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
    e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (36, 20): Class 'kotlin.Unit' 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 class is loaded from C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
    e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.1\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (37, 22): Class 'kotlin.Unit' 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 class is loaded from C:/Users/Ninad/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
    
    FAILURE: Build failed with an exception.
    
    * 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 22s
    Exception: Gradle task assembleDebug failed with exit code 1
    

    Please provide detailed answers and helpful solutions.