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

摘要:
在Ubuntu 18.04下配置HAXM以加速Android模拟器。最近,ubuntu18.04开发环境是在vmware环境下构建的。它开始发现Android模拟器始终在运行,并且在控制台提示符处加载了以下错误消息:emulator:模拟器:错误:x86simulationcurrentlyrequireshardwareacceleration。它开始排除是否为虚拟机启用了虚拟化
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
 
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:

 
 
1
$sudo apt-get install cpu-checker

Now you can check if your cpu supports kvm:

 
 
 
 
 
 
Shell
 
1
2
3
4
5
6
$kvm-ok
 
Ifyou 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:

 
 
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
 
 
 

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
 $sudoapt-getinstall 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
$sudoadduser your_user_name kvm
$sudoadduser 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
$sudovirsh-cqemu:///system list
Your screen will paint the following below ifsuccessful:
IdName                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-m2047-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
       
      1
      -qemu-m2047-enable-kvm
  • Run your Android project using this run configuration.

免责声明:文章转载自《Ubuntu 18.04 下配置 HAXM 加速 Android模拟器》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇linux命令--mvRestControllerAdvice注解无效问题下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

kali linux 入门(1) 基于win10和docker的环境搭建

1. 前言 渗透测试并没有一个标准的定义。国外一些安全组织达成共识的通用说法是,渗透测试是通过模拟恶意黑客的攻击方法,来评估计算机网络系统安全的一种评估方法,这个过程包括对系统的任何弱点、技术缺陷或漏洞的主动分析。这个分析是从一个攻击者可能存在的位置来进行的,并且从这个位置有条件主动利用安全漏洞。 渗透测试与其他评估方法不同。通常的评估方法是根据已知信息...

mac终端下ssh虚拟机中的linux提示WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

重新装了虚拟机中的Linux系统后,在mac下ssh就连不上虚拟机了   localhost:~ zhouqian$ ssh root@172.17.9.19 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @    WARNING: REMOTE HOST IDENTIFICATI...

记linux下使用create_ap 创建热点失败及解决(涉及rfkill)

先介绍一下 create_ap. 这是一个在linux中创建热点用的脚本, 托管在github中, https://github.com/oblique/create_ap/ 正文开始: 习惯了windows下点点鼠标就能创建wifi热点的方式, 面对linux 的cli有种两眼一抹黑的感觉. 幸好偶然得知了 create_ap 这个脚本, 创建热点只要一...

会话、进程组与僵死进程

  1.   终端       在Linux系统中,用户通过终端登录系统后得到一个Shell进程,这个终端成为Shell进程的控制终端(Controlling Terminal),Shell进程启动的其他进程的控制终端也是这个终端。默认情况下(没有重定向),每个进程的标准输入、标准输出和标准错误输出都指向控制终端,进程从标准输入读也就是读用户的键盘输入,进...

内核移植和文件系统制作(2):linux内核最小系统和initramfs文件系统

linux内核最小系统,使用内核版本:https://www.kernel.org/pub/linux/kernel/v3.0/linux-3.8.1.tar.bz2 1,FL2440板子的基本硬件:晶振12MHZ CPU 型号为S3C2440,基于ARM920T,指令集ARMV4,时钟主频400MHz SDRAM H57V2562GTR-75...

Linux 系统中堆栈的使用方法

本节内容概要描述了Linux内核从开机引导到系统正常运行过程中对堆栈的使用方式。这部分内容的说明与内核代码关系比较密切,可以先跳过。在开始阅读相应代码时再回来仔细研究。 Linux 0.12系统中共使用了4种堆栈。第1种是系统引导初始化时临时使用的堆栈;第2种是进入保护模式之后提供内核程序初始化使用的堆栈,位于内核代码地址空间固定位置处。该堆栈也是后来任务...