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

Flutter集成shared_preferences与device_info_plus时出现Daemon编译失败(增量缓存无法关闭)问题求助

Flutter集成shared_preferences与device_info_plus时出现Daemon编译失败(增量缓存无法关闭)问题求助

大家好,我是刚在VS Code上手Flutter的新手,最近在把一个Titanium应用迁移到Flutter的过程中,碰到了一个棘手的编译问题,想请各位大佬帮忙看看!

问题场景

我需要用到shared_preferences和device_info_plus两个Flutter包,结果一引入到项目里,编译时就触发了Kotlin相关的Daemon编译失败错误,两个包报的错误几乎一模一样。

错误详情

针对shared_preferences的错误核心片段:

Daemon compilation failed: null java.lang.Exception
...
Caused by: java.lang.AssertionError: java.lang.Exception: Could not close incremental caches in D:\Programming\Flutter\flutter_daemoncomp_test\build\shared_preferences_android\kotlin\compileReleaseKotlin\cacheable\caches-jvm\jvm\kotlin: class-fq-name-to-source.tab, source-to-classes.tab, internal-name-to-source.tab

针对device_info_plus的错误核心片段:

Daemon compilation failed: null java.lang.Exception
...
Caused by: java.lang.AssertionError: java.lang.Exception: Could not close incremental caches in D:\Programming\Flutter\flutter_daemoncomp_test\build\device_info_plus\kotlin\compileReleaseKotlin\cacheable\caches-jvm\jvm\kotlin: class-fq-name-to-source.tab, source-to-classes.tab, internal-name-to-source.tab

已尝试的解决方法

  • 核对过本地开发环境,确认符合两个包的官方推荐要求
  • 调整过项目中Kotlin的版本:一开始用的是2.1.0,后来换成2.2.0,错误完全没有变化
  • 执行过flutter clean清理项目缓存,重新编译后问题依旧

当前项目配置

我的项目根目录下的build.gradle中相关配置如下:

plugins {
    id("dev.flutter.flutter-plugin-loader") version "1.0.0"
    id("com.android.application") version "8.7.3" apply false
    id("org.jetbrains.kotlin.android") version "2.1.0" apply false
}

本地环境信息

执行flutter doctor -v的结果如下:

[√] Flutter (Channel stable, 3.32.8, on Microsoft Windows [Version 10.0.19045.6093], locale en-US)
    • Flutter version 3.32.8 on channel stable at D:\Programs\Android\FlutterSDK\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision edada7c56e (2 weeks ago), 2025-07-25 14:08:03 +0000
    • Engine revision ef0cd00091
    • Dart version 3.8.1
    • DevTools version 2.45.1

[√] Windows Version (10 Pro 64-bit, 22H2, 2009)

[√] Android toolchain - develop for Android devices (Android SDK version 36.0.0)
    • Android SDK at D:\Programs\Android\SDK
    • Platform android-36, build-tools 36.0.0
    • ANDROID_SDK_ROOT = D:\Programs\Android\SDK
    • Java binary at: D:\Programs\Java\jdk-17\bin\java
      This JDK is specified in your Flutter configuration. To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Temurin-17.0.16+8 (build 17.0.16+8)
    • 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.14.6 (June 2025))
    • Visual Studio at D:\Programs\Microsoft Visual Studio
    • Visual Studio Community 2022 version 17.14.36212.18
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2025.1.2)
    • Android Studio at D:\Programs\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
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)

[√] VS Code, 64-bit edition (version 1.103.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.116.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.6093]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 138.0.7204.184
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 139.0.3405.86

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

• No issues found!

有没有大佬碰到过类似的问题?或者能给我一些排查的方向?比如是不是Gradle缓存的问题?或者Kotlin与Android Gradle Plugin的版本兼容性问题?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.07 07:35:28