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'

}

}

相关推荐
消失的旧时光-19434 小时前
从 Android 回调到 C 接口:函数指针 + void* self 的一次彻底理解
android·c语言·开发语言
dvlinker4 小时前
动态代理技术实战测评—高效解锁Zillow房价历史
android·java·数据库
喵手4 小时前
JVM 基础知识:深入理解 Java 的运行时环境!
java·jvm·jvm基础·java运行环境
峥嵘life4 小时前
Android16 EDLA 认证BTS测试Failed解决总结
android·java·linux·运维·学习
二流小码农4 小时前
鸿蒙开发:自定义一个圆形动画菜单
android·ios·harmonyos
wniuniu_4 小时前
object->osd
android·java·数据库
封妖九禁苍天泣4 小时前
Android WebView 使用本地字体-WebViewAssetLoader
android
00后程序员张5 小时前
fastlane 结合 appuploader 命令行实现跨平台上传发布 iOS App
android·ios·小程序·https·uni-app·iphone·webview
ujainu小5 小时前
Flutter 生物认证权威指南:local_auth 3.0.0 全平台集成与实战
flutter·local_auth