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

使用fluttertoast构建Flutter项目时依赖解析失败求助

Flutter项目使用fluttertoast 8.2.8构建失败的解决方案

问题详情

使用fluttertoast 8.2.8版本构建Flutter项目时出现以下错误,已尝试移除依赖重建、重新创建android文件夹、确认SDK版本等操作仍未解决:

Warning: SDK processing. This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':fluttertoast:compileReleaseJavaWithJavac'.
> Could not determine the dependencies of null.
   > Cannot query the value of this provider because it has no value available.

* 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 11m 30s

附flutter doctor输出:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [Versi¢n 10.0.22631.4317], locale es-419)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.3)
[√] Android Studio (version 2024.1)
[√] VS Code (version 1.94.2)
[√] Connected device (3 available)
[√] Network resources

• No issues found!
PS C:\UsoftDev\aromacos> flutter doctor -v
[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [Versi¢n 10.0.22631.4317], locale es-419)
    • Flutter version 3.24.3 on channel stable at C:\UsoftDev\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (4 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\AlfaNote4\AppData\Local\Android\Sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.3)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.11.35303.130
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • android-studio-dir = C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)

[√] VS Code (version 1.94.2)
    • VS Code at C:\Users\AlfaNote4\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.98.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Versi¢n 10.0.22631.4317]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 129.0.6668.100
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 129.0.2792.79

[√] Network resources
    • All expected network resources are available.

解决方案尝试

1. 同步Android Studio与SDK命令行工具版本

错误开头的警告提示Android Studio(2024.1)和SDK命令行工具版本不匹配,按以下步骤操作:

  • 打开Android Studio的SDK Manager(Tools > SDK Manager)
  • 切换到SDK Tools标签,勾选Show Package Details
  • 找到Android SDK Command-line Tools,选择与Android Studio 2024.1兼容的版本(推荐最新版)进行安装
  • 安装完成后重启Android Studio,再重新构建项目

2. 清理Gradle缓存与项目构建缓存

执行以下命令清理缓存:

flutter clean
flutter pub get

同时手动删除以下目录:

  • 项目根目录下的.gradle文件夹
  • 用户目录下的.gradle文件夹(Windows路径:C:\Users\<你的用户名>\.gradle)

3. 手动指定Android Gradle Plugin(AGP)与Gradle版本

Android Studio 2024.1对应AGP 8.7.x版本、Gradle 8.7版本,修改配置文件:

  1. 打开android/build.gradle,修改classpath:
buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:8.7.0'
        // ...其他依赖
    }
}
  1. 打开android/gradle/wrapper/gradle-wrapper.properties,修改distributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip

4. 修复或替换fluttertoast依赖

  • 执行命令修复pub缓存的依赖:
flutter pub cache repair
  • 若仍有问题,尝试降级fluttertoast版本到8.2.7,修改pubspec.yaml:
dependencies:
  fluttertoast: ^8.2.7

然后执行flutter pub get重新获取依赖

5. 检查本地SDK配置

确认Android SDK的环境变量配置正确,ANDROID_HOME或ANDROID_SDK_ROOT指向正确的SDK路径(即C:\Users\AlfaNote4\AppData\Local\Android\Sdk),同时确保platform-tools和build-tools目录在系统PATH中。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 11:44:59