Skip to content

Allow setting environment variables in flutterflutterCustomEmulators #3267

Closed

Description

@hossamdash

Launching the android emulator under arch linux, wayland and the sway wm results in it hanging for a minute and then failing to start with an error message :
Failed to launch Pixel: Error: Emulator didn't connect within 60 seconds.
starting the emulator from the terminal by $ /opt/android-sdk/emulator/emulator @flutter_emulator and seeing the error message

handleCpuAcceleration: feature check for hvf
emulator: INFO: QtLogger.cpp:68: Warning: Could not find the Qt platform plugin "wayland" in "/opt/android-sdk/emulator/lib64/qt/plugins" ((null):0, (null))


Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.
 ((null):0, (null))
emulator: INFO: QtLogger.cpp:68: Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.
 ((null):0, (null))


zsh: abort (core dumped)  /opt/android-sdk/emulator/emulator @flutter_emulator

I have the following in my environment file to make QT applications launch under wayland QT_QPA_PLATFORM=wayland. in order to make the android emulator work i have to prefix the emulator command with a env variable override like so
env QT_QPA_PLATFORM=xcb /opt/android-sdk/emulator/emulator @flutter_emulator or simply just
QT_QPA_PLATFORM=xcb /opt/android-sdk/emulator/emulator @flutter_emulator
how can i make the dart extension launch the emulator with this override?
what i tried :
in my settings.json of vscode

"dart.flutterCustomEmulators": [
        {
            "id": "flutter_emulator",
            "name": "Pixel",
            "executable": "QT_QPA_PLATFORM=xcb /opt/android-sdk/emulator/emulator",
        }
    ]

and

        {
            "id": "flutter_emulator",
            "name": "Pixel",
            "executable": "/opt/android-sdk/emulator/emulator",
            "args":["QT_QPA_PLATFORM=xcb "]
        }
    ]

both didn't work.
and the second attempt i knew was not going to work as the env override needs to happen at the begining of the command. could a way be provided to pass env variables overrides to the custom emulator configuration ?

Activity

  1. DanTup commented on Apr 12, 2021

    @DanTup
    Member

    Is there any harm in setting QT_QPA_PLATFORM=xcb for all Dart/Flutter process spawned by the extension?

    If not, then you could use the dart.env setting, either at the User Settings level or Workspace Settings:

    "dart.env": {
      "QT_QPA_PLATFORM": "xcb"
    }

    If that doesn't work, then we could extend flutterCustomEmulators to have an env key too.

  2. added
    in flutterRelates to running Flutter apps
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    and removed on Apr 12, 2021
  3. added this to the v3.22.0 milestone on Apr 12, 2021
  4. DanTup commented on Apr 12, 2021

    @DanTup
    Member

    (you may not even need flutterCustomEmulators at all if setting dart.env will work for you)

  5. hossamdash commented on Apr 12, 2021

    @hossamdash
    Author

    Thanks, that did the trick. I still think adding an env key to flutterCustomEmulators would be a good option - although not a very important one - to have if another QT application { a different emulator, a web browser maybe?, etc.. } were to support native wayland while the one from google didn't and you wanted to use them both. feel free to close this for now!

  6. changed the title [-]Google's android emulator not launching under wayland[/-] [+]Allow setting environment variables in flutterflutterCustomEmulators[/+] on Apr 12, 2021
  7. DanTup commented on Apr 12, 2021

    @DanTup
    Member

    I still think adding an env key to flutterCustomEmulators would be a good option

    Yeah, I think so too - I've updated the title of this issue for that. Thanks!

  8. gusbemacbe commented on Jun 21, 2021

    @gusbemacbe

    Hello @hossamdash and @DanTup !

    I also run Manjaro with Sway, and have your problem, but I tried your settings and it did not work at all. I tried:

        "dart.env": 
        {
            "_JAVA_AWT_WM_NONREPARENTING": 1,
            "QT_QPA_PLATFORM": "xcb"
        },
        "dart.flutterCustomEmulators": 
        [
            {
                "id": "Pixel_2_API_29",
                "name": "Pixel 2 API 29",
                "executable": "QT_QPA_PLATFORM=xcb _JAVA_AWT_WM_NONREPARENTING=1 /home/gusbemacbe/Android/SDK/emulator/emulator",
                "args": 
                [
                    "-avd",
                    "@Pixel_2_API_29"
                ]
            }
        ],
    

    Or

        "dart.flutterCustomEmulators": 
        [
            {
                "id": "Pixel_2_API_29",
                "name": "Pixel 2 API 29",
                "env": "QT_QPA_PLATFORM=xcb _JAVA_AWT_WM_NONREPARENTING=1 /home/gusbemacbe/Android/SDK/emulator/emulator -avd @Pixel_2_API_29"
            }
        ],
    
  9. gusbemacbe commented on Jun 22, 2021

    @gusbemacbe

    I was able to run QT_QPA_PLATFORM=xcb _JAVA_AWT_WM_NONREPARENTING=1 flutter emulators --launch Pixel_2_API_29 from command line in terminal, and pressed F5 to launch my project to the emulator.

  10. DanTup commented on Jun 22, 2021

    @DanTup
    Member

    @gusbemacbe you need to put them in the env key, something like this:

    "dart.flutterCustomEmulators": [
    	{
    		"id": "Pixel_2_API_29",
    		"name": "Pixel 2 API 29",
    		"executable": "/home/gusbemacbe/Android/SDK/emulator/emulator",
    		"args": [
    			"-avd",
    			"@Pixel_2_API_29"
    		],
    		"env": {
    			"QT_QPA_PLATFORM": "xcb",
    			"_JAVA_AWT_WM_NONREPARENTING": "1"
    		}
    	}
    ],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in flutterRelates to running Flutter appsis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions