【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

相关推荐
tangweiguo0305198717 分钟前
Android原生(Kotlin)与Flutter混合开发 - 设备控制与状态同步解决方案
android·flutter
江上清风山间明月16 小时前
Flutter AlwaysScrollableScrollPhysics详解
flutter·滚动·scrollable·scrollphysics
普罗米拉稀18 小时前
Flutter 复用艺术:Mixin 与 Abstract 的架构哲学与线性化解密
flutter·ios·面试
yangshuo12811 天前
AI编程工具对决:Kilo vs Augment 开发Flutter俄罗斯方块游戏实战对比
flutter·游戏·ai编程
tangweiguo030519871 天前
Flutter 自定义 Switch 切换组件完全指南
flutter
笔沫拾光1 天前
iOS 正式包签名指南
flutter·ios·ios签名
森之鸟2 天前
flutter项目适配鸿蒙
flutter·华为·harmonyos
傅里叶2 天前
Flutter在OrangePi 5 Plus上视频播放锁死问题
前端·flutter
书弋江山2 天前
flutter 跨平台编码库 protobuf 工具使用
android·flutter
程序员老刘·2 天前
Flutter 3.35 更新要点解析
flutter·ai编程·跨平台开发·客户端开发