Ubuntu 18.04 下配置 HAXM 加速 Android模拟器

最近在vmware环境下搭建ubuntu18.04开发环境,开始发现总是运行android模拟器在console提示加载如下错误信息:

Emulator: emulator: ERROR: x86 emulation currently requires hardware acceleration,

开始排除虚拟机是否开启虚化,android studio的extras包是否安装,还有platform-tools,build-tools这些工具包是否完整安装在sdk目录下这些原因,最后参考如下文章成功解决了这个问题,现在记录如下:

本来以为要下载安装程序,结果发现是通过配置KVM来实现的,废话少说,附上原文,由于国内经常被和谐,因此复制原文还是有必要的。

原文地址 http://software.intel.com/en-us/blogs/2012/03/12/how-to-start-intel-hardware-assisted-virtualization-hypervisor-on-linux-to-speed-up-intel-android-x86-gingerbread-emulator

How to Start Intel Hardware-assisted Virtualization (hypervisor) on Linux to Speed-up Intel Android x86 Gingerbread Emulator

Submitted by Tao Wang (Intel) onMon, 03/12/2012 - 22:31

The Intel Hardware Accelerated Execution Manager (Intel® HAXM) is a hardware-assisted virtualization engine (hypervisor) that uses Intel Virtualization Technology (VT) to speed up Android app emulation on a host machine. In combination with Android x86 emulator images provided by Intel and the official Android SDK Manager, HAXM allows for faster Android emulation on Intel VT enabled systems. HAXM for both Windows and IOS are available now.

Since Google mainly support Android build on Linux platform (with Ubuntu 64-bit OS as top Linux platform, and IOS as 2nd), and a lot of Android Developers are using AVD on Eclipse hosted by a Linux system, it is very critical that Android developers take advantage of Intel hardware-assisted KVM virtualization for Linux just like HAXM for Windows and IOS.

Below are the quick step-by-step's on how to install, enable KVM  on Ubuntu host platform and  start Intel Android x86 Gingerbread emulator with Intel hardware-assisted virtualization (hypervisor). The result is very pleasing and AVD runs significantly faster and smoother than without hypervisor

KVM Installation

I referred the instructions from Ubuntu community documentation page.to get KVM installed.To see if your processor supports hardware virtualization, you can review the output from this command:

 
 
 
 
 
 

Shell

 
$ egrep -c '(vmx|svm)' /proc/cpuinfo
1
$ egrep -c '(vmx|svm)' /proc/cpuinfo

I got 64. If 0 it means that your CPU doesn't support hardware virtualization.

Next is to install CPU checker:

 
 
$sudo apt-get install cpu-checker
1
$sudo apt-get install cpu-checker

Now you can check if your cpu supports kvm:

 
 
 
 
 
 

Shell

 
$kvm -ok

If you see:
"INFO: Your CPU supports KVM extensions
INFO: /dev/kvm exists
KVM acceleration can be used"

1
2
3
4
5
6
$kvm -ok
 
If you see:
"INFO: Your CPU supports KVM extensions
INFO: /dev/kvm exists
KVM acceleration can be used"

It means you can  run your virtual machine faster with the KVM extensions.

If you see:
"INFO: KVM is disabled by your BIOS
HINT: Enter your BIOS setup and enable Virtualization Technology (VT),
and then hard poweroff/poweron your system
KVM acceleration can NOT be used"

You need to go to BIOS setup and enable the VT.

Use a 64 bit kernel

Running a 64 bit kernel on the host operating system is recommended but not required.
To serve more than 2GB of RAM for your VMs, you must use a 64-bit kernel (see 32bit_and_64bit). On a 32-bit kernel install, you'll be limited to 2GB RAM at maximum for a given VM.
Also, a 64-bit system can host both 32-bit and 64-bit guests. A 32-bit system can only host 32-bit guests.
To see if your processor is 64-bit, you can run this command:

 
 
$egrep -c ' lm ' /proc/cpuinfo
1
$egrep -c ' lm ' /proc/cpuinfo

If 0 is printed, it means that your CPU is not 64-bit.

If 1 or higher, it is. Note: lm stands for Long Mode which equates to a 64-bit CPU.
Now see if your running kernel is 64-bit, just issue the following command:

 
 
 
 
 
 

Shell

 
$uname -m
 
 

x86_64 indicates a running 64-bit kernel. If you see i386, i486, i586 or i686, you're running a 32-bit kernel.

Install KVM

For Ubuntu Lucid (10.04) or later:

 
 
 
 
 
 

Shell

 $sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
1
 

You may ignore the Postfix Configuration below by selecting "No Configuration"

Next is to add your <username> account to the group kvm and libvirtd

 
 
 
 
 
 

Shell

$sudo adduser your_user_name kvm
$sudo adduser your_user_name libvirtd
这个libvirtd应该是原作者书写错误,测试改成libvirt就可以了,因为查看系统所有用户组没有libvirtd用户组,只有libvirt用户组
 
 

After the installation, you need to relogin so that your user account becomes an effective member of kvm and libvirtd user groups. The members of this group can run virtual machines.

Verify Installation
You can test if your install has been successful with the following command:

 
 
 
 
 
 

Shell

 
1
2
3
4
$sudo virsh -c qemu:///system list
Your screen will paint the following below if successful:
Id Name                 State
----------------------------------

Start the AVD from Android SDK Directly from Terminal

Now start the Android for x86 Intel Emulator using  the following command:

 
 
 
 
 
 

Shell

 
1
$<SDK directory>/tools/emulator-x86 -avd Your_AVD_Name -qemu -m 2047 -enable-kvm

