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

Flutter升级后Gradle task assembleDebug失败(exit code 1)求助

解决Flutter升级后compileSdkVersion不兼容的构建失败问题

问题描述

升级Flutter后无法运行项目,尝试集成音频播放器插件失败,调整SDK版本后仍报错。当前核心代码如下:

import 'package:flutter/material.dart';

void main() => runApp(XylophoneApp());

class XylophoneApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Center(
            child:TextButton
              (onPressed: (){


              },
             child:Text('Click Me')),
          ),
        ),
      ),
    );
  }
}

运行时抛出以下错误:

Running "flutter pub get" in tessssssssssssssst...
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > One or more issues found when checking AAR metadata values:

     Dependency 'androidx.core:core:1.9.0-alpha05' requires 'compileSdkVersion' to be set to 32 or higher.
     Compilation target for module ':app' is 'android-31'

     Dependency 'androidx.core:core-ktx:1.9.0-alpha05' requires 'compileSdkVersion' to be set to 32 or higher.
     Compilation target for module ':app' is 'android-31'

* 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 54s
Exception: Gradle task assembleDebug failed with exit code 1

解决方案

1. 升级compileSdkVersion到32及以上

打开项目中android/app/build.gradle文件,找到android配置块,将compileSdkVersion修改为32或更高的稳定版本(推荐33),同时建议同步升级targetSdkVersion:

android {
    compileSdkVersion 33 // 替换为32或更高版本
    defaultConfig {
        targetSdkVersion 33 // 同步升级目标SDK版本
        // ...其他配置
    }
    // ...其他配置
}

2. 清理缓存并重新同步依赖

执行以下命令清理项目缓存并重新获取依赖:

flutter clean
flutter pub get

3. 检查音频播放器插件兼容性

如果音频播放器插件存在版本兼容问题:

  • 确认插件使用最新稳定版,适配当前Flutter版本及目标SDK版本
  • 在pubspec.yaml中锁定兼容版本,例如:
    dependencies:
      audioplayers: ^4.0.1 # 替换为插件最新稳定版
    

原因说明

升级Flutter后,项目依赖的AndroidX核心库(androidx.core:core、androidx.core:core-ktx)更新到了1.9.0-alpha05版本,该版本要求项目的compileSdkVersion至少为32,而你的项目当前编译目标是android-31,导致依赖校验失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 04:48:21