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

Android Gradle插件与Kotlin Gradle插件版本不兼容问题求助

解决Flutter构建失败:Kotlin Gradle插件版本不兼容问题

问题描述

构建Flutter应用时失败,报错信息:

失败:构建过程出现异常。

  • 问题原因:
    Android Gradle插件仅支持1.3.40及更高版本的Kotlin Gradle插件。
    以下依赖未满足版本要求:
    project ':google_map_location_picker' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31

项目环境配置:

version: 1.0.0+1

environment:
  sdk: ">=2.11.0 <3.0.0"
module:
  androidX: true
dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

Flutter SDK版本:Flutter Channel stable, 3.0.5

解决方案

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

你的项目根android/build.gradle已经指定了Kotlin版本为1.3.40,但依赖google_map_location_picker仍在使用旧版本。可以通过添加版本强制策略,让所有子模块遵循项目指定的Kotlin版本:

修改根android/build.gradle,在buildscript块之后添加以下内容:

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'org.jetbrains.kotlin') {
                details.useVersion "${kotlin_version}"
            }
        }
    }
}

修改后的完整根android/build.gradle示例:

buildscript {
    ext.kotlin_version = '1.3.40'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'org.jetbrains.kotlin') {
                details.useVersion "${kotlin_version}"
            }
        }
    }
}

方案2:更新google_map_location_picker依赖版本

如果方案1无效,检查你pubspec.yaml中google_map_location_picker的版本,更换为该包的最新稳定版本(需确保兼容Kotlin 1.3.40及以上),执行flutter pub get重新拉取依赖。

额外优化(可选)

你的android/app/build.gradle中testInstrumentationRunner使用了旧的support库,而项目已启用AndroidX,建议修改为:

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

完成上述修改后,执行flutter clean清除缓存,再重新构建项目即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 19:27:35