Android Studio AVD Emulator Startup Failure: Analysis and Solutions for libGL and libstdc++ Errors

Dec 07, 2025 · Programming · 10 views · 7.8

Keywords: Android Studio | AVD Emulator | libGL Error | libstdc++ | Linux Ubuntu

Abstract: This article provides an in-depth analysis of libGL and libstdc++ related errors encountered when starting the Android Studio AVD emulator on Linux systems, particularly the "Process finished with exit code 1" issue. By examining key error log information, such as libGL's inability to load drivers vmwgfx_dri.so and swrast_dri.so, and BadValue errors in X Error, the article systematically explores the root causes. Based on best practices and community-verified solutions, it details three main repair methods: modifying AVD graphics settings to software rendering, replacing the SDK's built-in libstdc++ library with the system version, and reinstalling the Android Emulator component. Each method includes specific operational steps and configuration examples to help developers quickly identify and resolve emulator startup issues.

Problem Background and Error Analysis

In Android development, using the Android Studio AVD (Android Virtual Device) emulator is a crucial step for testing applications. However, on Linux systems (such as Ubuntu 16.04 LTS 64-bit), developers often encounter emulator startup failures, with error logs showing “Process finished with exit code 1”. Specific error messages typically involve failures in loading libGL and libstdc++ libraries, for example:

libGL error: unable to load driver: vmwgfx_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: vmwgfx
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 155 (GLX)
Minor opcode of failed request: 24 (X_GLXCreateNewContext)
Value in failed request: 0x0

These errors indicate that the emulator is encountering obstacles when attempting to use OpenGL for graphics rendering. libGL is the library in Linux systems that handles OpenGL, and the errors point to vmwgfx and swrast drivers, corresponding to virtual machine and software rendering, respectively. When the system cannot load these drivers, the emulator fails to create a graphics context, causing the X server to return a BadValue error and ultimately terminating the process with exit code 1. The root cause is often related to incompatibilities with the libstdc++ library version bundled in the Android SDK or missing system libraries.

Core Solutions: Repair Methods Based on Best Practices

According to community verification and official documentation, the main methods to resolve this issue focus on adjusting graphics rendering settings or replacing library files. The following sections detail three effective solutions to help developers quickly restore emulator functionality.

Solution 1: Modify AVD Graphics Settings to Software Rendering

This is the most straightforward quick fix, suitable for most cases. By changing the AVD's graphics rendering mode from hardware acceleration to software rendering, libGL driver issues can be bypassed. The steps are as follows:

  1. Open Android Studio and navigate to the AVD Manager.
  2. Select the problematic AVD (e.g., Pixel 2 API 26) and click the Edit button.
  3. In Advanced Settings, find the “Emulated Performance Graphics” option.
  4. Change it from the default “Automatic” or “Hardware” to “Software”.
  5. Save the settings and restart the emulator.

This method is simple and effective but may sacrifice some graphics performance, making it suitable for development testing scenarios. If the problem persists, deeper library replacement solutions can be attempted.

Solution 2: Use System libstdc++ Library to Replace SDK Built-in Version

This solution addresses libstdc++ library incompatibility by forcing the emulator to use the system library instead of the SDK's built-in version. There are two implementation methods:

Method A: Start Emulator via Command Line with Parameters

When running the emulator directly in the terminal, add the -use-system-libs switch. For example, for an AVD named Nexus_5_API_23, the command is:

~/Android/Sdk/tools/emulator -avd Nexus_5_API_23 -use-system-libs

This parameter instructs the emulator to load the system's libstdc++.so.6 library instead of the version bundled in the Android SDK. This is based on a commit in the Android Open Source Project (e.g., commit 202063), aimed at resolving library loading conflicts. Ensure the system has the correct version of libstdc++ installed, typically via package managers (e.g., apt-get install libstdc++6).

Method B: Set Environment Variables

To automatically apply this fix within Android Studio, set the ANDROID_EMULATOR_USE_SYSTEM_LIBS environment variable. In Linux systems, edit the user configuration file (e.g., ~/.bashrc or ~/.profile) and add the following line:

export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1

Then run source ~/.bashrc to apply the changes. This ensures that the emulator uses the system library whether started via command line or Android Studio, improving compatibility.

Solution 3: Reinstall Android Emulator Component

If the above methods are ineffective, the Android Emulator component itself may be corrupted or outdated. Based on community suggestions, try reinstalling:

  1. In Android Studio, open the SDK Manager.
  2. Switch to the SDK Tools tab.
  3. Find Android Emulator, uncheck it, and apply to uninstall.
  4. Recheck it and apply to install the latest version.
  5. Restart Android Studio and test the emulator.

This helps fix potential file corruption or update to a more compatible version. Additionally, ensure system graphics drivers (e.g., Mesa) are updated to support OpenGL rendering.

Additional Recommendations and Other Potential Solutions

Beyond the main solutions, other answers provide additional insights. For example, one suggestion is to change the boot option to cold boot in AVD advanced settings, which can reset the emulator state and sometimes resolve temporary graphics issues. The path is: AVD Manager -> Edit -> Show Advanced Settings -> Boot Options, select Cold boot. Furthermore, checking system logs (e.g., dmesg or /var/log/Xorg.0.log) may offer more clues, such as graphics driver issues or permission errors.

In practice, it is recommended to try solutions in order: first modify graphics settings to software rendering, if the problem persists, use system library replacement, and finally consider reinstalling the component. For older systems like Ubuntu 16.04, ensure necessary graphics libraries are installed, such as libgl1-mesa-glx and libgl1-mesa-dri. If using a virtual machine (e.g., VMware), vmwgfx driver issues may require installing VMware Tools or adjusting VM settings to enable 3D acceleration.

Summary and Best Practices

Android Studio AVD emulator startup failures on Linux often stem from compatibility issues with libGL and libstdc++ libraries. By analyzing error logs, developers can quickly pinpoint graphics rendering or library loading failures. The solutions provided in this article are based on community verification and official resources, including modifying AVD settings, using system libraries, and reinstalling components. To prevent similar issues, it is advisable to keep the Android SDK and system libraries updated, and select compatible graphics options when creating AVDs. For persistent problems, refer to the Android Issue Tracker (e.g., issue 197254) for the latest fixes. Through systematic troubleshooting, developers can efficiently restore emulator functionality, ensuring a smooth Android application testing experience.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.