使 Android 模拟器运行得更快

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2662650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:49:21  来源:igfitidea点击:

Making the Android emulator run faster

androidperformancetestingandroid-emulatoremulation

提问by hpique

The Android emulator is a bit sluggish. For some devices, like the Motorola Droid and the Nexus One, the app runs faster in the actual device than the emulator. This is a problem when testing games and visual effects.

Android 模拟器有点迟钝。对于某些设备,例如摩托罗拉 Droid 和 Nexus One,该应用程序在实际设备中的运行速度比在模拟器中要快。这是测试游戏和视觉效果时的问题。

How do you make the emulator run as fast as possible? I've been toying with its parameters but haven't found a configuration that shows a noticeable improvement yet.

你如何让模拟器运行得尽可能快?我一直在玩弄它的参数,但还没有找到显示出明显改进的配置。

采纳答案by Gennadiy Ryabkin

Official web page

官方网页

~50% faster

约快 50%

Windows:

视窗:

  • Install "Intel x86 Emulator Accelerator (HAXM)" => SDK-Manager/Extras
  • Install "Intel x86 Atom System Images" => SDK-Manager/Android 2.3.3
  • Go to the Android SDK root folder and navigate to extras\intel\Hardware_Accelerated_Execution_Manager. Execute file IntelHaxm.exe to install. (in Android Studio you can navigate to: Settings -> Android SDK -> SDK Tools -> Intel x86 Emulator Accelerator (HAXM installer))

  • Create AVD with "Intel atom x86" CPU/ABI

  • Run emulator and check in console that HAXM running (open a Command Prompt window and execute the command: sc query intelhaxm)
  • 安装“Intel x86 Emulator Accelerator (HAXM)” => SDK-Manager/Extras
  • 安装“Intel x86 Atom System Images”=> SDK-Manager/Android 2.3.3
  • 转到 Android SDK 根文件夹并导航到 extras\intel\Hardware_Accelerated_Execution_Manager。执行文件 IntelHaxm.exe 进行安装。(在 Android Studio 中,您可以导航到:设置 -> Android SDK -> SDK 工具 -> Intel x86 Emulator Accelerator(HAXM 安装程序))

  • 使用“Intel atom x86”CPU/ABI 创建 AVD

  • 运行模拟器并检查运行 HAXM 的控制台(打开命令提示符窗口并执行命令:sc query intelhaxm)

enter image description here

在此处输入图片说明

Also don't forget install this one

也不要忘记安装这个

enter image description here

在此处输入图片说明

P.S. during AVD creation add emulation memory: Hardware/New/Device ram size/set up value 512 or more

PS 在 AVD 创建过程中添加仿真内存:Hardware/New/Device ram size/setup value 512 or more

Linux:

Linux:

  • Install KVM: open GOOGLE, write "kvm installation "
  • Create AVD with "Intel atom x86" CPU/ABI
  • Run from command line: emulator -avd avd_name -qemu -m 512 -enable-kvm
  • Or run from Eclipse: Run/Run Configurations/Tab "Target" - > check Intel x86 AVD and in "Additional Emulator Command Line Options" window add: -qemu -m 512 -enable-kvm (click Run)
  • 安装KVM:打开GOOGLE,写“kvm安装”
  • 使用“Intel atom x86”CPU/ABI 创建 AVD
  • 从命令行运行: emulator -avd avd_name -qemu -m 512 -enable-kvm
  • 或从 Eclipse 运行:运行/运行配置/选项卡“目标”-> 检查 Intel x86 AVD 并在“附加模拟器命令行选项”窗口中添加:-qemu -m 512 -enable-kvm(单击运行)

enter image description here

在此处输入图片说明

P.S. For Fedora, for Ubuntu

PS对于 Fedora对于 Ubuntu

OS-X:

