androidflutterdart

PathNotFoundException: Cannot open file .dart_tool/flutter_build/.../program.dill' (OS Error: No such file or directory, errno = 2)


the problem is that when I'm building my program in Flutter, I'm getting an error:

You are applying Flutter's app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/to/flutter-gradle-plugin-apply

Unhandled exception:
PathNotFoundException: Cannot open file, path = '/Users/.../.dart_tool/flutter_build/12ac92aa90402be39d79fb4ebb8222b4/program.dill' (OS Error: No such file or directory, errno = 2)
#0      _checkForErrorResponse (dart:io/common.dart:55)
#1      _File.open.<anonymous closure> (dart:io/file_impl.dart:381)
<asynchronous suspension>
#2      _FileStreamConsumer.addStream.<anonymous closure> (dart:io/file_impl.dart:205)
<asynchronous suspension>

Target kernel_snapshot_program failed: Exception


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/szymonkluzek/flutter/bin/flutter'' finished with non-zero exit value 1

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

Versions I have:

Flutter 3.24.5 • channel stable
Framework • revision dec2ee5c1f • 2024-11-13 11:13:06 -0800
Engine • revision a18df97ca5
Tools • Dart 3.5.4 • DevTools 2.37.3
Android SDK version 35.0.0
version 2024.2
compileSdkVersion 35
targetSdkVersion 35
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
classpath 'com.android.tools.build:gradle:8.1.1'
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment Homebrew (build 17.0.13+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.13+0, mixed mode, sharing)
ext.kotlin_version = '1.8.10'
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment Homebrew (build 17.0.13+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.13+0, mixed mode, sharing)
Dart SDK version: 3.5.4 (stable) (Wed Oct 16 16:18:51 2024 +0000) on "macos_arm64"
I tried by building program again as:

flutter clean
flutter pub get
flutter pub upgrade
flutter pub outdated
flutter upgrade --force
flutter pub cache repair

rm -rf .dart_tool

./gradlew --stop
./gradlew clean
./gradlew build --stacktrace
rm -rf ~/.gradle/caches/

all flutter validations are okay.

but it all doesn't work... Rebuilding my app also does not work properly.

It all started when I was trying to add Firebase messaging to my app. On iOS it all works.

The same issue starts when I'm running:

./gradlew build --refresh-dependencies

I'm getting an error:

> Task :app:compileFlutterBuildDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/szymonkluzek/flutter/bin/flutter'' finished with non-zero exit value 1

Solution

  • I had the same problem working on macOS. I suppose the reason of such problem was the location of the project's directory - it was located in the directory synced with iCloud. When I tried to build exactly the same project in another directory, that was not being synced with iCloud, such error have never ever occurred again.