Deadolus / android-studio-docker

Android Studio + flutter in Docker. Emulator works too - with or without Display, even over SSH if you forward the display
Apache License 2.0
131 stars 53 forks source link

can't connect to X11 (Ubuntu 22.04.3 LTS) #16

Open Utopiah opened 6 months ago

Utopiah commented 6 months ago
Failed to initialize graphics environment

java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.

(base) utopiah@r15-desktop4090:~/Prototypes/android-studio-docker$ echo $DISPLAY
:0

with in compose.yml having

       # Mount the proper locationm for x11 server if you are running this in native linux
      - /tmp/.X11-unix:/tmp/.X11-unix .
      - android_studio:/androidstudio-data
    environment:
      - DISPLAY=:0 # Set DISPLAY environment variable
Utopiah commented 6 months ago

Same error on Ubuntu 23.10

Utopiah commented 6 months ago

I tried xhost + or adding in $HOME/.bash_profile

JAVA_OPTIONS=-Djava.awt.headless=true
export JAVA_OPTIONS

but same result.

Deadolus commented 6 months ago

The error tells you that you can't connect to the display server. Usually, the server listens on :0, but this could also be some other variable. What does your shell (not inside docker!) DISPLAY environment variable say?

Utopiah commented 6 months ago

That's what I thought which is why I shared

echo $DISPLAY
:0

isn't it matching?

Utopiah commented 6 months ago

Not sure if it makes a difference in that case but I run docker here as a user, not as root.

Deadolus commented 6 months ago

Not sure if it makes a difference in that case but I run docker here as a user, not as root.

That should not make a difference. Make sure you are running x11, not wayland mabe? Maybe some problem with your .xauthority file not allowing access to the x11 server? Sorry can't help here, I am also no display server expert.

Utopiah commented 6 months ago

Seems so :

fabien@fabien-CORSAIR-ONE-i160:~$ echo $XDG_SESSION_TYPE
x11

No worries I'll investigate https://stackoverflow.com/questions/44429394/x11-forwarding-of-a-gui-app-running-in-docker and report here!

mihalycsaba commented 3 months ago

@Utopiah I assume you use wayland try running this in the terminal 'xhost + local:' works on gnome

@Deadolus maybe this can be added in the run.sh for wayland?