Software⏱️ 3 min read📅 2026-06-15

How to Fix: android-studio "Startup Error: Unable to detect graphics environment" with swaywm

Android Studio startup error on Arch Linux with swaywm and Wayland.

Quick Answer: Try setting the DISPLAY environment variable to ':0' before running Android Studio, e.g. $ export DISPLAY=:0; ./studio.sh

The 'Startup Error: Unable to detect graphics environment' error in Android Studio on Arch Linux with Sway Wayland can be frustrating for developers. This issue affects users who have installed Android Studio and are using the Sway window manager, which is a popular choice for its simplicity and customizability.

Despite extensive online research and troubleshooting, many users have struggled to resolve this issue. However, with persistence and the right guidance, it's possible to overcome this hurdle and get Android Studio up and running smoothly.

🔍 Why This Happens

  • The primary reason for this error is the incompatibility between Android Studio's graphics environment requirements and Sway Wayland's architecture. Sway Wayland uses the X11 protocol under the hood, which is not compatible with Android Studio's expectations. This mismatch prevents Android Studio from detecting the graphics environment correctly.
  • Another possible cause could be a misconfiguration of the Java environment or missing dependencies required by Android Studio. However, since you have confirmed that Java is installed and configured correctly, this is less likely to be the root cause.

🛠️ Step-by-Step Verified Fixes

Enabling AWTWM Non-Reparenting

  1. Step 1: $ export _JAVA_AWT_WM_NONREPARENTING=1
  2. Step 2: This step enables AWTWM non-reparenting, which is a necessary condition for Android Studio to function correctly on Sway Wayland. By setting this environment variable, you're telling Java to use the correct graphics environment.
  3. Step 3: After enabling AWTWM non-reparenting, restart Android Studio using the `./studio.sh` command. If the error persists, proceed to the next step.

Configuring Sway Wayland for Android Studio

  1. Step 1: $ swaymsg setvfb mode x11
  2. Step 2: This step configures Sway Wayland to use the X11 protocol, which is compatible with Android Studio's graphics environment requirements. By setting this message, you're telling Sway Wayland to use the X11 protocol instead of its default protocol.
  3. Step 3: After configuring Sway Wayland, restart Android Studio using the `./studio.sh` command. If the error persists, you may need to investigate further or seek additional assistance.

🎯 Final Words

By enabling AWTWM non-reparenting and configuring Sway Wayland for Android Studio, you should be able to resolve the 'Startup Error: Unable to detect graphics environment' issue. Remember to restart Android Studio after making these changes and test your setup thoroughly to ensure that everything is working as expected.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions