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

已更新Android build.gradle仍提示使用旧版Kotlin Gradle插件求助

解决Android Gradle插件与Kotlin版本冲突问题

核心原因

你项目中的location依赖模块硬编码了Kotlin Gradle插件版本1.4.20,低于Android Gradle插件要求的1.5.20+,且该依赖未继承你项目根配置的Kotlin版本,导致版本冲突。修改项目根目录的ext.kotlin_version无法覆盖依赖内部指定的旧版本,因此问题持续存在。

解决方案

方法1:强制所有模块使用统一Kotlin版本

在项目根目录的android/build.gradle中添加版本强制策略,确保所有依赖模块使用你指定的Kotlin版本:

buildscript {
    ext.kotlin_version = '1.7.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()
    }
    // 添加版本强制配置
    configurations.all {
        resolutionStrategy {
            force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
            force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
            force "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
}

方法2:升级location依赖到最新稳定版

检查你使用的location插件(如Flutter的location包)的最新版本,在pubspec.yaml中更新依赖:

dependencies:
  location: ^6.0.1 # 替换为当前最新稳定版本号

更新后执行flutter pub get同步依赖,再尝试构建。

方法3:手动修改依赖模块配置(临时方案)

若前两种方法无效,可直接修改本地缓存的location模块配置:

  1. 找到依赖缓存目录:~/.pub-cache/hosted/pub.dartlang.org/location-[版本号]/android/build.gradle
  2. 打开文件,将其中的kotlin-gradle-plugin版本改为1.7.20
  3. 同步项目后重新构建

验证步骤

  1. 执行flutter clean清除旧构建缓存
  2. 执行flutter pub get同步依赖
  3. 重新构建App Bundle:flutter build appbundle

内容的提问来源于stack exchange,提问作者fikri akhdi maulana

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 14:40:17