问题是,当我在 Flutter 中构建程序时,出现错误:
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
我拥有的版本:
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/
所有颤振验证都可以。
但这一切都不起作用...重建我的应用程序也无法正常工作。
这一切都是从我尝试向我的应用程序添加 Firebase 消息传递开始的。在 iOS 上一切正常。
当我跑步时也会出现同样的问题:
./gradlew build --refresh-dependencies
我收到错误:
> 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
我在 macOS 上工作时遇到了同样的问题。我想这个问题的原因是项目目录的位置 - 它位于与 iCloud 同步的目录中。当我尝试在另一个目录中构建完全相同的项目时,该项目没有与 iCloud 同步,这样的错误再也没有发生过。