Only a 64-bits Ubuntu can allow you to run allocated Memory of 2G or more. My 64-bit Ubuntu has 6G of Memory, so I used 1/3 of it for Android AVD. My AVD name is Intel_Atom_gingerbread_2.3 . '-qemu' provides the options to qemu, and '-m' specifies the amount of memory for the emulated Android (i.e. guest). If you use too small value for that, it's possible that performance is bad because of frequent swapping activities. Add '-show-kernel' to see the message from the kernel.

Start the AVD by AVD Manager in Eclipse

Below is procedures recommended by Google. If you are running the emulator from Eclipse, run your Android application with an x86-based AVD and include the KVM options:

    • In Eclipse, click your Android project folder and then select Run > Run Configurations...
    • In the left panel of the Run Configurations dialog, select your Android project run configuration or create a new configuration.
    • Click the Target tab.
    • Select the x86-based AVD you created previously.
    • In the Additional Emulator Command Line Options field, enter:

       
       
       
       
       
       

      Shell

       
      -qemu -m 2047 -enable-kvm
      1
      -qemu -m 2047 -enable-kvm

  • Run your Android project using this run configuration.

Ubuntu 18.04 下配置 HAXM 加速 Android模拟器的更多相关文章

  1. ubuntu 18.04下 配置qt opencv的坑

    问题和过程描述: 我按照网上的教程装了qt5.8版本,然后去配置opencv,感觉一切顺利,然后随便写了个 Mat src = imread("xxx") 然后imshow发现编译 ...

  2. Ubuntu 18.04 下 emscripten SDK 的安装

    Ubuntu 18.04 下 emscripten SDK 的安装http://kripken.github.io/emscripten-site/docs/getting_started/downl ...

  3. Ubuntu 18.04安装配置Apache Ant

    Ubuntu 18.04安装配置Apache Ant 文章目录 Ubuntu 18.04安装配置Apache Ant 下载 执行以下命令 `/etc/profile`中配置环境变量 载入配置 测试 执 ...

  4. Ubuntu 18.04 安装配置 go 语言

    Ubuntu 18.04 安装配置 go 语言 1.下载 下载 jdk 到 Downloands 文件夹下 cd 进入 /usr/local, 创建 go 文件夹, 然后 cd 进这个文件夹 cd / ...

  5. Ubuntu 18.04下安装Steam顶级在线游戏平台

    Ubuntu 18.04下安装Steam顶级在线游戏平台 原创: 聆听世界的鱼 Linux公社 今天 Steam是由Valve公司开发的顶级在线游戏平台,是目前全球最大的综合性数字发行平台之一.它让你 ...

  6. 在Ubuntu 18.04 下安装mysql,没有初始密码,重设root密码

    在Ubuntu 18.04 下安装mysql 不知道是由于mysql更新为新版还是.Ubuntu18.04中的特性,安装过程中没有设置密码的环节,在网络上找了半天,总算解决了!特此记录下来,以便以后查 ...

  7. ubuntu 18.04下Chromium设置为系统代理

    前言 在ubuntu 18.04下挂上ss后firefox能直接上google了但是chromium上不去 会出现下面两种情况 # This site can't be reached xxxxxx ...

  8. Ubuntu 18.04 美化配置

    网上很多关于Ubuntu 18.04 美化的配置,但每个人遇见的问题都有些不太一样, 现将本人配置的过程整理如下 更新源为阿里云 找到Software & Updates,将源更新为阿里云的源 ...

  9. Ubuntu 18.04 安装配置LAMP

    --作者:飞翔的小胖猪 --创建时间:2021年5月29日 --修改时间:2021年5月29日 一.准备 1.1 环境 操作系统:Ubuntu 18.04 网页引擎:Apache php版本:7.4 ...

随机推荐

  1. Nagios服务器端配置文件详解

    Nagios服务器端安装部署详解见:http://www.cnblogs.com/ginvip/p/6505948.html Nagios 主要用于监控一台或者多台本地主机及远程的各种信息,包括本机资 ...

  2. Helm二:安装

    目录 Helm安装 Helm client安装 Helm tiller安装 Chart仓库配置 私有chart仓库 chart仓库的组成 创建本地仓库 chart仓库基本管理 Helm安装 Helm ...

  3. Hadoop生态圈-Azkaban实战之Command类型执行指定脚本

    Hadoop生态圈-Azkaban实战之Command类型执行指定脚本 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 1>.服务端测试代码(别忘记添加权限哟!) [yinzh ...

  4. 流媒体技术学习笔记之(四)解决问题video.js 播放m3u8格式的文件,根据官方的文档添加videojs-contrib-hls也不行的原因解决了

    源码地址:https://github.com/Tinywan/PHP_Experience 总结: 说明: 测试环境:本测试全部来自阿里云直播和OSS存储点播以及本地服务器直播和点播 播放器:Vid ...

  5. 用matplotlib制作的比较满意的蜡烛图

    用matplotlib制作的比较满意的蜡烛图 2D图形制作包, 功能强大, 习练了很久, 终于搞定了一个比较满意的脚本. 特点: 使用方面要非常简单 绘制出来的图要非常的满意, 具有如下的特点 时间和 ...

  6. html5 canvas旋转

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. 20155230 2016-2017-2 《Java程序设计》第五周学习总结

    20155230 2016-2017-2 <Java程序设计>第五周学习总结 教材学习内容总结 1.错误处理通常称为异常处理. 2.catch括号中列出的异常不得有继承关系,否则会发生编译 ...

  8. iOS常用小功能

    CHENYILONG Blog 常用小功能 技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong  ...

  9. shift 用法

    shift  shift命令用于对参数的移动 (左移),通常用于在不知道传入参数个数的情况下依次遍历每个参数然后进行相应处理(常见于Linux中各种程序的启动脚本). 示例 1  示例 依次读取输入的 ...

  10. ajax函数说明

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...