【转】android开发中关于模拟器emulation的常见问题

【转】android开发中关于模拟器emulation的常见问题

Trouble:

	无法启动android模拟器,提示

	XDM authorization key matches an existing client!
	SDL init failure, reason is: No available video device

Oneway:

	打开电脑的 Terminal 终端,
	以当前图形界面用户的身份执行命令
	
	xhost localhost
	
	即可,如果想实现登录后自动执行这个命令,可以做以下操作
	点开 Applicantions Menu -> Settings -> Session and Startup
	在打开的选项中点击 Application Autostart
	然后点击左下方的 Add 按钮,
	设置Name的值为:xhost localhost
	设置Description的值为:xhost localhost
	设置Command的值为:xhost localhost
	点击OK,点击Close,即可

Trouble:

	无法启动android模拟器,提示

	emulator: ERROR: x86 emulation currently requires hardware acceleration!
	Please ensure KVM is properly installed and usable.
	CPU acceleration status: This user doesn't have permissions to use KVM (/dev/kvm).
	
	或者提示
	emulator: ERROR: x86 emulation currently requires hardware acceleration!
	Please ensure KVM is properly installed and usable.
	CPU acceleration status: Could not open /dev/kvm :Permission denied

Oneway:

	使用 root 权限执行以下三条命令后注销当前用户或者直接重启电脑即可
	(本例子中当前登录图形界面的用户是 sman)
	
	groupadd kvm
	usermod -G kvm -a sman
	echo 'KERNEL=="kvm",GROUP="kvm",MODE="0660"' >> /etc/udev/rules.d/androidUseKVM.rules 
	
	这三条命令的作用分别是:
	#创建用户组kvm
	#将用户sman添加到kvm用户组
	#开机时自动赋予用户组kvm拥有0660的权限

Trouble:

	无法启动android模拟器,提示
	
	Android/Sdk/tools/emulator -netdelay none -netspeed full -avd Nexus_5_API_23
	
	libGL error: failed to load driver: i965
	libGL error: Try again with LIBGL_DEBUG=verbose for more details.

	failed to create drawable
	getGLES1ExtensionString: Could not create GLES 1.x Pbuffer!
	Failed to obtain GLES 1.x extensions string!
	Could not initialize emulated framebuffer

Oneway:

	根据提示在Terminal中申明环境变量并在Terminal中启动模拟器

	export LIBGL_DEBUG=verbose; Android/Sdk/tools/emulator -netdelay none -netspeed full -avd Nexus_5_API_23

	得到提示:

	libGL: OpenDriver: trying /usr/lib64/xorg/modules/dri/i965_dri.so
	libGL error: failed to open drm device: Permission denied
	libGL error: failed to load driver: i965
	libGL: OpenDriver: trying /usr/lib64/xorg/modules/dri/swrast_dri.so
	libGL: OpenDriver: trying /usr/lib64/xorg/modules/dri/i965_dri.so
	libGL error: failed to open drm device: Permission denied
	libGL error: failed to load driver: i965
	libGL: OpenDriver: trying /usr/lib64/xorg/modules/dri/swrast_dri.so
	failed to create drawable
	getGLES1ExtensionString: Could not create GLES 1.x Pbuffer!
	Failed to obtain GLES 1.x extensions string!
	Could not initialize emulated framebufferSegmentation fault


	先解决第一个错误,第一个错误是没有权限使用drm设备
	于是使用groups命令检查当前用户是否存在于video用户组
	[sman@mnxnm:~]$ groups
	users plugdev vboxusers kvm
	可以看到sman不属于video用户组

	于是使用root权限将当前用户sman添加到video用户组
	root@mnxnm:~# usermod -G video -a sman

	注销当前用户再重新登录(必须重新登录,否则用户组改动不会生效)
	登录后确认sman是否成功加入video用户组
	[sman@mnxnm:~]$ groups
	users video plugdev vboxusers kvm
	可以看到sman成功加入video用户组

	再启动Android studio,再通过Android Virtual Device Manager启动模拟器
	看看错误有没有消除
	如果提示NAND: could not write file /tmp/android-sman/emulator-7UY28S, File exists
	则 rm /tmp/android-sman/emulator-* 后再试

	OK,成功启动模拟器

Trouble:

	android模拟器中DNS解析正常但无法ping通外网

Oneway:

	这是正常现象,因为模拟器与PC之间的网络通信是通过TCP端口转发来实现的
	而ping是ICMP数据包,没有端口,故模拟器无法将ping请求送出
	但是是可以正常浏览网页的
	
	所以不能用ping来测试模拟器是否能够联网,而是用网页浏览器来测试

Trouble:

	android模拟器中安装调试apk时出错,提示
	
	Application Installation Failed
	Installation failed with message INSTALL_FAILED_CONTAINER_ERROR.
	It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.

	WARNING: Uninstalling will remove the application data!

	Do you want to uninstall the existing application?

Oneway:

	方法一:adb root
		adb shell rm /mnt/secure/asec/smdl*

	方法二:将项目源文件 AndroidManifest.xml 中的
		android:installLocation="preferExternal"
		修改成
		android:installLocation="auto"
		即可

 

posted @ 2016-04-02 16:20  yixing98  阅读(4536)  评论(0编辑  收藏  举报