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

运行Flutter代码时遇Gradle依赖错误,请求解决

解决Flutter中Gradle依赖报错:Could not find method compile()...

错误核心原因

  1. compile 是Gradle旧版关键字,高版本(如你用的7.1.2)已废弃,需用implementation/api替代,但这不是主要问题;
  2. 关键错误:com.android.tools.build:gradle是Gradle构建插件,它不属于app模块的dependencies配置,必须放在项目级的build.gradle中。

修复步骤

  1. 修改app模块的build.gradle(你报错的C:\Users\TME_Education\StudioProjects\jeda\android\app\build.gradle):
    删除错误的compile行,保留正确依赖:

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        // 这里只放你的业务/Flutter相关依赖,比如Flutter嵌入库等
    }
    
  2. 修改项目级build.gradle(路径:C:\Users\TME_Education\StudioProjects\jeda\android\build.gradle):
    在buildscript的dependencies块中配置Gradle插件:

    buildscript {
        ext.kotlin_version = '1.6.10' // 版本需与Flutter兼容,可根据你的项目调整
        repositories {
            google()
            mavenCentral()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:7.1.2' // 把插件依赖放在这里
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
  3. 点击Android Studio的「Sync Project with Gradle Files」按钮同步配置,之后重新运行Flutter项目即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 18:45:38