【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

相关推荐
0wioiw011 小时前
Flutter基础(前端教程③-跳转)
前端·flutter
Lefan13 小时前
一文了解什么是Dart
前端·flutter·dart
0wioiw014 小时前
Flutter基础(前端教程④-组件拼接)
前端·flutter
木叶丸14 小时前
Flutter 生命周期完全指南
android·flutter·ios
用户74279877375915 小时前
[flutter翻书效果] 用flutter实现一个书籍翻页效果
flutter
技术蔡蔡21 小时前
Flutter和Firebae简单的聊天应用
flutter·全栈·firebase
小蜜蜂嗡嗡2 天前
flutter封装vlcplayer的控制器
前端·javascript·flutter
你听得到112 天前
从需求到封装:手把手带你打造一个高复用、可定制的Flutter日期选择器
前端·flutter
哲科软件2 天前
跨平台开发的抉择:Flutter vs 原生安卓(Kotlin)的优劣对比与选型建议
android·flutter·kotlin
天涯海风2 天前
Kuikly 与 Flutter 的全面对比分析,结合技术架构、性能、开发体验等核心维度
flutter·kuikly