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'

}

}

相关推荐
柒.梧.2 分钟前
JVM核心知识点部分总结(快速入门)
jvm
IT痴者3 分钟前
Kotlin 开发注意事项(Android Java 开发者转型指南)
android·java·kotlin
wuqingshun3141595 分钟前
产生死锁的四个必要条件
java·jvm
Kapaseker8 分钟前
你可能还不知道 Compose Pager 有多强大
android·kotlin
阿捏利9 分钟前
vscode+jadx-mcp-server配置及使用
android·apk·逆向·mcp·jadx
Predestination王瀞潞17 分钟前
3. JVM(Java Virtual Machine,Java 虚拟机):从核心架构到运行机制的全方位剖析
java·jvm·架构
程知农23 分钟前
Android的配置笔记
android·笔记
幸福在路上wellbeing28 分钟前
Android 程序员 常用的AI工具有哪些
android·人工智能
阿拉斯攀登29 分钟前
【RK3576 安卓 JNI/NDK 系列 03】JNI 核心语法(上):数据类型映射与方法调用
android·安卓ndk入门·jni方法签名·java调用c++·rk3576底层开发
XerCis36 分钟前
安卓手机搭建Samba服务器SMB
android·服务器·智能手机