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'

}

}

相关推荐
GitLqr14 小时前
深度拆解 Dart 事件循环:从面试题看清 Microtask 与 Event Queue 的执行顺序
flutter·面试·dart
爱笑鱼14 小时前
Binder(八):远端进程死了,BinderProxy 为什么还能收到通知?
android
Android-Flutter14 小时前
Kotlin 冷流与热流详解
android·kotlin
zhangphil14 小时前
Android ContentProvider/ContentResolver读图片,跨进程 IPC慢
android
yueqc115 小时前
Android .so 文件压缩
android·so·包体积
龚礼鹏15 小时前
深入解析 Android Automotive (AAOS) 启动流程与 CarService 核心机制(基于 Android 16 最新源码视角)
android
rosmis15 小时前
agent各指标定义
android·java·开发语言
风样滴男人哟17 小时前
PHP特性之反射类ReflectionClass机制
android·开发语言·php
看昭奚恤哭17 小时前
Flutter 布局核心思想
开发语言·javascript·flutter
末代iOS程序员华仔17 小时前
iOS上架海外工具类应用合规指南:避免封号与下架风险
flutter·ios·swift