OS-X:

  • In Android SDK Manager, install Intel x86 Atom System Image
  • In Android SDK Manager, install Intel x86 Emulator Accelerator (HAXM)
  • In finder, go to the install location of the Intel Emulator Accelerator and install IntelHAXM (open the dmg and run the installation). You can find the location by placing your mouse over the Emulator Accelerator entry in the SDK Manager.
  • Create or update an AVD and specify Intel Atom x86 as the CPU. Intel x86 Emulator Accelerator (HAXM) showing Location
  • 在 Android SDK Manager 中,安装 Intel x86 Atom System Image
  • 在 Android SDK Manager 中,安装 Intel x86 Emulator Accelerator (HAXM)
  • 在 finder 中,转到 Intel Emulator Accelerator 的安装位置并安装 IntelHAXM(打开 dmg 并运行安装)。您可以通过将鼠标放在 SDK 管理器中的 Emulator Accelerator 条目上来找到该位置。
  • 创建或更新 AVD 并将 Intel Atom x86 指定为 CPU。 显示位置的英特尔 x86 仿真器加速器 (HAXM)

P.S: Check this tool, very convenient even trial

PS:勾选这个工具,试用也很方便

回答by mcohen75

UPDATE: Now that an Intel x86 image is available, the best answer is by zest above.

更新:既然英特尔 x86 映像可用,最好的答案是上面的热情。

As CommonsWare has correctly pointed out, the emulator is slow because it emulates an ARM CPU, which requires translation to Intel opcodes. This virtualization chews up CPU.

正如 CommonsWare 正确指出的那样,模拟器很慢,因为它模拟 ARM CPU,这需要转换为 Intel 操作码。这种虚拟化会消耗 CPU。

To make the emulator faster, you have to give it more CPU. Start with a fast CPU or upgrade if you can.

为了让模拟器更快,你必须给它更多的 CPU。如果可以,从快速 CPU 或升级开始。

Then, give the emulator more of the CPU you have:

