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'

}

}

相关推荐
修炼者20 小时前
【进阶Android】HashMap 的并发“车祸”
android
西西学代码1 天前
Flutter---回调函数
开发语言·javascript·flutter
冬奇Lab1 天前
Android 15音频子系统(六):音频焦点管理机制深度解析
android·音视频开发·源码阅读
庞轩px1 天前
模拟面试回答第十三问:JVM内存模型
jvm·面试·职场和发展
圣光SG1 天前
Vue.js 从入门到精通:技术成长之路
flutter
森林里的程序猿猿1 天前
并发设计模式
java·开发语言·jvm
u0136863821 天前
将Python Web应用部署到服务器(Docker + Nginx)
jvm·数据库·python
LionelRay1 天前
Thinking in Compose
android
njidf1 天前
实战:用Python开发一个简单的区块链
jvm·数据库·python
woai33641 天前
学习JVM-基础篇-类加载器&双亲委派机制
jvm