Flutter获取SHA-1时出现Kotlin Gradle插件版本兼容报错
解决Flutter中location依赖导致的Kotlin Gradle插件版本冲突问题
问题描述
获取SHA-1密钥时出现版本冲突错误:
Android Gradle插件仅支持1.5.20及更高版本的Kotlin Gradle插件。以下依赖未满足版本要求:
project ':location' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20
项目根目录build.gradle已配置最新Kotlin插件:
dependencies { classpath 'com.android.tools.build:gradle:7.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10" classpath 'com.google.gms:google-services:4.3.14' }
解决办法
强制统一Kotlin版本
在项目根目录build.gradle中添加版本强制策略,让所有模块使用指定的Kotlin版本,覆盖依赖库自带的旧版本:buildscript { ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.3.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.14' } } allprojects { repositories { google() mavenCentral() } configurations.all { resolutionStrategy.force "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" } }更新location插件版本
打开pubspec.yaml,将location依赖替换为最新稳定版,执行flutter pub get同步依赖:dependencies: flutter: sdk: flutter location: ^6.0.0 # 替换为当前最新兼容版本清理缓存重新构建
执行以下命令清除缓存,避免旧配置残留:flutter clean cd android && ./gradlew cleanBuildCache cd .. && flutter pub get
内容的提问来源于stack exchange,提问作者Krishnapal Sendhav
相关产品推荐
相关产品推荐

