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'

}

}

相关推荐
zilikew3 分钟前
Flutter框架跨平台鸿蒙开发——每日谚语APP的开发流程
flutter·华为·harmonyos·鸿蒙
Whisper_Sy4 分钟前
Flutter for OpenHarmony移动数据使用监管助手App实战 - 月报告实现
android·开发语言·javascript·网络·flutter·ecmascript
雨季6667 分钟前
Flutter for OpenHarmony 入门实践:从 Scaffold 到 Container 的三段式布局构建
开发语言·javascript·flutter
zilikew9 分钟前
Flutter框架跨平台鸿蒙开发——脑筋急转弯小游戏的开发流程
flutter·华为·harmonyos·鸿蒙
天才少年曾牛13 分钟前
Android 怎么写一个AIDL接口?
android
jiayong2317 分钟前
JVM垃圾回收算法与收集器面试题详解
jvm
冬奇Lab35 分钟前
【Kotlin系列14】编译器插件与注解处理器开发:在编译期操控Kotlin
android·开发语言·kotlin·状态模式
灰灰勇闯IT41 分钟前
【Flutter for OpenHarmony--Dart 入门日记】第4篇:集合类型详解——List 的增删改查与函数式操作
flutter·交互
时光慢煮42 分钟前
打造跨端浮动操作按钮:Flutter × OpenHarmony 实战
flutter·华为·开源·openharmony
ujainu44 分钟前
Flutter for OpenHarmonyOS 前置知识:Dart语言详解(下)
flutter·wpf·harmonyos