Flutter编译运行android问题之JVM版本问题

错误1:

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':audioplayers_android:compileDebugKotlin'. > Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (21). Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation

* 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 1s

错误2:

FAILURE: Build failed with an exception.

* What went wrong:

Could not determine the dependencies of task ':audioplayers_android:compileDebugKotlin'.

> Unknown Kotlin JVM target: 21

* 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 1s

解决方案:

1.首先找到依赖项目的路径:

audioplayers: ^4.1.0 存放路径

On Windows:
复制代码
C:\Users\<Your-Username>\AppData\Local\Pub\Cache\hosted\pub.dev\audioplayers-4.1.0
On macOS/Linux:
复制代码
~/.pub-cache/hosted/pub.dev/audioplayers-4.1.0

实际我的路径是:~/.pub-cache/hosted/pub.flutter-io.cn/audioplayers-4.1.0

audioplayers-4.1.0对应的依赖:

查看pubspec.yaml中的:

修改同目录下audioplayers_android-3.0.2/android/build.gradle

添加:

android{

...

...

compileOptions {

sourceCompatibility = 21

targetCompatibility = 21

}

kotlinOptions {

jvmTarget = '21'

}

}

相关推荐
Jomurphys24 分钟前
Compose 封装 - 点击防抖
android
最贪吃的虎1 小时前
Java基础之泛型
java·运维·jvm·分布式·后端
pps-key2 小时前
ai交易算力研究
大数据·jvm·人工智能·机器学习
2501_946675642 小时前
Flutter与OpenHarmony打卡动画效果组件
运维·nginx·flutter
乾坤一气杀2 小时前
OkHttp3 内部工作原理时序图
android
一起搞IT吧4 小时前
相机拍照无响应问题分析一:【MEMORY_NOT_ENOUGH导致】持续快拍,一会儿无法拍照了
android·c++·数码相机·智能手机
没有bug.的程序员4 小时前
网关在高并发场景下的优化实践:从Reactor模型到GC调优的深度指南
java·jvm·高并发·gc调优·网关优化·reactor模型·netty调优
人邮异步社区5 小时前
C++之父的《C++程序设计语言》(第4版)重译出版!
java·jvm·c++
是店小二呀5 小时前
【MySQL】MySQL 从安装到理解
android·mysql·adb
we1less6 小时前
[audio] threadLoop_write 到 audio-hal 分析
android