Search code examples
androidflutterterminaladb

Launch a Flutter apk using adb and open the dart observatory


I have an APK that is built in debug mode using flutter build apk --debug. I want to launch that APK using adb then connect to the dart VM service that is spun up.

I launch the application using:

adb -s emulator-5554 shell am start -n com.filledstacks.bookshelf/com.filledstacks.bookshelf.MainActivity

This works as expected and launches the app with the output:

Starting: Intent { cmp=com.filledstacks.bookshelf/.MainActivity }

I then use logCat to get the log for my Flutter application using the following shell command.

adb -s emulator-5554 logcat -d flutter:I '*:S' -T '09-20 16:24:48.967'

The command above filters logs for all flutter:I logs. This prints out what I expect:

--------- beginning of main
09-20 16:25:16.939 14663 14702 I flutter : The Dart VM service is listening on http://127.0.0.1:36659/Ex8iWuJ4xEo=/

But when I open that url I get the "site can't be reached message".

My guess is that the process that launches the app is stopped, which shuts down the observatory. But I don't have enough terminal experience to test that out. I've been trying for about 2 hours.

I'm on MacOS using latest adb.


Solution

  • Try opening the URL by replacing 127.0.0.1 with 10.0.2.2 This is the address for the emulator.

    OR

    You can port forward from the emulator to your host machine for accessing using 127.0.0.1.