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

Flutter集成geolocator插件提示需更新Kotlin Gradle插件

解决Flutter集成geolocator 12.0.0时的Kotlin Gradle插件版本问题

核心问题分析

你遇到的问题本质是Kotlin Gradle插件版本与Android Gradle Plugin(AGP)版本不兼容:你设置了Kotlin 2.0.0,但当前使用的AGP 7.4.2并不支持这么高的Kotlin版本,反而会导致编译失败。

分步解决方案

1. 匹配兼容的Kotlin与AGP版本

修改android/build.gradle中的Kotlin版本为AGP 7.4.2支持的最高稳定版本(1.7.20),确保版本对应:

buildscript {
    ext.kotlin_version = '1.7.20' // 与AGP 7.4.2兼容的稳定版本

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

2. 检查app模块配置

打开android/app/build.gradle,确认以下两点:

  • 顶部已添加Kotlin插件引用:
    apply plugin: 'kotlin-android'
    
  • 没有单独指定与根build.gradle冲突的Kotlin版本

3. 清除缓存并重新构建

执行以下命令彻底清除缓存,避免旧版本残留:

flutter clean
rm -rf android/.gradle
flutter pub get
flutter build apk --release

4. 升级AGP(可选)

如果确实需要使用更高版本的Kotlin(比如1.8+),需同步升级AGP版本:

  • 将AGP版本改为8.0.2(支持Kotlin 1.8.x),同时Kotlin版本设为1.8.22
  • 修改android/gradle/wrapper/gradle-wrapper.properties中的Gradle版本,适配AGP 8.x:
    distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 12:12:17