平台
Ubuntu14.04 64
现象
在AndrodStudio中点击模拟器的启动按钮后,模拟器界面弹出后,又立刻闪退。
解决
一、查看模拟器的信息
从上面可以看到模拟器的存放路径以及名称:
路径:/home/pengdonglin/.android/avd/4_WVGA_Nexus_S_API_24.avd
名称:4_WVGA_Nexus_S_API_24
架构:x86_64
二、命令行运行模拟器
在androidsdk的路径下面运行下面的命令:
./emulator/qemu/linux-x86_64/qemu-system-x86_64 -avd 4_WVGA_Nexus_S_API_24
此时出现了错误:
emulator: WARNING: encryption is off
WARNING: The Mesa software renderer is deprecated. Use Swiftshader (-gpu swiftshader) for software rendering.
failed to create drawable
getGLES2ExtensionString: Could not create GLES .x Pbuffer!
Failed to obtain GLES .x extensions string!
Could not initialize emulated framebuffer
warning: host doesn't support requested feature: CPUID.80000001H:ECX.sse4a [bit 6]
warning: host doesn't support requested feature: CPUID.80000001H:ECX.sse4a [bit 6]
warning: host doesn't support requested feature: CPUID.80000001H:ECX.sse4a [bit 6]
warning: host doesn't support requested feature: CPUID.80000001H:ECX.sse4a [bit 6]
emulator: emulator window was out of view and was recentered emulator: ERROR: Could not initialize OpenglES emulation, use '-gpu off' to disable it.
从提示中有两种解决办法:
1、设置 -gpu swiftshader
2、设置 -gpu off
在运行模拟器的时候,加入上面任意一个,都可以解决问题,但是最终我们并不是从命令行运行模拟器,所以我们得把这上面的配置写到模拟器的启动配置文件中。
从模拟器的配置信息看:
这里已经设置了软件GLES 2.0,所以这里就需要在配置文件中修改模拟器的配置了,配置文件的路径:
~/.android/avd/4_WVGA_Nexus_S_API_24.avd/config.ini
下面是这个文件中关于GPU的配置:
hw.gps=yes
hw.gpu.enabled=yes
hw.gpu.mode=mesa
解决方法1:
hw.gpu.enabled=no
hw.gpu.mode=mesa
解决方法2:
hw.gpu.enabled=yes
hw.gpu.mode=swiftshader
使用上面的任意一个,模拟器都可以运行:
完。