💡

Flutter エラーで起動せず[expected version is 1.1.15]

2021/09/12に公開

状況

Flutterでaudioplayers 0.20.1のプラグインをインストールしてデバッグ実行しようとすると、エラーが出て起動しなかった。「 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」と表示される

改善策

android/build.gradle
+     ext.kotlin_version = '1.5.21'
-     ext.kotlin_version = '1.3.50'

audioplayersの前提となるKotolinのバージョンに比べて、Flutterのデフォルトで作成したプロジェクトのKotolinのバージョンが古いのかな。

エラー内容

audioplayers のプラグインをインストールして、実行しようとすると、以下のエラーが出た

Launching lib\main.dart on Android SDK built for x86 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/sakushin/.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/sakushin/.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:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.20.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (242, 26): 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/sakushin/.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.20.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (245, 52): Unresolved reference: takeIf
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.20.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (245, 61): Unresolved reference: it
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\audioplayers-0.20.1\android\src\main\kotlin\xyz\luan\audioplayers\WrappedSoundPool.kt: (246, 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/sakushin/.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 14s
Exception: Gradle task assembleDebug failed with exit code 1

参考

https://stackoverflow.com/questions/67832028/execution-failed-for-task-audioplayerscompiledebugkotlin

Discussion