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'

}

}

相关推荐
守月满空山雪照窗6 小时前
深入理解 MTK FPSGO:Android 游戏帧率治理框架的架构与实现
android·游戏·架构
2401_887724506 小时前
在 Ubuntu Core 上部署 Go Web 服务的完整实践指南
jvm·数据库·python
Polar__Star6 小时前
C#怎么实现Redis分布式缓存 C#如何在ASP.NET Core中集成Redis实现分布式缓存方案【架构】
jvm·数据库·python
阿凤216 小时前
uniapp运行到app端怎么打开文件
android·前端·javascript·uni-app
qq_206901396 小时前
如何在 WordPress 中通过邮箱获取用户 ID(PHP 实现)
jvm·数据库·python
俺不要写代码7 小时前
C++并发基本概念及实现、进程、基本概念
网络·jvm
学习使我健康7 小时前
Android 事件分发机制
android·java·前端
Polar__Star7 小时前
HTML函数在多GPU系统中如何调用_显卡切换机制说明【汇总】
jvm·数据库·python
贵沫末7 小时前
Claude Code For VS Code安装以及跳过认证
android
2301_813599557 小时前
mysql为什么不要在索引列上做运算_mysql函数索引使用场景
jvm·数据库·python