微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何解决flutter项目编译Debug Kotlin错误

如何解决如何解决flutter项目编译Debug Kotlin错误

我是 Flutter 开发的新手。我在一个项目中使用了 audioplayers: ^0.19.0 包,但是当该项目在模拟器上运行时,它会弹出大错误消息。你们能帮我解决这个问题吗?我不知道是我的代码错误还是程序包问题。

任务“:audioplayers:compileDebugKotlin”执行失败。

编译错误。详情见日志

import 'package:Flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
 

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Simple Music'),backgroundColor: Colors.Amber[300],),body: SafeArea(
          child: Center(
            child: TextButton(
              child: Text("music"),onpressed: () {
                final player = AudioCache();
                player.play("note2.wav");
              },);
  }
}

调试控制台

Launching lib\main.dart on AOSP on IA Emulator in debug mode...
e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-Metadata-version-check' to suppress errors
e: C:/Users/acer/.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/acer/.gradle/caches/transforms-2/files-2.1/4d4ccf1034ba5937e6e7ba3aa34d2661/jetified-core-ktx-1.6.0-beta02-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:/Users/acer/.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:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (18,32): Unresolved reference: mutableMapOf
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\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/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (26,expected version is 1.1.15.
The class is loaded from C:/Users/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\AudioplayersPlugin.kt: (27,expected version is 1.1.15.
The class is loaded from C:/Users/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\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/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class

e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (127,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/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (129,9): Unresolved reference: synchronized

e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (130,18): 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/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (131,59): Unresolved reference: mutablelistof

e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (136,expected version is 1.1.15.
The class is loaded from C:/Users/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (137,expected version is 1.1.15.

The class is loaded from C:/Users/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (143,expected version is 1.1.15.
The class is loaded from C:/Users/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class

e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (144,expected version is 1.1.15.
The class is loaded from C:/Users/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (154,14): 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/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (156,23): Unresolved reference: let
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (156,39): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its Metadata is 1.5.1,49): Unresolved reference: it
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (161,expected version is 1.1.15.

The class is loaded from C:/Users/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (163,23): Unresolved reference: let

e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (163,expected version is 1.1.15.
The class is loaded from C:/Users/acer/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (163,47): Unresolved reference: it


e: C:\Flutter\Flutter\Flutter_sdk\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.19.0\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (235,30): 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/acer/.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 1m 50s

Exception: Gradle task assembleDebug Failed with exit code 1
Exited (sigterm)

解决方法

尝试像这样更改 build.gradle 文件(位于项目的 android 文件夹中)中的 ext.kotlin_version 值:

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

    dependencies{
        ...
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。