73

I was trying to run my Flutter app and this shows up:

    Compiler message:
lib/main.dart:1:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
Invalid depfile: C:\Users\IMBA\AndroidStudioProjects\mi_card_flutter-master\.dart_tool\flutter_build\410385fb4867e1d74565d68665ecb577\kernel_snapshot.d
Invalid depfile: C:\Users\IMBA\AndroidStudioProjects\mi_card_flutter-master\.dart_tool\flutter_build\410385fb4867e1d74565d68665ecb577\kernel_snapshot.d
...
Compiler message:
lib/main.dart:1:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ahtml; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:33:7)
#1      asFileUri (package:vm/kernel_front_end.dart:567:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:760:21)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:536:15)
<asynchronous suspension>
#4      _FlutterFrontendCompiler.compile (package:flutter_frontend_server/server.dart:40:22)
#5      starter (package:flutter_frontend_server/server.dart:178:27)
#6      main (file:///C:/b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:8:30)
#7      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

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

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\IMBA\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 882

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\IMBA\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 16s
Exception: Gradle task assembleDebug failed with exit code 1

And something else showed up after I used the --scan flag in the problem section.

java.lang.ClassNotFoundException: com.google.wireless.android.sdk.stats.IntellijIndexingStats$Index
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.intellij.util.indexing.counters.IndexCounters.<clinit>(IndexCounters.java:34)
    at com.intellij.util.indexing.impl.MapReduceIndex.<init>(MapReduceIndex.java:94)
    at com.intellij.util.indexing.impl.MapReduceIndex.<init>(MapReduceIndex.java:110)
    at org.jetbrains.jps.backwardRefs.index.CompilerReferenceIndex$CompilerMapReduceIndex.<init>(CompilerReferenceIndex.java:248)
    at org.jetbrains.jps.backwardRefs.index.CompilerReferenceIndex.<init>(CompilerReferenceIndex.java:84)
    at org.jetbrains.jps.backwardRefs.JavaCompilerBackwardReferenceIndex.<init>(JavaCompilerBackwardReferenceIndex.java:12)
    at org.jetbrains.jps.backwardRefs.JavaBackwardReferenceIndexWriter.initialize(JavaBackwardReferenceIndexWriter.java:80)
    at org.jetbrains.jps.incremental.java.JavaBuilder.buildStarted(JavaBuilder.java:149)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:359)
    at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:178)
    at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:139)
    at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:288)
    at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:121)
    at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:228)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

I took all the material of this Flutter app from the appbrewery Flutter course. This happens when I was trying to make the MIcard project. Any thoughts to solving this problem?

sergiy tikhonov
  • 4,961
  • 1
  • 10
  • 27
