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'

}

}

相关推荐
alexhilton4 小时前
深入理解withContext和launch的真正区别
android·kotlin·android jetpack
消失的旧时光-19436 小时前
Flutter TextField 从入门到精通:掌握输入框的完整指南
flutter
TDengine (老段)7 小时前
TDengine 转换函数 TO_JSON 用户手册
android·大数据·数据库·json·时序数据库·tdengine·涛思数据
q***42827 小时前
SpringCloudGateWay
android·前端·后端
卫生纸不够用7 小时前
Appium-锁屏-Android
android·appium
阿拉斯攀登7 小时前
安卓工控机 OTA 升级方案(SpringBoot+MQTT)
android·spring boot·物联网·iot
顾林海8 小时前
从0到1搭建Android网络框架:别再让你的请求在"路上迷路"了
android·面试·架构
打工人你好8 小时前
如何设计更安全的 VIP 权限体系
java·jvm·安全
花花鱼8 小时前
android room中实体类变化以后如何迁移
android
wordbaby9 小时前
Flutter Form Builder 完全指南:告别 Controller 地狱
前端·flutter