然后,为模拟器提供更多您拥有的 CPU:

  1. Disable Hyperthreading- Since the emulator doesn't appear to utilize more than one core, hyperthreading actually reduces the amount of overall CPU time the emulator will get. Disabling HT will slow down apps that take advantage of multiple CPUs. Hyperthreading must be disabled in your BIOS.
  2. Make the emulator run on a CPU other than CPU 0- This has a much smaller impact than turning off HT, but it helps some. On Windows, you can specify which CPU a process will run on. Many apps will chew up CPU 0, and by default the emulator runs on CPU 0. I change the emulator to run on the last one. Note that on OS X you cannot set affinity (see: https://superuser.com/questions/149312/how-to-set-processor-affinity-on-a-mac).
  1. 禁用超线程- 由于模拟器似乎不会使用多个内核,因此超线程实际上减少了模拟器将获得的整体 CPU 时间。禁用 HT 会降低利用多个 CPU 的应用程序的速度。必须在 BIOS 中禁用超线程。
  2. 使模拟器在 CPU 0 以外的 CPU 上运行- 这比关闭 HT 的影响要小得多,但对某些人有帮助。在 Windows 上,您可以指定进程将在哪个 CPU 上运行。许多应用程序会占用 CPU 0,并且默认情况下仿真器在 CPU 0 上运行。我将仿真器更改为在最后一个上运行。请注意,在 OS X 上,您无法设置关联(请参阅:https: //superuser.com/questions/149312/how-to-set-processor-affinity-on-a-mac)。

I'm seeing somewhere around a 50% improvementwith these two changes in place.

通过这两个更改,我看到了大约 50% 的改进

To set processor affinity on Windows 7:

在 Windows 7 上设置处理器关联:

  1. Open Task Manager
  2. Click View All Processes (to run as administrator, otherwise you can't set processor affinity)
  3. Right click on emulator.exe and choose Set Affinity...
  4. On the Set Affinity dialog, select just the last CPU
  1. 打开任务管理器
  2. 单击查看所有进程(以管理员身份运行,否则无法设置处理器关联)
  3. 右键单击 emulator.exe 并选择 Set Affinity...
  4. 在 Set Affinity 对话框中,只选择最后一个 CPU

Note: When you change affinity in this way, it's only changed for the lifetime of the process. Next start, you have to do it again.

注意:当您以这种方式更改关联时,它只会在进程的生命周期内更改。下一次开始,你必须再做一次。

enter image description here

在此处输入图片说明

回答by Paul Lammertsma

I would like to suggest giving Genymotiona spin. It runs in Oracle's VirtualBox, and will legitimately hit 60 fps on a moderate system.

我想建议给Genymotion一个旋转。它在 Oracle 的 VirtualBox 中运行,并且在中等系统上合法地达到 60 fps。

Here's a screencap from one of my workshops, running on a low-end 2012 model MacBook Air:

这是我的一个工作室的屏幕截图,在 2012 年低端型号的 MacBook Air 上运行:

Nexus 7 emulator running at 56.6 fps

Nexus 7 模拟器以 56.6 fps 运行

If you can't read the text, it's a Nexus 7 emulator running at 56.6 fps. The additional (big!) bonus is that Google Play and Google Play Services come packaged with the virtual machines.

如果您看不懂文字,那是 Nexus 7 模拟器,运行速度为 56.6 fps。额外的(大!)好处是 Google Play 和 Google Play 服务与虚拟机一起打包。

(The source of the demoed animation can be found here.)

(演示动画的来源可以在这里找到。)

回答by John Lehmann

Enable GPU Hardware Acceleration(in addition to Intel's HAXM), if you are using API 15 v3 or newer and SDK Tools v17+. Graphics acceleration for the emulator takes advantage of your development computer's graphics hardware, specifically its graphics processing unit (GPU), to make screen drawing faster. This gives a noticeable boost in speed.

如果您使用 API 15 v3 或更新版本和 SDK Tools v17+,请启用GPU 硬件加速(除了 Intel 的 HAXM)。模拟器的图形加速利用开发计算机的图形硬件,特别是其图形处理单元 (GPU),使屏幕绘制速度更快。这显着提高了速度。

To enable graphics acceleration enabled by default on your emulator: when creating the AVD, in the Hardware section, click New, select GPU emulation and set the value to Yes.

要在模拟器上默认启用图形加速:创建 AVD 时,在硬件部分,单击新建,选择 GPU 模拟并将值设置为是。

To enable acceleration only at runtime: use the -gpu flag while starting the emulator like this:

要仅在运行时启用加速:在启动模拟器使用 -gpu 标志,如下所示:

emulator -avd <avd_name> -gpu on

Source: Google's Using the Emulator tutorial.

来源:Google 的使用模拟器教程

回答by ThomasW

EditAlthough using the Intel images gets some performance gains, the performance gained by using Genymotion is much greater. See Paul Lammertsma's answer.

编辑虽然使用 Intel 映像获得了一些性能提升,但使用 Genymotion 获得的性能要大得多。请参阅Paul Lammertsma 的回答

Previous Answer

上一个答案

With ADT rev 17 the emulator supports running x86 system images in virtualization mode on Windows and Mac OS X. This has a noticeable impact on performance.

在 ADT rev 17 中,模拟器支持在 Windows 和 Mac OS X 上以虚拟化模式运行 x86 系统映像。这对性能有显着影响。

ADT rev 17 notes: http://android-developers.blogspot.jp/2012/03/updated-sdk-tools-and-adt-revision-17.html

ADT 修订版 17 注释:http: //android-developers.blogspot.jp/2012/03/updated-sdk-tools-and-adt-revision-17.html

Configuring Virtual Machine Acceleration: http://developer.android.com/guide/developing/devices/emulator.html#accel-vm

配置虚拟机加速:http: //developer.android.com/guide/developing/devices/emulator.html#accel-vm

回答by TripleG

I recently switched from a core 2 @ 2.5 with 3gb of ram to an i7 @ 1.73 with 8gb ram (both systems ran Ubuntu 10.10) and the emulator runs at least twice as fast now. Throwing more hardware at it certainly does help.

我最近从带有 3gb ram 的 core 2 @ 2.5 切换到带有 8gb ram 的 i7 @ 1.73(两个系统都运行 Ubuntu 10.10),现在模拟器的运行速度至少是原来的两倍。投入更多的硬件确实有帮助。

回答by sonicboom

Just wanted to say that after I installed the Intel HAXM accelerator and use the Intel Atom image the emulator seems to run 50 times faster. The difference is amazing, check it out!

只是想说,在我安装了 Intel HAXM 加速器并使用 Intel Atom 映像后,模拟器的运行速度似乎提高了 50 倍。差别是惊人的,看看吧!

http://www.developer.com/ws/android/development-tools/haxm-speeds-up-the-android-emulator.html

http://www.developer.com/ws/android/development-tools/haxm-speeds-up-the-android-emulator.html

回答by Joe P

I noticed that the emulator defaults to only Core 0, where most Windows applications will default to "any" core. Also, if you put it on another core (like the last core), it may make the emulator go crazy. If you can, you can try putting your heavy-CPU usage applications on the other CPU cores for a boost in speed.

我注意到模拟器默认只有核心 0,大多数 Windows 应用程序默认为“任何”核心。另外,如果你把它放在另一个核心上(比如最后一个核心),它可能会让模拟器发疯。如果可以,您可以尝试将 CPU 使用率高的应用程序放在其他 CPU 内核上以提高速度。

Hardware-wise, get the fastest CPU you can get that works for single-core applications. More than 2 cores might not experience a huge difference in terms of emulator performance.

在硬件方面,获得适用于单核应用程序的最快 CPU。超过 2 个内核在模拟器性能方面可能不会出现巨大差异。

Eclipse + the Android emulator together eat up a ton of RAM. I would recommend 3 gigs of RAM at least because I used a system with 2 gigs of RAM, and it slowed down because the system ran out of RAM and started to use the page file.

Eclipse + Android 模拟器一起吃掉了大量的 RAM。我建议至少使用 3 gig 的 RAM,因为我使用的系统具有 2 gig 的 RAM,并且由于系统耗尽 RAM 并开始使用页面文件而速度变慢。

I feel that the best CPUs for it will probably have a high clock (only use clock as a measure for CPUs in the same series btw), handle non-SIMD operations well, and have a turbo boost mechanism. There aren't many Java-based benchmarks, but overall look for application benchmarks like compression and office. Don't look at gaming or media since those are affected greatly by SIMD. If you find a Java one, even better.

我觉得最适合它的 CPU 可能会有一个高时钟(顺便说一句,只使用时钟作为衡量同系列 CPU 的指标),很好地处理非 SIMD 操作,并具有涡轮增压机制。没有很多基于 Java 的基准测试,但总体上寻找诸如压缩和办公之类的应用程序基准测试。不要看游戏或媒体,因为它们受 SIMD 的影响很大。如果你找到一个Java,那就更好了。

回答by Cesar

On this year google I/O (2011), Google demonstrated a faster emulator. The problem is not so much on the byte code between ARM and x86 but the software rendering performed by QEMU. They bypass the rendering of QEMU and send the rendering directly to an X server I believe. They showed a car game with really good performace and fps.

在今年的 google I/O (2011) 上,Google 展示了一个更快的模拟器。问题不在于 ARM 和 x86 之间的字节码,而在于 QEMU 执行的软件渲染。他们绕过 QEMU 的渲染并将渲染直接发送到我相信的 X 服务器。他们展示了一款性能和fps非常好的汽车游戏。

I wonder when that will be available for developers...

我想知道什么时候可以为开发人员提供...

回答by Koc

Google recently announced a new emulator for Android. It's a much faster and better than the old one. You can find more info about it here.

谷歌最近宣布了一个新的安卓模拟器。它比旧的更快更好。您可以在此处找到有关它的更多信息。