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'

}

}

相关推荐
消失的旧时光-194325 分钟前
从 Android 组件化到 Flutter 组件化
android·flutter·架构
廋到被风吹走1 小时前
【Java】【JVM】即时编译解析:C1/C2、分层编译、OSR与日志分析
java·开发语言·jvm
Android轮子哥1 小时前
Android 12 SplashScreen 一种另类的适配方案
android·github
kirk_wang1 小时前
Flutter三方库鸿蒙适配实战:让flutter_sms在HarmonyOS上跑起来
flutter·移动开发·跨平台·arkts·鸿蒙
粤M温同学1 小时前
Android OkHttp 下载限速方案实现
android·okhttp
网小鱼的学习笔记2 小时前
面试题1:==和equals的比较
java·jvm·面试
2501_915106323 小时前
Perfdog 成本变高之后,Windows 上还能怎么做 iOS APP 性能测试
android·ios·小程序·https·uni-app·iphone·webview
愤怒的代码3 小时前
从开发调试到生产上线:全维度 Android 内存监控与分析体系构建
android·java·kotlin
jzlhll1233 小时前
Android最简化发布模块到mavenCentral
android·mavencentral
2501_915106323 小时前
iOS 安装了证书,HTTPS 还是抓不到
android·网络协议·ios·小程序·https·uni-app·iphone