[Flutter] Module was compiled with an incompatible version of Kotlin. The binary version of its meta


问题描述:

Android Studio在更新完gradle后,发现demo项目运行出错了。

报错有一大串(很多文件),一直在重复说着要我提高gradle版本。

看下报错信息:


The class is loaded from C:/Users/samsung/.gradle/caches/transforms-3/7ad36a5b116dac2d2ae0e1e5f4e80713/transformed/jetified-kotlin-stdlib-1.5.31.jar!/kotlin/Unit.class
e: D:\Flutter\flutter\.pub-cache\hosted\pub.flutter-io.cn\wakelock-0.6.1+1\android\src\main\kotlin\creativemaybeno\wakelock\WakelockPlugin.kt: (30, 15): 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

.....
.....
.....

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':wakelock: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 20s
[!] Your project requires a newer version of the Kotlin Gradle plugin.
    Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update D:\Flutter\Code\flutter_demo\android\build.gradle:
    ext.kotlin_version = ''
Exception: Gradle task assembleDebug failed with exit code 1
  

其中,从这三句可以看到原因和解决方法:

The class is loaded from C:/Users/samsung/.gradle/caches/transforms-3/7ad36a5b116dac2d2ae0e1e5f4e80713/transformed/jetified-kotlin-stdlib-1.5.31.jar!/kotlin/Unit.class 
The binary version of its metadata is 1.5.1, expected version is 1.1.15.
[!] Your project requires a newer version of the Kotlin Gradle plugin.
update D:\Flutter\Code\flutter_demo\android\build.gradle:

解决方法:

找到项目下的\android\build.gradle文件

修改Kotlin_version为报错信息中最高的版本,即1.5.31

ext.kotlin_version = '1.5.31'

完毕!

相关