Thứ Hai, 15 tháng 2, 2016

[Android] Hướng dẫn sử dụng GenyMotion để tạo Android Virtual Device test

Giới thiệu: GenyMotion là một công cụ giả lập Android, mà bạn có thể sử dụng nó để test các apps của mình, cũng như trải nghiệm android trên PC của mình. Nó có thể giả lập các thiết bị thật như là Google Nexus, Samsung Galaxy, ... Hoạt động rất nhanh, đơn giản, và mượt mà như máy thật. Bạn cũng có thể sử dụng Full Screen Size mode để có cảm nhận như chạy Android trên màn hình desktop, và bạn cũng dễ dàng copy-paste hay drag-drop file vào máy ảo này. Bạn cũng có thể giả lập các tính năng về GPS, wifi internet ở thời gian thực.
Cá nhân tôi, ngoài chuyện test app trong quá trình development, tôi còn dùng nó để chơi game nữa. Bạn có thể trao đổi thêm nếu bạn muốn tìm hiểu cách chơi game bằng GenyMotion này :)

Dưới đây là chi tiết hướng dẫn cách cài đặt và sử dụng GenyMotion.

Cài đặt

First of all you will need to create a Account on Genymotion Website. Go to this link and create an account.

1) Sign up for an account on the Genymotion Website
2) Install VirtualBox 5.0, a powerful free virtualization software for Genymotion to run.
3) Download Genymotion Emulator v2.5.2 or higher for your platform. Note: There is an incompatibility issue with Genymotion v2.5.1 for VirtualBox 4.3.28 and higher versions.
4) Install the Genymotion Emulator
- Windows: Run the MSI installer
- Mac: Open the dmg and drag both apps to Applications directory
5) Go to the Genymotion ADB settings and set the path to your SDK directory (i.e. for Mac OSX, the directory is /Users/[username]/Library/Android/sdk. For Windows, all SDK files should be by default in C:\Documents and Settings\\AppData\Local\Android\sdk)

6) (PC's only) You need to reboot and enable Intel Virtualization Technology or Intel VT-x on the BIOS. Typically you need to reboot and hit F1, Esc, or F10 to enter this mode. See these instructions for more information.

7) Install the Genymotion plugin for Android Studio. Go to Preferences->Plugins and click Browse repositories. Search for Genymotion and you should find one provided by

After restarting, go to Preferences->Genymotion and setup the location of the Genymotion app.


Run the Genymotion application
Sign in and add your first virtual device (i.e. Nexus 4 - 4.4.4 - API 19, Nexus 4 - 5.0.0. - API 21).
You must use an image running 4.3, 4.4.4, or 5.0.0. Other versions may not work.
Do not start your emulator yet!
From within Android Studio, click the genymobile icon Genymobile and click "Start" on your virtual device.
You can start the emulator through the Android Studio plugin, or can launch the Genymotion application separately.
Wait for device to boot up into a useable state
Note: On Ubuntu/Linux, make sure to 3D acceleration mode by launching VirtualBox and going to Settings -> Display to fix. VirtualBox appears to prone to memory leaks, so you may find yourself killing the process from time to time. To avoid large CPU consumption by the compiz window manager and swapping in general, try increasing the video memory allocation and Base Memory (found in Settings -> System).

Note: Are you getting an error when starting the emulator? Error Failed to load VMMR0.r0? Follow the advice here. In short, go to virtual box page and download and install VirtualBox 4.3.6 Oracle VM VirtualBox Extension Pack.

Note: If you get Failed to load OVI error when re-adding the emulator, you need to use a new name for the same device. For example, "Nexus 4 - 4.4.4 - API 19" might be called "Nexus 4 - 4.4.4 - API 19 New".

Setup Google Play Services

1) The Google Play APK package needed is specific to the Android emulator version. You must use the corresponding Google Play Service package. Otherwise, you may notice problems with Google Play not having Internet connectivity or other strange issues.

Version APK Link
Android 5.0
Google Play Services APK - requires Genymotion 2.4.0+
Android 4.4.4 Google Play Services APK
Android 4.3 Google Play Services APK

2) Drag and drop the zip file onto the running Genymotion emulator device

3) When asked to flash the device, make sure to proceed with the installation.

At this point, 'Google Apps Services' will crash frequently with the message "google play services has stopped working".
You must close and restart the emulator so that Google Play Store can be installed.

4) After restart, open the "Play Store" app on your emulator and sign in with a google account.

If you can't find Google Play, try updating the Google Hangouts app to trigger an update to the Play Store.

5) Android 5.0.0 only: If you are using Android 5.0.0, you will be prompted to update to the latest version of Google+ app. In addition, make sure to upgrade to at least Genymotion 2.4.0 (there appears to be issues with Genymotion 2.3.1).

6) Make sure to update to the latest version of Google Play Services by opening the "Play Store" app and then the "Maps" app to verify play services is running correctly.

Note: After installed google play if you have got problem like no connection, you need to be carefull to install right version that will match emulator version. For example Android 4.3 is API 18. If you install Samsung Galaxy S4 API 18 - 1080 x 1920 for genymotion emulator and install Google Services APK for Android 4.3, google play will work without any issue. The important point is google play API version and genymotion emulator device version.

Enable GPS on Emulator

Next, if you don't have the emulator started yet, be sure to boot the genymotion emulator from within the Android Studio plugin:

Now we need to enable the GPS location on the emulator by manually selecting a location on the map: