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'

}

}

相关推荐
1024+15 小时前
YOLO 转 RKNN 识别率降低调优操作手册(新手篇)
android·yolo·kotlin
木易 士心16 小时前
深度解析 Android 音频焦点处理与实战开发
android·音视频
祉猷并茂,雯华若锦17 小时前
Appium 3.x安卓APP企业级安装实战
android·appium
微露清风18 小时前
浅析 MySQL 索引
android·数据库·mysql
浮江雾18 小时前
Flutter第九节-----Align与Padding实战指南
linux·服务器·开发语言·flutter·入门
Java技术实战18 小时前
一文通解:数据结构之 栈
java·jvm·数据结构·
91刘仁德18 小时前
MySQL 数据类型详解
android·笔记·mysql·adb
编程圈子20 小时前
操作系统学习14 IDT + PIC + 键盘中断
android·学习·计算机外设
齊家治國平天下1 天前
Android 14 Vehicle HAL (VHAL) 设计与实现深度解析
android·aaos·carservice·车载开发·android 14·vhal·vehicle hal
西西学代码1 天前
Charge-BleDevice
flutter