Skip to content

Support running emulators when running in remote/container environments #3315

@Delgan

Description

@Delgan

Describe the bug
Hi!
I'm using the Remote - Containers extension with the Flutter' one on Linux. I can successfully configure Flutter, create an emulator, launch it, and run my application.

The problem: when I press F5 the existing device is not listed and there is no "Create Android emulator" option.
Also, when I press Ctrl+Shift+P and search for "Flutter: Launch Emulator" there is no such command.

Note that if I create the emulator with flutter emulators --create and then start it with flutter emulators --launch then I'm able to run my application using F5 and it's working perfectly fine. However, the Flutter extension won't mention the device if it is not launched, even after restarting VSCode (although it's somehow detected by the Flutter daemon according to logs below).

To Reproduce

  1. Open a local Flutter project
  2. Install Remote Development VSCode extension
  3. Use the following Dockerfile to configure Remote - Containers extension (important: KVM_GID needs to be modified):
FROM ubuntu:20.04

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# The container is configured for non-root user but we need to access "/dev/kvm" to run emulators.
# We have to map the group owner of "/dev/kvm` from host (which is "kvm") to inside the container.
# So we'll create a new "kvm" group with the id from host returned in "cat /etc/group | grep kvm"). 
ARG KVM_GID=108

RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    && apt-get update \
	&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
        sudo \
        openjdk-8-jdk-headless \
	    wget curl git xz-utils zip unzip libglu1 \
        python3 python3-dev python3-venv python3-pip python3-tk \
        libpulse-dev libxcomposite-dev libxcursor-dev libasound2-dev kmod qemu-kvm \
        ssh vim locate \
	&& apt-get autoremove -y \
	&& apt-get clean -y \
	&& rm -rf /var/lib/apt/lists/* \
    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
    && chmod 0440 /etc/sudoers.d/$USERNAME \
    && groupadd -g $KVM_GID kvm \
    && adduser $USERNAME kvm

RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
    && mkdir /commandhistory \
    && touch /commandhistory/.bash_history \
    && chown -R $USERNAME /commandhistory \
    && echo $SNIPPET >> "/home/$USERNAME/.bashrc"
    
RUN cd /opt \
	&& wget -O android-sdk-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-6514223_latest.zip \
	&& mkdir -p /opt/android-sdk-linux/cmdline-tools/ \
	&& unzip -q android-sdk-tools.zip -d /opt/android-sdk-linux/cmdline-tools/ \
	&& rm android-sdk-tools.zip \
    && chown -R $USERNAME android-sdk-linux

RUN cd /opt \
    && wget -O flutter_linux.tar.xz https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_2.0.5-stable.tar.xz \
    && tar xf flutter_linux.tar.xz \
    && rm flutter_linux.tar.xz \
    && chown -R $USERNAME flutter

RUN cd /opt \
    && wget -O android-studio.tar.gz https://redirector.gvt1.com/edgedl/android/studio/ide-zips/4.1.3.0/android-studio-ide-201.7199119-linux.tar.gz \
    && tar xzvf android-studio.tar.gz \
    && rm android-studio.tar.gz \
    && chown -R $USERNAME android-studio

USER $USERNAME

ENV PATH $PATH:/opt/flutter/bin:/opt/android-sdk-linux/cmdline-tools/tools/bin:/opt/android-sdk-linux/platform-tools:/opt/android-sdk-linux/emulator:/opt/android-studio/bin
ENV ANDROID_SDK_ROOT=/opt/android-sdk-linux

RUN yes | sdkmanager --licenses \
	&& touch $HOME/.android/repositories.cfg \
	&& sdkmanager platform-tools \
	&& sdkmanager emulator \
	&& sdkmanager "platforms;android-29" "build-tools;29.0.3" \
    && sdkmanager "system-images;android-27;google_apis_playstore;x86"

RUN yes | flutter doctor --android-licenses \
    && flutter config --no-enable-web --no-analytics \
    && flutter update-packages \
    && flutter emulators --create --name foobar
  1. Use the following devcontainer.json to configure Remote - Containers extension:
{
	"name": "Dart",
	"build": {
		"dockerfile": "Dockerfile"
	},
	"settings": {
		"terminal.integrated.shell.linux": "/bin/bash"
	},
	"extensions": [
		"dart-code.dart-code",
		"dart-code.flutter",
		"ms-python.python"
	],
	"remoteUser": "vscode",
	"mounts": [
		"source=projectname-bashhistory,target=/commandhistory,type=volume"
	],
	"runArgs": [
		"--device=/dev/kvm",
		"-e",
		"DISPLAY=${localEnv:DISPLAY}",
		"-v",
		"/tmp/.X11-unix:/tmp/.X11-unix"
	],
	"postCreateCommand": "flutter pub get"
}
  1. Use the Remote - Containers extension to build and open your local project in a Docker container.
  2. Install Flutter and Dart extensions inside the remote container.
  3. Press F5 and notice there is no device listed.

Expected behavior
When pressing F5, the "foobar" device should be listed and there should be a "Create Android device" option.
The "Flutter: Launch Emulator" command should also be available.

Screenshots
No screenshots but some outputs.

vscode@4b020da5cc29:/workspaces/myproject$ flutter doctor -v
[✓] Flutter (Channel stable, 2.0.5, on Linux, locale en_US.UTF-8)
    • Flutter version 2.0.5 at /opt/flutter
    • Framework revision adc687823a (2 weeks ago), 2021-04-16 09:40:20 -0700
    • Engine revision b09f014e96
    • Dart version 2.12.3

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /opt/android-sdk-linux
    • Platform android-29, build-tools 29.0.3
    • ANDROID_SDK_ROOT = /opt/android-sdk-linux
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Android Studio
    • Android Studio at /opt/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.
vscode@4b020da5cc29:/workspaces/myproject$ flutter emulators
1 available emulator:

foobar • foobar • Google • android

To run an emulator, run 'flutter emulators --launch <emulator id>'.
To create a new emulator, run 'flutter emulators --create [--name xyz]'.

You can find more information on managing emulators at the links below:
  https://developer.android.com/studio/run/managing-avds
  https://developer.android.com/studio/command-line/avdmanager
vscode@4b020da5cc29:/workspaces/myproject$ flutter devices  
No devices detected.

Run "flutter emulators" to list and start any available device emulators.

If you expected your device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try increasing the time to wait for connected devices with the
--device-timeout flag. Visit https://flutter.dev/setup/ for troubleshooting tips.
vscode@4b020da5cc29:/workspaces/myproject$ cat logs/flutter-daemon.log 
!! PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING !!

Dart Code extension: 3.21.1
Flutter extension: 3.21.0 (not activated)

App: Visual Studio Code
Remote: dev-container
Version: 1.55.2
Platform: linux

HTTP_PROXY: undefined
NO_PROXY: undefined

Logging Categories:
    FlutterDaemon

Sun May 02 2021 [15:06:40 GMT+0000 (Coordinated Universal Time)] Log file started
[3:06:40 PM] [FlutterDaemon] [Info] Spawning /opt/flutter/bin/flutter with args ["daemon","--show-web-server-device"]
[3:06:40 PM] [FlutterDaemon] [Info] ..  in /opt/flutter
[3:06:40 PM] [FlutterDaemon] [Info] ..  with {"toolEnv":{"FLUTTER_HOST":"VSCode","PUB_ENVIRONMENT":"vscode.dart-code"}}
[3:06:40 PM] [FlutterDaemon] [Info]     PID: 236
[3:06:40 PM] [FlutterDaemon] [Info] ==> [{"id":"1","method":"emulator.getEmulators"}]
[3:06:42 PM] [FlutterDaemon] [Info] <== [{"event":"daemon.connected","params":{"version":"0.6.0","pid":407}}]
[3:06:42 PM] [FlutterDaemon] [Info] ==> [{"id":"2","method":"device.enable"}]
[3:06:42 PM] [FlutterDaemon] [Info] <== [{"event":"daemon.logMessage","params":{"level":"status","message":"Starting device daemon..."}}]
[3:06:42 PM] [FlutterDaemon] [Info] <== [{"id":"2"}]
[3:06:42 PM] [FlutterDaemon] [Info] <== [{"id":"1","result":[{"id":"foobar","name":"foobar","category":"mobile","platformType":"android"}]}]
[3:07:01 PM] [FlutterDaemon] [Info] ==> [{"id":"3","method":"daemon.getSupportedPlatforms","params":{"projectRoot":"/workspaces/myproject"}}]
[3:07:01 PM] [FlutterDaemon] [Info] <== [{"id":"3","result":{"platforms":["ios","android"]}}]
[3:07:02 PM] [FlutterDaemon] [Info] ==> [{"id":"4","method":"daemon.getSupportedPlatforms","params":{"projectRoot":"/workspaces/myproject"}}]
[3:07:02 PM] [FlutterDaemon] [Info] <== [{"id":"4","result":{"platforms":["ios","android"]}}]
[3:07:02 PM] [General] [Warn] Unable to launch due to no active device
vscode@4b020da5cc29:/workspaces/myproject$ cat logs/dart-application.log 
!! PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING !!

Dart Code extension: 3.21.1
Flutter extension: 3.21.0 (not activated)

App: Visual Studio Code
Remote: dev-container
Version: 1.55.2
Platform: linux

HTTP_PROXY: undefined
NO_PROXY: undefined

Logging Categories:
    General

Sun May 02 2021 [15:06:40 GMT+0000 (Coordinated Universal Time)] Log file started
[3:06:40 PM] [General] [Info] Searching for SDKs...
[3:06:40 PM] [General] [Info] Environment PATH:
[3:06:40 PM] [General] [Info]     /vscode/vscode-server/bin/x64/3c4e3df9e89829dce27b7b5c24508306b151f30d/bin
[3:06:40 PM] [General] [Info]     /usr/local/sbin
[3:06:40 PM] [General] [Info]     /usr/local/bin
[3:06:40 PM] [General] [Info]     /usr/sbin
[3:06:40 PM] [General] [Info]     /usr/bin
[3:06:40 PM] [General] [Info]     /sbin
[3:06:40 PM] [General] [Info]     /bin
[3:06:40 PM] [General] [Info]     /opt/flutter/bin
[3:06:40 PM] [General] [Info]     /opt/android-sdk-linux/cmdline-tools/tools/bin
[3:06:40 PM] [General] [Info]     /opt/android-sdk-linux/platform-tools
[3:06:40 PM] [General] [Info]     /opt/android-sdk-linux/emulator
[3:06:40 PM] [General] [Info]     /opt/android-studio/bin
[3:06:40 PM] [General] [Info] Found Flutter project at /workspaces/myproject:
                        Mobile? true
                        Web? false
                        Create Trigger? false
                        Flutter Repo? false
[3:06:40 PM] [General] [Info] Searching for flutter
[3:06:40 PM] [General] [Info]     Looking for flutter in:
[3:06:40 PM] [General] [Info]         /workspaces/myproject
[3:06:40 PM] [General] [Info]         /workspaces/myproject/bin
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/
[3:06:40 PM] [General] [Info]         /workspaces/myproject/.flutter
[3:06:40 PM] [General] [Info]         /workspaces/myproject/.flutter/bin
[3:06:40 PM] [General] [Info]         /workspaces/myproject/vendor/flutter
[3:06:40 PM] [General] [Info]         /workspaces/myproject/vendor/flutter/bin
[3:06:40 PM] [General] [Info]         /home/vscode/snap/flutter/common/flutter
[3:06:40 PM] [General] [Info]         /home/vscode/snap/flutter/common/flutter/bin
[3:06:40 PM] [General] [Info]         /vscode/vscode-server/bin/x64/3c4e3df9e89829dce27b7b5c24508306b151f30d/bin
[3:06:40 PM] [General] [Info]         /usr/local/sbin
[3:06:40 PM] [General] [Info]         /usr/local/bin
[3:06:40 PM] [General] [Info]         /usr/sbin
[3:06:40 PM] [General] [Info]         /usr/bin
[3:06:40 PM] [General] [Info]         /sbin
[3:06:40 PM] [General] [Info]         /bin
[3:06:40 PM] [General] [Info]         /opt/flutter/bin
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/cmdline-tools/tools/bin
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/platform-tools
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/platform-tools/bin
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/emulator
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/emulator/bin
[3:06:40 PM] [General] [Info]         /opt/android-studio/bin
[3:06:40 PM] [General] [Info]     Found at:
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/
[3:06:40 PM] [General] [Info]         /opt/flutter/bin
[3:06:40 PM] [General] [Info]     Candidate paths to be post-filtered:
[3:06:40 PM] [General] [Info]         /opt/flutter
[3:06:40 PM] [General] [Info]         /opt/flutter
[3:06:40 PM] [General] [Info]     Found at /opt/flutter
[3:06:40 PM] [General] [Info]     Returning SDK path /opt/flutter for flutter
[3:06:40 PM] [General] [Info] Searching for dart
[3:06:40 PM] [General] [Info]     Looking for dart in:
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/cache/dart-sdk
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/cache/dart-sdk/bin
[3:06:40 PM] [General] [Info]         /vscode/vscode-server/bin/x64/3c4e3df9e89829dce27b7b5c24508306b151f30d/bin
[3:06:40 PM] [General] [Info]         /usr/local/sbin
[3:06:40 PM] [General] [Info]         /usr/local/bin
[3:06:40 PM] [General] [Info]         /usr/sbin
[3:06:40 PM] [General] [Info]         /usr/bin
[3:06:40 PM] [General] [Info]         /sbin
[3:06:40 PM] [General] [Info]         /bin
[3:06:40 PM] [General] [Info]         /opt/flutter/bin
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/cmdline-tools/tools/bin
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/platform-tools
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/platform-tools/bin
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/emulator
[3:06:40 PM] [General] [Info]         /opt/android-sdk-linux/emulator/bin
[3:06:40 PM] [General] [Info]         /opt/android-studio/bin
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/cache/dart-sdk
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/cache/dart-sdk/bin
[3:06:40 PM] [General] [Info]     Found at:
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/cache/dart-sdk/bin
[3:06:40 PM] [General] [Info]         /opt/flutter/bin
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/cache/dart-sdk/bin
[3:06:40 PM] [General] [Info]     Candidate paths to be post-filtered:
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/cache/dart-sdk
[3:06:40 PM] [General] [Info]         /opt/flutter
[3:06:40 PM] [General] [Info]         /opt/flutter/bin/cache/dart-sdk
[3:06:40 PM] [General] [Info]     Found at /opt/flutter/bin/cache/dart-sdk
[3:06:40 PM] [General] [Info]     Returning SDK path /opt/flutter/bin/cache/dart-sdk for dart
[3:06:40 PM] [General] [Info] Experiment random number is 81 for experiement 'lsp-default'. Experiment is enabled for <= 10
[3:06:40 PM] [General] [Info] !! PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING !!

Dart Code extension: 3.21.1
Flutter extension: 3.21.0 (not activated)

App: Visual Studio Code
Remote: dev-container
Version: 1.55.2
Platform: linux

Workspace type: Flutter
Analyzer type: DAS
Multi-root?: false

Dart SDK:
    Loc: /opt/flutter/bin/cache/dart-sdk
    Ver: 2.12.3
Flutter SDK:
    Loc: /opt/flutter
    Ver: 2.0.5

HTTP_PROXY: undefined
NO_PROXY: undefined
[3:06:40 PM] [General] [Info] Spawning /opt/flutter/bin/cache/dart-sdk/bin/pub with args ["global","list"]
[3:06:40 PM] [General] [Info] Activating Flutter extension for Flutter project...
[3:06:40 PM] [General] [Info] Extension:Startup timing: 158ms
[3:06:40 PM] [General] [Info] Found 0 folders requiring "pub get":
[3:06:40 PM] [General] [Info] !! PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING !!

Dart Code extension: 3.21.1
Flutter extension: 3.21.0 (activated)

App: Visual Studio Code
Remote: dev-container
Version: 1.55.2
Platform: linux

Workspace type: Flutter
Analyzer type: DAS
Multi-root?: false

Dart SDK:
    Loc: /opt/flutter/bin/cache/dart-sdk
    Ver: 2.12.3
Flutter SDK:
    Loc: /opt/flutter
    Ver: 2.0.5

HTTP_PROXY: undefined
NO_PROXY: undefined
[3:06:40 PM] [General] [Info] devtools has no installed version, returning NotInstalled
[3:06:40 PM] [General] [Info] Spawning /opt/flutter/bin/cache/dart-sdk/bin/pub with args ["global","activate","devtools"]
[3:06:41 PM] [General] [Info] Analyzer:Startup timing: 1248ms
[3:06:54 PM] [General] [Info] Spawning /opt/flutter/bin/cache/dart-sdk/bin/pub with args ["global","list"]
[3:06:54 PM] [General] [Info] devtools version 2.1.1 appears to be latest so returning Valid
[3:07:01 PM] [General] [Info] Starting debug session...
[3:07:01 PM] [General] [Info]     workspace: /workspaces/myproject
[3:07:01 PM] [General] [Info] Using found common entry point: /workspaces/myproject/lib/main.dart
[3:07:01 PM] [General] [Info] Using workspace as cwd: /workspaces/myproject
[3:07:01 PM] [General] [Info] Detected launch project as Flutter
[3:07:01 PM] [General] [Info] Using Flutter debug adapter for this session
[3:07:02 PM] [General] [Warn] Unable to launch due to no active device

Versions:

  • VS Code version: 1.55.2
  • Dart extension version: 3.21.1 (Dart) / 3.21.0 (Flutter)
  • Dart/Flutter SDK version: 2.12.13 (Dart) / 2.0.5 (Flutter)

Metadata

Metadata

Assignees

No one assigned

    Labels

    in flutterRelates to running Flutter appsin remoteRelates to running the extension in a remote setting using VS Code's remote dev supportis enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions