Android Testing Environment Cheatsheet (Part 1)

Environment

Genymotion and Android emulators cannot run within a VM.
Instead, this setup can help contain all the tools you need:
– Install Genymotion on your host OS.
– Install your android tools on a Kali VM to keep it portable.
– Connect to your android apps running in Genymotion from the Kali VM.

Note:
– Using an Ubuntu host here.
– Using Virtualbox here to create Kali VM but could be any VM platform.
– Genymotion requires Virtualbox to be installed for its emulation.
– Genymotion must be run natively on your host.
– If you prefer not to use a VM to store all your tools, just install everything on your host instead.

Configure the Kali VM

Install Virtualbox:
$ sudo apt-get install virtualbox

For the following steps, it is assumed Kali is installed in a Virtualbox VM. Tip: pressing the right control keyboard button releases your mouse from Virtualbox.

Install Virtualbox guest addons
apt-get update
apt-get install -y virtualbox-guest-x11
reboot

Create android test user
useradd -m android
passwd android
usermod -a -G sudo android
chsh -s /bin/bash android
logout

Install Android Studio
Download from android.com.
Unpack:
unzip android-studio-ide-*.zip
Run first time to install:
~/tools/android-studio/bin/studio.sh

Add Android Studio to your PATH/.profile:
$ PATH="$PATH:/home/android/tools/android-studio

Note: The command line android SDK tools (e.g. adb) are stored in:
~/Android/Sdk/platform-tools

Add Android SDK tools to your PATH/.profile:
$PATH="$PATH:/home/android/Android/Sdk/tools/:/home/android/Android/Sdk/platform-tools/:/home/android/Android/Sdk/build-tools/2.4.0.3/"

Configure network interfaces
In the Virtualbox network settings for the Kali VM, for Adapter 1, choose Host-only Adapter (vboxnet0).
This will allow the VM and the Genymotion VM to talk to each other over ADB.
In the same network settings window, enable Adapter 2 for NAT
Adapter 1 will allow connections to Genymotion, while Adapter 2 will allow internet.
Reboot the Kali VM and run
$ sudo ifconfig
If the second adapter does not have an IP address run:
$ dhclient -r eth1
$ dhclient eth1

You should now have an internet connection on your Kali VM.

Install Genymotion on host

Create a Genymotion account at genymotion.com.
Download Genymotion.
If your host is Windows, download Genymotion & Virtualbox as a package.
If your host is Linux/Mac, ensure you have Virtualbox installed already.

Install Genymotion
chmod u+x genymotion-*.bin
./genymotion-2.8.0-linux_x64.bin
The installer will ask you to setup a virtual device.
Sign in using your created Genymotion account to complete this step.
Select your target device e.g. Google Nexus 4.
Once the download has completed and installed, the new virtual device will be listed.

Configuring Genymotion

In Genymotion Settings, ADB tab, deselect the Genymotion Android tools (default), just choose custom Android SDR tools and leave it blank (this avoids the device is “offline” errors when connecting with adb from a VM).
Choose Start to launch the virtual device.
The network settings for Genymotion can be left as default (these are configured in the Virtualbox settings rather than in the Genymotion settings and should be left as Host-only Adapter vboxnet0).
In the same network settings window, enable Adapter 2 for NAT
Adapter 1 will allow connections from the Kali VM, while Adapter 2 will allow internet in Genymotion.
If you have Virtualbox installed on your host the device should start.
Click “No” for the question “Do you want to specify the Android SDK location?”.

Connecting to Genymotion

Here, we will connect to Genymotion from our Kali VM:
$ adb devices
$ adb connect 192.168.56.101 (the IP of your Genymotion emulator, when you mouse over it it should be in title of the window)
$ adb devices (should now see the listed connected device)
$ adb shell

Now your Kali VM is ready to install all the essential android testing tools and can connect to a Genymotion emulator. Having all your android testing tools in a VM allows moving of the VM to different computers, backing up and can save lots of setup time.

Leave a Reply

Your email address will not be published. Required fields are marked *