How to fix Waiting for observatory port to be available issue

In an earlier post I talked about an issue that I ran into when I change package name in Manifest.xml file of my Flutter application in VS Code. At that time the issue was related to error saying Failed to launch emulator in 60 seconds. I got out of that issue by wiping data in emulator. The problem was related to a corrupted APK file left in emulator.

Now I ran into an issue with a new project. When you ask VS Code to use boiler plate code for Flutter application, package name is always set to com.exmaple.{app_name}. At some point you will change the package name to reflect your organization's name and URL. In my case I renamed it to com.byteblocks.byte_rx. Now my Manifext.xml file looked like below.

<manifest xmlns:android=""
    <uses-permission android:name="android.permission.INTERNET" />

When I tried to debug the application against Pixel 3 emulator, VS Code got stuck with the message Installing build\app\outputs\apk\app.apk. I tried wiping data from emulator, doing cold reboot etc. I got nowhere with any of the suggestions.

At this point, you have to look at verbose information related to building and running of the application. First run following command from VS Code Terminal itself.

flutter run -v

When I ran this command, at the very end the process stopped with following trace messages.

[   +9 ms] executing: C:\Users\cobyk\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 
    shell am start -a android.intent.action.RUN -f 0x20000000
--ez enable-background-compilation true --ez enable-dart-profiling true --ez enable-checked-mode true --ez verify-entry-points true
[ +282 ms] Starting: Intent { act=android.intent.action.RUN flg=0x20000000 cmp=com.byteblocks.byte_rx/.MainActivity (has extras) }
[   +1 ms] Waiting for observatory port to be available...

As you can see that application is trying to run and launch MainActivity and then got stuck. I looked at MainActivity.kt Kotlin file. It looked like below.

package com.example.byte_rx


class MainActivity: FlutterActivity() {

Very first line is where the problem. I had renamed my package to com.byteblocks.byte_rx. I did not make the same change here. I change that line and the code file looks like below.

package com.byteblocks.byte_rx


class MainActivity: FlutterActivity() {

After that I followed following steps to check if the issue has been fixed.

  • On VS Code Teminal, run flutter clean command. Just to be on safe side, clean all the old build files.
    PS C:\Development\Projects\MobileApps\byte_rx> flutter clean
    Deleting build...                                                  338ms
    Deleting .dart_tool...                                              14ms
    Deleting .packages...                                                1ms
    Deleting Generated.xcconfig...                                       0ms
    Deleting                            0ms
  • Now build the application by running flutter build apk command.
    PS C:\Development\Projects\MobileApps\byte_rx> flutter build apk
    Running "flutter pub get" in byte_rx...                            764ms
     Building with sound null safety 
    Running Gradle task 'assembleRelease'...                                
    Running Gradle task 'assembleRelease'... Done                      37.6s
    √  Built build\app\outputs\flutter-apk\app-release.apk (15.4MB).
  • Last step is to execute flutter run -v. Do run it with verbose option so that you can see if we are not getting at same error before. If problem is fixed, you should see your application launched in emulator.

It would have been helpful, if VS Code would have shown the issue during build time. Oh well, at some point in future VS Code may want to add this as an enhancement.




20.9 °C / 69.5 °F

weather conditions Clouds

Monthly Posts

Blog Tags