24

I have a Nexus 6P API23 emulator downloaded on my Ubuntu 15.10 PC. When I try to launch it, it fails and a dialog box pops up and says:

(AVD config: Nexus 6P API 23 x86 -- Hardware-GLES 2.0 Graphics)

Cannot launch AVD in emulator.
Output:
libGL error: unable to load driver: nouveau_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: nouveau
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  155 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  47
  Current serial number in output stream:  46
libGL error: unable to load driver: nouveau_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: nouveau
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  155 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  47
  Current serial number in output stream:  46
libGL error: unable to load driver: nouveau_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: nouveau
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
  Serial number of failed request:  33
  Current serial number in output stream:  34
QObject::~QObject: Timers cannot be stopped from another thread

I have tried other AVDs and they don't work.

Kevin Dixson
  • 419
  • 1
  • 4
  • 10

7 Answers7

53

you can also use "Software" in the Emulated Performance Graphics option, in the AVD settings

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
aoliva
  • 531
  • 3
  • 2
14

I've had the same error as you and have managed to find a workaround. Hopefully this will solve your issue as well.

Rather than launching the emulator from Android Studio, open the terminal and cd into the tools directory withing your Android SDK directory - mine is ~/Android/Sdk/tools. From there run the command:

LD_PRELOAD='/usr/$LIB/libstdc++.so.6' DISPLAY=:0 ./emulator -avd <insert avd name here>

You should now be able to launch your application with android studio by pressing the green run arrow and selecting the emulator you just started.

For more information as to why this works go here

Edit:

After some more thought, I tried this script and it seems to work, so that you can start the emulator within the Android Studio. It replaces emulator executable with a bash script that calls it as above. You'll need to change to tools path to the correct location. I'd also suggest making a backup copy of your tools directory in case something goes wrong:

#!/bin/bash

TOOLS_PATH='/home/user/Android/Sdk/tools'
UNEXPANDED_LIB='$LIB'

for emul in ${TOOLS_PATH}/em*
do
cp ${emul} ${emul}-orig
cat <<EOF > ${emul}
#!/bin/bash
LD_PRELOAD='/usr/$UNEXPANDED_LIB/libstdc++.so.6' ${emul}-orig "\$@"
EOF
done
Community
  • 1
  • 1
sapensadler
  • 386
  • 5
  • 11
  • I've created a Python script, which provides a really basic launcher using your fix: https://gist.github.com/NickGeek/1e125d7ca6aeff2d4e0e3ac2399bc14c – NStorm Apr 27 '16 at 07:07
  • 1
    1) be sure to update TOOLS_PATH to your own path. 2) keep that script outside the .../tools directory. 3) Run only once! (if run twice you will need to reinstall SDK tools), as files get replaced. You will need to execute it each time you update SDK tools (so keep that in mind) – lepe Nov 24 '16 at 02:43
7

My case: I work with Debian Jessie and Android Studio 2.2.3. My graphic card is an ATI Radeon HD 6850 by Sapphire.

The emulator says that there is a problem loading the graphic driver ("libGL error: unable to load driver: r600_dri.so"). As it is explained here, it seems that Google packaged with Android Studio an old version of one library (libstdc++.so.6), and the emulator fails when it tries to use the graphic card.

Solution? Very easy: to use the system libraries instead of the packaged in Android Studio. How? Adding "-use-system-libs" at the end of the command. So:

./emulator -avd EMULATOR_NAME -netspeed full -netdelay none -use-system-libs

The definitive solution (if you don't want to use the terminal) is to set the ANDROID_EMULATOR_USE_SYSTEM_LIBS environment variable to 1 for your user/system. With this change, when you run the emulator within Android Studio, it will also load the system libraries instead of the packaged.

PS - The easiest way I found to set the environment variable, it's to modify the script that launch the Android Studio (studio.sh, in my case it is inside /opt/android-stuido/bin), and add at the begining this:

export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1

UPDATE December 2017: I had the same problem with Debian Stretch and Android Studio 3.0.1 (same graphic card). The same solution works for me.

Pablo Insua
  • 852
  • 11
  • 19
1

Entering the following in the terminal (Ctrl-Alt-T) solved this for me:

cd $Android/Sdk/tools/lib64/libstdc++
mv libstdc++.so.6 libstdc++.so.6.bak
ln -s /usr/lib64/libstdc++.so.6

This apparently creates a symlink. This solution was taken from Line #23 of https://code.google.com/p/android/issues/detail?id=197254#c23.

You may need to change the paths to the files depending on your installation (i.e. the original used the path ANDROID_HOME/android-sdk-linux_x86/ whereas my installation was just Android/Sdk/).

Concrete_Buddha
  • 556
  • 4
  • 16
0

I had exactly the same problem on Ubuntu 16.04 LTS and Android Studio 2.3.2 and I solved the issue by doing the following in a terminal window: (NOTE: I saw this somewhere else on online but I can't remember where so I can't give credit where credit is due)

sudo apt list "*nvidia-[0-9][0-9][0-9]"

mine returned: nividia-346 nividia-352 nividia-361 nividia-367 nividia-375

I then ran the following for each that was returned:

sudo apt install nvidia-375
sudo apt install nvidia-367
sudo apt install nvidia-361
sudo apt install nvidia-352
sudo apt install nvidia-346

Then reboot Ubuntu and everything worked fine.

Preview
  • 35,317
  • 10
  • 92
  • 112
plowboy
  • 9
  • 1
  • I can confirm that using the Nvidia proprietary driver instead of the nouveau driver helps, but you don't have to install every Nvidia driver version available. Install only the latest version available for your hardware configuration, otherwise you might end up with a driver mess. – sfera Jun 08 '17 at 13:22
  • Warning: installing the latest Nvidia driver (nvidia-384) left my screen black after reboot, had to ssh in from another machine and uninstall this driver to be able to boot again normally (KDE neon 5.12.2 based on Ubuntu 16.04 LTS). – legolas108 Mar 02 '18 at 20:04
0

I was ubuntu 16.04 android studio 3 ,

ln -s $Android/Sdk/emulator/lib64/libstdc++/libstdc++.so.6.0  $Android/Sdk/tools/lib64/libstdc++ 

i found my libstdc++.so.6 in ~/Android/Sdk/emulator/lib64/libstdc++/,

but android studio will found ~/Android/Sdk/tools/lib64/libstdc++/

cheng Hc
  • 1
  • 2
0

On Debian Stretch (Android Studio 3.0.1 / Android Emulator 27.1.12) I experienced this same issue and applied the following fix:

sudo apt-get install libstdc++6:amd64
cd ~/Android/Sdk/emulator/lib64/libstdc++
mkdir old
mv libstdc* old
ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6
manimaul
  • 322
  • 3
  • 5