Flutter项目连接Firebase遇Kotlin Gradle插件1.7.1找不到错误求助
解决Flutter连接Firebase时的Kotlin Gradle插件版本找不到问题
错误信息:
Could not find org.jetbrain.kotlin:kotlin-gradle-plugin:1.7.1
核心问题分析
你的配置里存在两处关键问题:
- Kotlin依赖的组名拼写错误:正确组名是
org.jetbrains.kotlin(末尾多一个s),你写成了org.jetbrain.kotlin,导致Gradle无法定位到正确的依赖包。 - 仓库加载顺序可能影响依赖检索效率,优先加载Google仓库能提升兼容依赖的获取成功率。
修复步骤
1. 修正android目录下build.gradle的配置
调整仓库顺序并修复Kotlin依赖组名:
buildscript { ext.kotlin_version = '1.7.1' repositories { google() // 优先加载Google仓库 mavenCentral() } dependencies { classpath 'com.google.gms:google-services:4.4.1' // 修正组名,添加末尾的s classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } tasks.register("clean", Delete) { delete rootProject.buildDir }
2. 修正android/app目录下build.gradle的依赖
同步修正Kotlin标准库的组名:
plugins { id "com.android.application" id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" id 'com.google.gms.google-services' } def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } android { namespace "com.example.clinicconnect_test" compileSdk flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { applicationId "com.example.clinicconnect_test" minSdkVersion 21 targetSdkVersion 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies { implementation 'com.google.android.gms:play-services-maps:18.2.0' implementation(platform("com.google.firebase:firebase-bom:32.8.0")) implementation("com.google.firebase:firebase-analytics") // 修正组名 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }
3. 清理缓存并重新构建
执行以下命令清除旧配置缓存,避免残留问题:
flutter clean rm -rf android/.gradle flutter pub get flutter run
可选:更换兼容的Kotlin版本
如果1.7.1版本仍无法下载,可尝试使用与Flutter版本匹配的稳定版(如1.8.22适配Flutter 3.10+),只需修改ext.kotlin_version的值即可。
内容的提问来源于stack exchange,提问作者Naufal Nujaimin
相关产品推荐
相关产品推荐

