GreenCodeSki
GreenCodeSki

Reputation: 909

Invalid depfile: Flutter

I am following a tutorial from a udemy course and recently I built a new pc so the hard drive that stored my code is secondary right now. When I compile the code, it gives me the following error. To explain it better, I am posting a picture of one warning in my code but I am pretty sure it is an error flutter is making as it usually does with imports. Error in Code I have tried running a test app by making a default app from cmd and that works fine. So obviously, flutter doctor shows no error. the error is repetitive and long so I am pasting some of it below.

The error-

Invalid depfile: D:\WorkSpace\Code\Flutter\Image App\image_app\.dart_tool\flutter_build\8f0d0eee9ef614ed024ca7691a333af8\kernel_snapshot.d
Invalid depfile: D:\WorkSpace\Code\Flutter\Image App\image_app\.dart_tool\flutter_build\8f0d0eee9ef614ed024ca7691a333af8\kernel_snapshot.d

Compiler message:
Error: Could not resolve the package 'http' in 'package:http/http.dart'.
lib/src/app.dart:5:8: Error: Expected ';' after this.
import 'widgets/image_list.dart;'
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/src/app.dart:2:8: Error: Not found: 'package:http/http.dart'
import 'package:http/http.dart' show get; //Only need get so we only care about one Get fuction
       ^
lib/src/app.dart:5:8: Error: Error when reading 'lib/src/widgets/image_list.dart;': The system cannot find the file specified.

import 'widgets/image_list.dart;'
       ^
/C:/src/flutter/packages/flutter/lib/src/material/bottom_navigation_bar.dart:9:8: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

import 'package:vector_math/vector_math_64.dart' show Vector3;
       ^
/C:/src/flutter/packages/flutter/lib/widgets.dart:15:1: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

export 'package:vector_math/vector_math_64.dart' show Matrix4;
^
/C:/src/flutter/packages/flutter/lib/rendering.dart:31:1: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

export 'package:vector_math/vector_math_64.dart' show Matrix4;
^
/C:/src/flutter/packages/flutter/lib/src/widgets/implicit_animations.dart:8:8: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

import 'package:vector_math/vector_math_64.dart';
       ^
/C:/src/flutter/packages/flutter/lib/src/widgets/transitions.dart:8:8: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

import 'package:vector_math/vector_math_64.dart' show Matrix4;
       ^
/C:/src/flutter/packages/flutter/lib/src/widgets/widget_inspector.dart:27:8: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/vector_math-2.0.8/lib/vector_math_64.dart': The system cannot find the path specified.

import 'package:vector_math/vector_math_64.dart';
       ^
/C:/src/flutter/packages/flutter/lib/foundation.dart:12:1: Error: Error when reading '/C:/Users/dluck/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/meta-1.1.8/lib/meta.dart': The system cannot find the path specified.

C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:90:4: Error: Getter not found: 'mustCallSuper'.
  @mustCallSuper
   ^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:90:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @mustCallSuper
   ^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:104:4: Error: Getter not found: 'mustCallSuper'.
  @mustCallSuper
   ^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:104:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @mustCallSuper
   ^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:118:4: Error: Getter not found: 'protected'.
  @protected
   ^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:118:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @protected
   ^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:119:4: Error: Getter not found: 'mustCallSuper'.
  @mustCallSuper
   ^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:119:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @mustCallSuper
   ^
/C:/src/flutter/packages/flutter/lib/src/foundation/node.dart:139:4: Error: Getter not found: 'protected'.
  @protected
   ^^^^^^^^^

C:/src/flutter/packages/flutter/lib/src/semantics/semantics.dart:3970:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @required TextDirection thisTextDirection,
   ^
/C:/src/flutter/packages/flutter/lib/src/semantics/semantics.dart:3971:4: Error: Getter not found: 'required'.
  @required TextDirection otherTextDirection,
   ^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/semantics/semantics.dart:3971:4: Error: This can't be used as metadata; metadata should be a reference to a compile-time constant variable, or a call to a constant constructor.
  @required TextDirection otherTextDirection,
   ^
