![由于 libGL,Android 模拟器无法在 Linux 上运行](https://linux22.com/image/1153466/%E7%94%B1%E4%BA%8E%20libGL%EF%BC%8CAndroid%20%E6%A8%A1%E6%8B%9F%E5%99%A8%E6%97%A0%E6%B3%95%E5%9C%A8%20Linux%20%E4%B8%8A%E8%BF%90%E8%A1%8C.png)
我使用过几个 Linux 发行版(Ubuntu、Deepin 等),目前使用的是 KDE Neon 用户版。当我想使用 Android 模拟器时,却无法使用。因为 Android 模拟器并非在所有 Linux 发行版上都可运行。 信息:我的输出:
user@username-PC:~/Android/Sdk/tools$ ./emulator -accel-check
accel:
0
KVM (version 12) is installed and usable.
accel
user@username-PC:~/Android/Sdk/tools$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
user@username-PC:~/Android/Sdk/tools$ egrep -c '(vmx|svm)' /proc/cpuinfo
4
当我启动 Android 模拟器时,出现以下错误:
emulator: WARNING: Not all modern X86 virtualization features supported, which introduces problems with slowdown when running Android on multicore vCPUs. Setting AVD to run with 1 vCPU core only.
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: 58
Current serial number in output stream: 59
当我将多核 CPU 设置设为 1 时:
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: 58
Current serial number in output stream: 59
答案1
使用系统 libstdc++ 解决了这个问题
例如:
cd ~/Android/Sdk/tools
./emulator -avd Nexus_5X_API_27 -use-system-libs
如果工作正常,请在中设置以下变量~/.bashrc
:
export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1
重新登录或source ~.bashrc
。然后您可以省略该-use-system-libs
选项:
./emulator -avd Nexus_5X_API_27
从 Android Studio 调用模拟器时,此方法不起作用。以下是解决方法
android-studio.sh
在您的可用目录中创建一个 shell 脚本PATH
。例如,~/bin
其内容如下:
#!/bin/bash
export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1
~/Programs/android-studio/bin/studio.sh %f
然后更新启动器命令
~/.local/share/applications/jetbrains-studio.desktop
指向~/bin/android-studio.sh
。