Vidya Marin
  • 765
  • 1
  • 6
  • 6
  • 1
    U might need to consider downgrading check this [enter link description here](https://stackoverflow.com/questions/65912637/how-can-i-fix-this-error-struct-utf8-is-empty-support-for-empty-structs-is-d) – Kisakyamukama May 21 '21 at 06:06

24 Answers24

76

Something that work for me is: Delete your pubspec.lock, and press 'Pub Get' in your pubspec.yaml, it'll regenerate pubspec.lock file again and should fix the problem.

Ahmed AlNeaimy
  • 343
  • 3
  • 14
Aldy Yuan
  • 1,795
  • 9
  • 23
45

Go to pubspec.yaml file, try doing Packages get | Pub get, and then build the project again.

Dharman
  • 30,962
  • 25
  • 85
  • 135
ANUP SAJJAN
  • 1,458
  • 13
  • 17
22

I faced the same error and further, I tried:

  1. flutter clean
  2. flutter pub get in the terminal, and the issue solved!
Deep
  • 399
  • 3
  • 3
7

I also tried this, thanks to iapicca

run in your terminal

flutter channel stable

flutter upgrade --force

flutter pub cache repair

next,

cd <YOUR APP FOLDER>

flutter clean

jeffasante
  • 2,549
  • 2
  • 8
  • 8
5

This should work!!!

flutter clean,


flutter pub get,


flutter build appbundle --release --no-tree-shake-icons

dbc
  • 104,963
  • 20
  • 228
  • 340
4

Just faced this issue, I solved it by removing an unused import

import 'dart:js';

the issue started when I added it by mistake, took a while to realize it was the issue

Fethi
  • 766
  • 7
  • 18
4

Just in case, do this:

IntelliJ/Android Studio: "Edit Configurations" (in your run configurations) → "Additional run args".

VS Code: search for "Flutter run additional args" in your user settings.

Then, add:

--no-sound-null-safety

This fixed the problem for me. What this basically does is that, if you use an import that doesn't support null safety, Flutter ignores it.

Hamza Amr
  • 165
  • 1
  • 12
3

Optimizing imports (Ctrl + Alt + O) in Android Studio solved the issue for me. Studio Screenshot

zrhl
  • 87
  • 2
  • 9
3

This error happens when indentation is not proper in pubspec.yaml file. Make sure font and other dependencies are having right indentation.

Sriraksha
  • 459
  • 1
  • 8
  • 15
3

delete pubspeck.lock and pub get , didn't solve my problem.

in my case its caused by import 'dart:html';.

VSCode sometimes imports these libs automatically instead of what we want is import 'dart:io';

Look for in your file which has import 'dart:html'; and delete it. then you can run the app again.

pmatatias
  • 3,491
  • 3
  • 10
  • 30
2

This worked for me.

Deleted build and android/app/build.

2

this solution work for me :

1 - delete pubspeck.lock

2 - run flutter clean

3 - run flutter pub get

Zakaria Ferzazi
  • 364
  • 3
  • 4
1

I couldn't build for iOS, so I deleted flutter/bin/cache/artifacts. iOS works well then building Android had the same error. I tried flutter upgrade and that solved the problem.

thanhbinh84
  • 17,876
  • 6
  • 62
  • 69
  • 1
    I did the same artifcat removal by following a youtube tutorial. Upgrading flutter solved the issue. – Rajesh Nov 12 '22 at 16:40
1

Removing .gradle folder helped

Gradle is located at

On Windows: %USERPROFILE%\.gradle

On Mac / UNIX: ~/.gradle
  1. Close android studio.
  2. Remove whole .gradle folder.
  3. Open Android studio and build.
Jakub S.
  • 5,580
  • 2
  • 42
  • 37
1
  1. Go to the pubspec.yaml file and Download packages

OR

  1. Go to Terminal flutter pub get

  2. Upgrade Flutter flutter upgrade --force

  3. Run Flutter App Press F5 or flutter run

Sarthak Raval
  • 1,001
  • 1
  • 10
  • 23
1

Try this, it might work for you

flutter clean,

flutter pub get,

flutter build apk --release --no-tree-shake-icons

If you have flavours then add flavour with the build command. And update the minimumsdk to a higher version compatible with java version.

0

I managed to solve this problem by reading a different topic here: Recompile with Xlint

First, find your build.gradle file from the Android folder (Android/app/build.gradle)

Then paste the following code inside the android brackets {}:

allprojects {
tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}}

I have pasted it at the bottom before the end bracket and it worked for me.

After this, just restart your app and it should work.

nik7
  • 806
  • 3
  • 12
  • 20
MariusMihai92
  • 19
  • 1
  • 6
0

I found solution update flutter sdk.

flutter channel stable

flutter upgrade --force
AK IJ
  • 492
  • 4
  • 10
0

Delete pubspec.lock file and then flutter clean and flutter pub get . This works like a charm.

Amazed
  • 49
  • 2
  • 2
0

the packages that you added are not updated . sometimes it is old version . so update the pckages that mentioned under the dependencies in your pubspec file .

Rasathurai Karan
  • 673
  • 5
  • 16
0

I did fix the issue by removing an unused import:

import 'dart:developer';

So I will highly recommand you to remove all unused imports before trying any of the other solutions

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
mr.Penguin
  • 1,166
  • 1
  • 8
  • 24
0

please check your asset rooting in pubspec.yaml

assets: - assets/images/logo.svg

then thats clear

try to

flutter pub get
RIYAS PULLUR
  • 13
  • 1
  • 4
0

Use "Flutter Upgrade" command to resolve this issue.

if you are using android studio, go to the menu options and select Tools-->Flutter-->Flutter Upgrade.

0

This error can happen for many reasons, and there are multiple solutions to solve this issue.

Solution 1:

Run following commands

flutter clean

"invalidate cache and restart" by navigating file>invalidate Caches

flutter pub get

Hit flutter run, hope this would work.

Solution 2:

Hit

flutter clean

Delete following files form your root-project directory

.dart_tool
.idea
build
pubspec.lock
.flutter-plugins
.flutter-plugins-dependencies

"invalidate cache and restart" by navigating file>invalidate Caches

Open android folder into Android Studio, it would take some time and download all the packages

Open flutter project again, android studio do some indexing. then hit

flutter pub get
flutter run

Enjoy! this solution should work

Solution 3:

Simply hit flutter run it gives you list of errors (red & blue color) at above " Execution failed for task ':app:compileFlutterBuildDebug'"

Read each error carefully, there would be a directory path from which you can get the package name of BAD EGG

Upgrade that imposter (Package) manually, And hit flutter run again

Repeat this process for each error, Once you solve the dependency issues among packages, that resolve your problem.

Enjoy!