U
nhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:
package%3Ahttp%2Fhttp.dart; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFi
leSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1      asFileU
ri (package:vm/kernel_front_end.dart:604:37)
#
2      writeDepfile (package:vm/kernel_front
_end.dart:799:21)
<asynchronous suspension>
#
3      FrontendCompiler.compile (package:fron
tend_server/frontend_server.dart:472:15)
<asynchronous 
suspension>
#4      _FlutterFrontendCompiler.comp
ile (package:flutter_frontend_server/server.dar
t:38:22)
#5      starter (package:flutter_fronte
nd_server/server.dart:149:27)
#6      main (f
ile:///C:/b/s/w/ir/cache/builder/src/flutter/fl
utter_frontend_server/bin/starter.dart:8:30)
#7    
  _startIsolate.<anonymous closure> (dart:isol
ate-patch/isolate_patch.dart:305:32)
#8      _RawRec
eivePortImpl._handleMessage (dart:isolate-patch
/isolate_patch.dart:174:12)

Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.

FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 780

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' 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 6s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

Upvotes: 71

Views: 151059

Answers (28)

ElsayedDev
ElsayedDev

Reputation: 650

search for any imports not need for the file. In my secnrio it was

import 'dart:nativewrappers/_internal/vm/lib/ffi_allocation_patch.dart';

Upvotes: 2

Bishop Possible
Bishop Possible

Reputation: 51

In my case i updated my flutter version and had to update my intl v0.19. here are the steps i took to solve my issue. I wasnt interested in using flutter Localization so i deleted the l10n.ymal.

Had to remove this line from my pubspec.ymal

After thus run: flutter clean && flutter pub get

Hope this helps.

Upvotes: 0

Shourya Sonu
Shourya Sonu

Reputation: 81

One of the simplest way :

flutter clean

flutter pub get

flutter run

that's it

Upvotes: 1

Nuel Emmanuel
Nuel Emmanuel

Reputation: 1

check your code properly, dart may have automatically imported some packages that are not necessary. check your imports very well, remove all imports not that are from you. In my case this was the import that was causing the error

"import 'dart:nativewrappers/_internal/vm/lib/ffi_allocation_patch.dart';"

I removed it and my code started working again.

Upvotes: 0

A225N
A225N

Reputation: 21

This happened to me, try to delete unused imports in your project!

Upvotes: 2

Maxim
Maxim

Reputation: 476

Fixing problems in "Dart Analysis" tab solved the problem enter image description here

Upvotes: 1

whodoom
whodoom

Reputation: 1

I add this code it will run

import 'package:flutter/material.dart' show BuildContext, Colors, Column, Expanded, Key, MainAxisAlignment, MaterialApp, Row, Scaffold, Size, SizedBox, StatelessWidget, Text, TextButton, Widget, runApp;

Upvotes: -2

diaa serag
diaa serag

Reputation: 61

While you are writing the code, this library is import by itself. ( import 'dart:html';)This causes some problems. You can delete it from the code

Upvotes: 6

Ishmael Mavor Raines
Ishmael Mavor Raines

Reputation: 330

Before running 'flutter pub get'

Go to the dependencies folder e.g. or whichever your app is pointing to ...

C:\Users\Administrator\AppData\Local\Pub\Cache\hosted\pub.dev

Look for the dependency that is misbehaving and just delete it.

Then run 'flutter pub get' to re-download it

flutter pub get

Upvotes: 0

Davik4life
Davik4life

Reputation: 11

It's easy. The way around it is to look on the home page or the main page, comment out or delete the 'import dart.html' and save, and then run flutter run. You should be good to go.

Upvotes: 0

Sh_Touqeer
Sh_Touqeer

Reputation: 101

I face similar problem I solved it by deleting import 'dart:html'; from top of the dart file. i.e remove import 'dart:html';

Upvotes: 10

