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

Flutter构建APK失败:Android Gradle Plugin版本兼容问题

搞定Kotlin Gradle Plugin与Android Gradle Plugin版本兼容问题

1. 核心原因:版本不匹配

你用的Kotlin 2.1.0要求最低Android Gradle Plugin(AGP)版本为7.3.1,之前的7.2.2达不到要求,光更新Kotlin和Gradle版本没用,必须升级AGP。

2. 修改android/build.gradle文件

直接升级AGP版本,同时移除已废弃的jcenter仓库:

ext.kotlin_version = '2.1.0'
    repositories {
        google()
        mavenCentral()
        // jcenter已停止维护,移除避免依赖拉取问题
        // jcenter()
    }

    dependencies {
        // 将AGP版本升级到7.3.1,满足Kotlin 2.1.0的最低要求
        classpath 'com.android.tools.build:gradle:7.3.1'
        // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:perf-plugin:1.4.1'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        // END: FlutterFire Configuration
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        // 移除jcenter仓库
        // jcenter()
        maven { url "https://jitpack.io" }
    }
}

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

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

3. 确认Gradle版本兼容性

AGP 7.3.1对应的Gradle版本要求是7.4及以上,你当前使用的Gradle 7.6.3完全符合要求,因此gradle-wrapper.properties无需修改。

4. 清理缓存并重新构建

执行以下命令清理旧缓存,然后重新构建APK:

flutter clean
flutter pub get
flutter build apk

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 05:22:47