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'

}

}

相关推荐
YIN_尹39 分钟前
【MySQL】数据类型(上)
android·mysql·adb
奋斗的小青年!!41 分钟前
OpenHarmony Flutter 拖拽排序组件性能优化与跨平台适配指南
flutter·harmonyos·鸿蒙
leaves falling2 小时前
一篇文章深入理解指针
jvm
小雨下雨的雨2 小时前
Flutter 框架跨平台鸿蒙开发 —— Stack 控件之三维层叠艺术
flutter·华为·harmonyos
robotx2 小时前
AOSP设备节点权限添加相关
android
顾林海2 小时前
Android文件系统安全与权限控制:给应用数据上把“安全锁”
android·面试·操作系统
linweidong2 小时前
C++ 中避免悬挂引用的企业策略有哪些?
java·jvm·c++
青莲8432 小时前
Android 动画机制完整详解
android·前端·面试
城东米粉儿2 小时前
android 离屏预渲染 笔记
android
未知名Android用户2 小时前
Android自定义 View + Canvas—声纹小球动画
android