user19168684
user19168684

Reputation: 79

I have the same bug and I deactivated vs code. When I reactivated it, I just typed

flutter clean

flutter pub get 

flutter run

And everything started to work.

Upvotes: 7

Ramasie
Ramasie

Reputation: 21

Someone has a solution to delete kernel_snapshot.d and kernel_snapshot.stamp

Well, I did but error not gone. What i did else is to check other errors and other errors was coming from Stripe Package. So i commented like this #flutter_stripe ^2.1.1 on pubspec.yaml and also, do Pub get: Note : Any error you see after commented or removed sdk package on pubs make sure you remove those errors else, after that, clean build folder on xcode and run pod install. The error gone. For you and anyone else, check other errors below the red or yellow highlight on Xcode. You may see other error which may not shown on Buldtime Nav. also make sure you use the latest Xcode Version.

Upvotes: 0

Randika Vishman
Randika Vishman

Reputation: 8124

Like many of you have suggested, I tried out almost all the things mentioned here and several other StackOverflow posts. But nothing worked for me.

The build error I got:

Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...
Xcode build done.                                           17.6s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    Invalid depfile: /Users/MY_APP_NAME/PACKAGE_NAME/app/.dart_tool/flutter_build/9a159911376355ed7b90130da2eaf0aa/kernel_snapshot.d
    Invalid depfile: /Users/MY_APP_NAME/PACKAGE_NAME/app/.dart_tool/flutter_build/9a159911376355ed7b90130da2eaf0aa/kernel_snapshot.d
    Invalid depfile: /Users/MY_APP_NAME/PACKAGE_NAME/app/.dart_tool/flutter_build/9a159911376355ed7b90130da2eaf0aa/kernel_snapshot.d
    Invalid depfile: /Users/MY_APP_NAME/PACKAGE_NAME/app/.dart_tool/flutter_build/9a159911376355ed7b90130da2eaf0aa/kernel_snapshot.d
    Error: Couldn't resolve the package 'shared_preferences' in 'package:shared_preferences/shared_preferences.dart'.
    ../lib/ui/home/home_screen.dart:29:8: Error: Not found: 'package:shared_preferences/shared_preferences.dart'
    import 'package:shared_preferences/shared_preferences.dart';
           ^
    ../lib/ui/home/home_screen.dart:871:37: Error: The getter 'SharedPreferences' isn't defined for the class '_HomeScreenState'.
     - '_HomeScreenState' is from 'package:PACKAGE_NAME/ui/home/home_screen.dart' ('../lib/ui/home/home_screen.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'SharedPreferences'.
        final sharedPreferences = await SharedPreferences.getInstance();
                                        ^^^^^^^^^^^^^^^^^
    ../lib/ui/home/home_screen.dart:893:37: Error: The getter 'SharedPreferences' isn't defined for the class '_HomeScreenState'.
     - '_HomeScreenState' is from 'package:PACKAGE_NAME/ui/home/home_screen.dart' ('../lib/ui/home/home_screen.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'SharedPreferences'.
        final sharedPreferences = await SharedPreferences.getInstance();
                                        ^^^^^^^^^^^^^^^^^
    Unhandled exception:
    FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Ashared_preferences%2Fshared_preferences.dart; message=StandardFileSystem only supports file:* and data:* URIs)
    #0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)
    #1      asFileUri (package:vm/kernel_front_end.dart:614:37)
    #2      writeDepfile (package:vm/kernel_front_end.dart:754:21)
    <asynchronous suspension>
    #3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:570:9)
    <asynchronous suspension>
    #4      starter (package:flutter_frontend_server/server.dart:85:12)
    <asynchronous suspension>
    #5      main (file:///opt/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:13:24)
    <asynchronous suspension>
    Failed to package /Users/MY_APP_NAME/PACKAGE_NAME/app.
    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Analyzing workspace
    note: Constructing build description
    note: Build preparation complete
    /Users/MY_APP_NAME/PACKAGE_NAME/app/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.5.99. (in target 'AppAuth' from project 'Pods')
    /Users/MY_APP_NAME/PACKAGE_NAME/app/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.5.99. (in target 'GoogleSignIn' from project 'Pods')

Could not build the application for the simulator.
Error launching application on iPhone 12 Pro Max.

One of the solutions that looked promising was deleting two files; kernel_snapshot.d and kernel_snapshot.stamp however that also didn't work for me. But I went to the path where these two files were residing. You can have a look into the folders and files structure in the following screenshot:

The folders and files I deleted

So what I did is actually delete those files that have been selected in the following screenshot and then try running the app as usual on the simulator. And it worked.

Upvotes: 4

Jasbin Karki
Jasbin Karki

Reputation: 614

well, you can do two steps to fix this issue

1. flutter clean
2. flutter pub get

after running these commands it should fix your issue

Upvotes: 6

Akshay Bhimani
Akshay Bhimani

Reputation: 1874

Check for any import which is related to browser or http and if your target platform is mobile then you might not need browser import and you can remove it.

In my case, I have removed this.

import 'package:dart_web3/browser.dart';

Upvotes: 0

Mc Ride
Mc Ride

Reputation: 7

Take a closer look if you have added such an import?

    import 'package:firebase/firebase.dart';

If so, this is for the web. If you are writing a mobile application, then it is better to use such an import :

    import 'package:firebase_auth/firebase_auth.dart';

This could be a potential error.

Upvotes: 0

Alejandro Polak
Alejandro Polak

Reputation: 51

In my case, I had the same problem and solution:

flutter clean . 
 
flutter create .

This is a solution that I always try before almost any problem, then if it is not solved I see it in ..

Upvotes: 0

Kirito344
Kirito344

Reputation: 1

I figured that out the issue was caused by import 'package:firebase/firebase.dart'; in my project to Fix it delete that import

Upvotes: 0

user15604971
user15604971

Reputation:

If you're on VS code "try flutter clean then flutter run" on terminal

Upvotes: 1

Ashkan
Ashkan

Reputation: 141

Invalid depfile: D:\...\f5\.dart_tool\flutter_build\8e234dd4da26339b660f6097cc2a271a\kernel_snapshot.d

Delete kernel_snapshot.d and kernel_snapshot.stamp files at this location:

your flutter project\.dart_tool\flutter_build\8e234dd4da26339b660f6097cc2a271a

Upvotes: 14

VolcanoCoder
VolcanoCoder

Reputation: 733

Sometimes it happens to me too. I either deleted the converted code or converted it command For example here I entered:

import 'dart:html';

, And my error was fixed after deleting it or turning it into a comment

// import 'dart:html';

Upvotes: 70

Aashar Wahla
Aashar Wahla

Reputation: 3295

I had exactly the same error and later on came to find out that I had imported web-only dependency in my pubspec file.

In my case.

firebase: ^5.0.0

This is only for web.

Upvotes: 0

Sunggu Kim
Sunggu Kim

Reputation: 11

I experienced this. At first you have to check if you added the related dependencies on the pubspec.yaml file like below:

web_socket case ==>

( on pubspec.yaml )

dependencies: web_socket_channel: ^1.1.0
flutter: sdk:flutter

Upvotes: 1

you need clean the project run "flutter Clean" in the project and later run the project normal

Upvotes: 13

vinit jain
vinit jain

Reputation: 252

i also faced the same problem and i sort out by running "flutter clean" command. https://github.com/flutter/flutter/issues/21053

Upvotes: 19

Nihar Hegde
Nihar Hegde

Reputation: 636

I got the same error and I am following a udemy course as well.
I tried flutter pub get and it worked.

Upvotes: 50

GreenCodeSki
GreenCodeSki

Reputation: 909

Okay so I found out since I changed the PC, I needed to change permissions of a file. Follow here https://github.com/simolus3/moor/issues/224

Upvotes: 6

Related Questions