You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter旧项目编译报错:无法解析kotlin-gradle-plugin:1.8.0

解决无法解析org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0的问题

以下是针对该问题的具体修复步骤:

1. 匹配Gradle与Kotlin版本兼容性

Kotlin 1.8.0要求Gradle插件版本至少为7.3.0,检查并更新android/build.gradle中的Gradle插件版本:

buildscript {
    dependencies {
        // 替换为适配Kotlin 1.8.0的版本,例如7.4.2
        classpath 'com.android.tools.build:gradle:7.4.2'
    }
}

2. 替换为有效仓库源

旧项目可能依赖已废弃的jcenter(),需切换到Kotlin官方维护的mavenCentral(),修改android/build.gradle:

buildscript {
    repositories {
        google()
        mavenCentral() // 必须添加此仓库
        // 移除jcenter()(如果存在)
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        // 移除jcenter()
    }
}

3. 统一Kotlin版本配置

在android/build.gradle中集中管理Kotlin版本,避免版本冲突:

buildscript {
    ext.kotlin_version = '1.8.0' // 统一指定版本号
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

同时确保app/build.gradle中的Kotlin依赖版本与上述一致:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

4. 清理缓存并重新同步

  • 命令行执行清理:
    ./gradlew clean build --refresh-dependencies
    
  • 或在Android Studio中操作:File -> Invalidate Caches... -> 勾选"Invalidate and Restart"

内容的提问来源于stack exchange,提问作者Noor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 22:39:55