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

Flutter打包APK遇Kotlin Gradle插件版本不兼容问题求助

解决Flutter构建APK时Kotlin Gradle插件版本冲突问题

你的问题出在location插件内部硬编码了旧版Kotlin Gradle插件(1.4.20),它不会自动继承根项目定义的1.7.20版本,所以直接修改根项目的ext.kotlin_version无法覆盖这个硬编码配置。

解决方案

修改android/build.gradle文件,在subprojects块中添加依赖版本强制策略,让所有子模块统一使用你指定的Kotlin版本:

buildscript {
    ext.kotlin_version = '1.7.20'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.0'
        //noinspection DifferentKotlinGradleVersion
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')

    // 新增:强制所有子模块使用根项目定义的Kotlin版本
    configurations.all {
        resolutionStrategy.force "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.ext.kotlin_version}"
        resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.kotlin_version}"
        resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootProject.ext.kotlin_version}"
        resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${rootProject.ext.kotlin_version}"
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

后续操作

  1. 执行flutter clean清理项目缓存
  2. 执行flutter pub get重新同步依赖
  3. 再次尝试构建APK(flutter build apk)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 21:41:11