Android Gradle插件与Kotlin Gradle插件版本不兼容问题求助
解决Flutter项目中sign_in_with_apple插件引发的Kotlin Gradle版本不兼容问题
错误信息
FAILURE: Build failed with an exception. * What went wrong: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher. The following dependencies do not satisfy the required version: project ':sign_in_with_apple' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50 * 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 Exception: Gradle task assembleDebug failed with exit code 1
问题根源
你的Android Gradle插件要求Kotlin Gradle插件版本至少1.5.20,但sign_in_with_apple插件内部依赖的是1.3.50版本——即使你自己项目配置了高版本Kotlin,插件的依赖配置会强制引入旧版本,导致版本冲突引发构建失败。
解决方案
1. 强制统一Kotlin Gradle插件版本
在项目根目录的build.gradle文件中,添加版本强制策略,确保所有模块使用符合要求的Kotlin版本:
buildscript { ext.kotlin_version = '1.9.20' // 选择1.5.20及以上的稳定版本,这里以1.9.20为例 repositories { google() mavenCentral() } dependencies { classpath "com.android.tools.build:gradle:7.4.2" // 确保AGP版本与Kotlin版本兼容 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() mavenCentral() } // 添加这段配置强制统一Kotlin版本 configurations.all { resolutionStrategy { force "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } }
2. 升级sign_in_with_apple插件版本
打开pubspec.yaml,将插件升级到最新稳定版(新版本通常会适配更高版本的Kotlin):
dependencies: sign_in_with_apple: ^5.0.0 // 替换为当前最新稳定版本
执行flutter pub get更新依赖。
3. 清理缓存并重新构建
执行以下命令清理缓存,避免旧配置干扰:
flutter clean rm -rf android/.gradle rm -rf ~/.gradle/caches flutter pub get flutter run
内容的提问来源于stack exchange,提问作者Eben Oasis
相关产品推荐
相关产品推荐

