Flutter Could not prepare to run the isolate
Asked Answered
B

21

32

I started a flutter project using Android studio. The android emulator opened the project smoothly. When I opened the Ios emulator, the project worked smoothly. When I ran the android emulator again, project isn't runed . Thanks for your help.

Android Studio Features :

  • Android Studio 3.0
  • Build #AI-171.4408382, built on October 20, 2017
  • JRE: 1.8.0_152-release-915-b08 x86_64
  • JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  • Mac OS X 10.12.6

Flutter : v0.4.4 Beta

Console :

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
I/FlutterActivityDelegate( 2747): onResume setting current activity to this
E/flutter ( 2747): [ERROR:flutter/shell/common/engine.cc(147)] Could not prepare to run the isolate.
E/flutter ( 2747): [ERROR:flutter/shell/common/engine.cc(112)] Engine not prepare and launch isolate.
E/flutter ( 2747): [ERROR:flutter/shell/platform/android/android_shell_holder.cc(138)] Could not launch engine in configuration.
Syncing files to device Android SDK built for x86...
Application finished.
Brownlee answered 2/6, 2018 at 8:4 Comment(4)
Share some of your code.Wonderland
@Wonderland There is default project. Counter project.Principal
Did you run flutter doctor?Wonderland
You would get this error when something is messed up with the main() method in the main.dart file.Odd
P
42

If you are facing the problem even if you have main method in main.dart inside your lib folder

Try

flutter clean

And then

flutter run

Worked for me :)

Parry answered 19/5, 2020 at 18:56 Comment(0)
C
56

I had the same error and it happened when I didn't write the main method. so do this

void main() => runApp(MyApp());

MyApp is my main class

Centenarian answered 13/7, 2018 at 14:18 Comment(1)
Ha! Some reason the refactoring in VSCode deleted this method, got me confused for a full several minutes. Thank you very much :)Detrusion
P
42

If you are facing the problem even if you have main method in main.dart inside your lib folder

Try

flutter clean

And then

flutter run

Worked for me :)

Parry answered 19/5, 2020 at 18:56 Comment(0)
I
17

if you use VS code editor, make sure you press the run button only when the main.dart file is opened. Pressing run when other files are opened also causes this error.

Another file is opened, pressing run will cause the error: Another file is opened, running program now will cause the error

Main.dart file is opened, now you can run your program: enter image description here

Inchoation answered 17/5, 2023 at 10:12 Comment(4)
This helped me, but why? Can I fix this in some way, like specify where is the main file so that I don't need to go to it every time I want to start the app?Realgar
Answer needs supporting information Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Originative
@PrzemysławWrzesiński Main.dart is the start for any flutter app, so you only need to run your app from that file. I think full-blown IDEs have that feature by default like android studio or Visual Studio IDE but I couldn't find the same for VS code editorInchoation
Thanks @Inchoation ! I found a way to do it - you need to create a launch.json file as described here which you can use to configure the app and then add the "program" argument to all configurations, see hereRealgar
S
5
  1. please check whether your Flutter Project containsmain.dart in lib folder, if not, create it.

  2. check your code like this:

import 'package:flutter/material.dart';
import 'package:module_flutter/xxxApp.dart';

void main() => runApp( new xxxApp());
Simian answered 13/9, 2018 at 9:28 Comment(0)
P
4

make sure that you are clicked debug on the main.dart page and you won't face this error again, in case try to debug from another page you will face this error.

Prairial answered 12/4, 2023 at 23:54 Comment(0)
D
3
  1. Check device or emulator has enough storage, if not uninstall some for making space
  2. remove the cache folder rm -rf ${FLUTTER_ROOT}/bin/cache
  3. flutter clean
  4. flutter run
Deuterogamy answered 1/6, 2022 at 2:8 Comment(0)
R
2

I had a very similar situation and the main reason was that my application runs using multiple flavors and in the tag 'program' of the flavors configuration (in the case of VS code), I found a different entry point file (ex: app.dart) and the correct entry point was other (main.dart)

{
            "name": "xyz",
            "request": "launch",
            "type": "dart",
            "program": "lib/main.dart", //here was the problem
            "args": [
                "--flavor",
                "dev"
            ]
        }

Hope this can help someone!

Reflective answered 27/9, 2022 at 21:11 Comment(0)
E
2

Below commands on the terminal worked for me.

  1. Flutter pub cache clean
  2. Flutter pub get
  3. Flutter clean
  4. Flutter packages get
Eureetloir answered 16/5, 2023 at 6:30 Comment(0)
C
2

It happened to me when used "Start Debugging" button in VS code that at the top and right of window while opening another dart file (Not main.dart).

Carpology answered 19/5, 2023 at 13:10 Comment(0)
B
1

I have the same error. I tried many ways and this is the right way.

You need to run

flutter build ios --debug (or --profile or --release)

before you launch the project in Xcode.

Boggers answered 9/3, 2020 at 2:32 Comment(0)
S
1

These methods will maybe work restart android studio, run flutter clean, reinstall flutter in the same location:- be careful when doing, check the SDK is installed and if installed the check the SDK is in the project or not, check the project code again and again. click get dependencies to get everything in the project, check spelling mistakes. I Hope Your Project runs Smooth Now.

Seow answered 20/4, 2021 at 10:6 Comment(0)
A
1

Check whether your main function is using run-app.

void main() {
  runApp(PageName());
}

This mentioned above should be present.

Attractive answered 19/11, 2022 at 3:4 Comment(0)
E
1

This can happen due to two reasons mainly:

  1. You do not have a main() function set up properly.
  2. You try to run it from other folders other than main.dart.
Eureetloir answered 23/5, 2023 at 5:19 Comment(0)
P
1

None of the methods worked for me. Eventually I uninstalled the previous version of the app on the device (but failed to launch for another reason and presumably still in stuck state). Then it worked.

Persecute answered 28/6, 2023 at 19:43 Comment(0)
C
1

I deleted my .vscode folder and that solved it for me.

Chlorenchyma answered 12/7, 2023 at 6:22 Comment(0)
V
1

Most likely this will occur if you have not written the void main(){ runApp(const MyApp())} so make sure you have done that

Valona answered 24/8, 2023 at 0:49 Comment(2)
This was already explained in the top answer here, please upvote that instead of posting a new answer or explain whether and how your answer is different.Diffraction
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Halliard
B
0

Make sure you'r app is not running multiple instances. Try to stop them all first.

Behoof answered 17/10, 2019 at 14:29 Comment(0)
W
0

I have had the same problem. Just go you your main.dart file and verify if it has

void main(){
runApp(MyApp());
}

before 'class MyApp extends StatelessWidget'

Now save the file by "CTRL+S" and run you app. It will solve your problem. Hope you find it helpful

Would answered 30/4, 2023 at 20:41 Comment(0)
G
0

I am using visual studio code, I had same error. I run command,

  1. Flutter clean
  2. Flutter packages get

Make sure your main method is correct.

Also, Visual studio code needs "main.dart" file to be opened while you run the debug command.

Gratifying answered 17/5, 2023 at 13:41 Comment(0)
W
0

There might unique condition like mine.

If your project have environment setup(like mine is DEV and PROD).

And if you want to run project in DEV mode then you should run project from dev_main.dart and similarly for PROD.

Womenfolk answered 14/3, 2024 at 5:39 Comment(0)
W
0

I got this when trying to run a test program outside of lib. In such cases, you need code like this:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}
Weakly answered 24/6, 2024 at 1:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.