【flutter运行时项目中第三方库与系统环境中jdk版本冲突问题】

报错信息信息示例:

复制代码
A problem occurred configuring project ':geolocator_android'.
> Could not resolve all artifacts for configuration ':geolocator_android:classpath'.
> Could not resolve com.android.tools.build:gradle:7.4.2.
Required by:
project :geolocator_android
> No matching variant of com.android.tools.build:gradle:7.4.2 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally but:
- Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
- Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
- Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
> Failed to notify project evaluation listener.
> Could not get unknown property 'android' for project ':geolocator_android' of type org.gradle.api.Project.
> Could not get unknown property 'android' for project ':geolocator_android' of type org.gradle.api.Project.

通过翻译得知是因为使用与项目Java版本不兼容的Gradle插件时。com.android.tools.build:gradle:7.4.2 需要Java 11来运行,项目或环境被配置为使用Java 8。

解决方案:

1.要确保你的gradle-wrapper.properties文件中的Gradle版本与你的Android Gradle插件版本兼容。

2.升级Java版本或降级Gradle插件版本(最好是能够升级jdk版本)

2-1.升级jdk。安装好jdk11后配置好系统环境变量,把Android studio的jdk路径改为jdk11的路径。(目前最新版本的Android studio koala似乎不能修改jdk路径了,博主安装后没找到在哪里设置)

3.修改好jdk后重启Android studio

相关推荐
时光慢煮11 分钟前
从零构建跨端图书馆管理页面:Flutter × OpenHarmony 实战指南-架构搭建
flutter·开源·openharmony
向前V18 分钟前
Flutter for OpenHarmony数独游戏App实战:单元格交互与选中
flutter·游戏·交互
小白阿龙25 分钟前
鸿蒙+flutter 跨平台开发——简易井字棋小游戏实现
flutter·华为·harmonyos·鸿蒙
夜雨声烦丿28 分钟前
Flutter 框架跨平台鸿蒙开发 - 打造随机抽奖/点名器应用
flutter·华为·harmonyos
时光慢煮1 小时前
Flutter 编译开发 OpenHarmony 全流程实战教程-基于开源仓库GitCode 搜索工具 v1.0.3 的跨平台实践
flutter·开源·gitcode
小白阿龙1 小时前
鸿蒙+flutter 跨平台开发——Placeholder 控件的基础使用场景
flutter·华为·harmonyos·鸿蒙
时光慢煮1 小时前
基于 Flutter × OpenHarmony 图书馆管理系统之构建书籍管理模块
flutter·华为·开源·openharmony
IT陈图图1 小时前
智慧图书馆的数字名片:基于 Flutter × OpenHarmony 的读者卡片构建实践
flutter·鸿蒙·openharmony
南村群童欺我老无力.1 小时前
Flutter 框架跨平台鸿蒙开发 - 打造专业级单位换算器,支持8大类50+单位互转
flutter·华为·harmonyos
南村群童欺我老无力.1 小时前
Flutter 框架跨平台鸿蒙开发 - 井字棋游戏开发指南(含Minimax AI)
人工智能·flutter·华为·harmonyos