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

如何解决Could not create task ':app:copyFlutterAssetsDebug'构建错误

解决Flutter构建错误:Could not create task ':app:copyFlutterAssetsDebug'

错误详情

执行flutter run时出现以下构建失败:

FAILURE: Build failed with an exception.

* Where:
Build file '/home/elkana/Dev/IdeaProjects/my_app/android/build.gradle' line: 13

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> Could not create task ':app:copyFlutterAssetsDebug'.
> For input string: "7-rc-4"

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 8s
Running Gradle task 'assembleDebug'... 9.7s
Error: Gradle task assembleDebug failed with exit code 1

环境信息

  • Flutter版本:3.19.4(stable通道)
  • Gradle版本:8.7-rc-4(候选发布版)
  • Android SDK版本:34.0.0
  • 项目android/app/build.gradle内容:
plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    namespace "com.example.my_app"
    compileSdk flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        applicationId "com.example.my_app"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {}

已尝试的无效操作

  • 切换到Flutter stable通道
  • 执行flutter pub upgrade
  • 执行flutter pub outdated(确认所有依赖为最新版本)

有效解决方案

问题根源

Gradle 8.7-rc-4是候选发布版,版本号中的-rc-4格式无法被Flutter Gradle插件正确解析,导致任务创建失败。

解决步骤

  1. 降级Gradle到正式稳定版
    打开项目根目录下的android/gradle/wrapper/gradle-wrapper.properties文件,修改distributionUrl为Flutter 3.19.4兼容的正式版Gradle(比如8.6):

    distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
    
  2. 清理构建缓存
    执行以下命令彻底清理缓存:

    flutter clean
    cd android && ./gradlew clean
    cd ..
    
  3. 重新构建项目
    再次执行flutter run即可正常构建。

内容的提问来源于stack exchange,提问作者elisoft-engineer

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 17:17:47