DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Tutorial: Setting up Android Devices for Testing Mobile Apps
HaramChoi for askui

Posted on • Updated on • Originally published at askui.com

Tutorial: Setting up Android Devices for Testing Mobile Apps

In this tutorial, we will walk you through how to set up an Android device for developing and testing mobile apps running on Android devices. Depending on the testing environment, i.e. whether it is a real Android device or an emulator, the procedure might slightly differ. But the overall process of the setup will be more or less the same.

If you want to prepare your Android development environment without using the Android Studio, then follow this post.

Requirements

  • Android Studio installed
  • (optional) Android device, if you want to run your app on a real device

1. Install Android SDK Command-line Tools

If you have the Android Studio installed, you have to verify if you have the Android SDK Command-line Tools and the Android SDK Platform-Tools installed. They both are packages containing several command line tools that are useful for developing apps for Android devices.

To verify the installation of them,

  • Click on the More Actions button, and then
  • Open the SDK Manager

more-action

  • Then, select Android SDK from the list on the left side of the window.
  • Go to the SDK Tools tab, and check the Android SDK Command-line Tools and the Android SDK Platform-Tools. After clicking the OK button, it will start to install the tools we have selected.

android-sdk-tools

2. Set up the Test Device

After installing the necessary tools in the Android Studio, we can start to set up the Android device that we want to use for the development.

Set up a Real Android Device

This part is for setting up a real Android device. If you want to use the Android Emulator instead, then you can skip it and go directly to the next step.

To use additional development features in an Android device, we need to enable the Developer Options within the device. To enable the Developer Options, tap the Build Number option 7 times. You can find this option in one of the following locations, depending on your Android version:

  • Android 9 (API level 28) and higher: Settings > About Phone > Build Number
  • Android 8.0.0 (API level 26) and Android 8.1.0 (API level 26): Settings > System > About Phone > Build Number
  • Android 7.1 (API level 25) and lower: Settings > About Phone > Build Number

After enabling the Developer Options, we can enable the USB debugging option. This option will allow the Android Studio and other SDK tools to recognize your Android device via USB. To enable USB debugging, toggle the USB debugging option in the Developer Options menu. You can find this option in one of the following locations, depending on your Android version:

  • Android 9 (API level 28) and higher: Settings > System > Advanced > Developer Options > USB debugging
  • Android 8.0.0 (API level 26) and Android 8.1.0 (API level 26): Settings > System > Developer Options > USB debugging
  • Android 7.1 (API level 25) and lower: Settings > Developer Options > USB debugging

Set up an Android Emulator

If you want to use the Android Emulator for testing purposes, we have to create a virtual device that runs in the emulator. After running the Android Studio,

  • Click on the More Actions button, and then
  • Open the Virtual Device Manager

If no virtual device is created, we can create one by clicking the Create device button on the top left corner of the Virtual Device Manager window.

You will now see the Virtual Device Configuration window. Within the configuration window, you will be asked to:

  • Choose a hardware profile
  • Choose a system image

virtual-device-configuration

The hardware profile represents the specification of the hardware that will be used as a virtual device. Various presets of Android devices e.g. Pixel or Nexus are provided. But you can also create your own hardware profile, after which you will be customizing parameters in such:

  • Screen size
  • Resolution
  • Using Hardware buttons (Back, Home, Menu, Volume, etc.)
  • Using On-device sensors (Accelerometer, Gyroscope, GPS)

After choosing a hardware profile, we will be choosing a system image for the Android device. Here we can choose out of a variety of Android images, from the latest Android 13 Tiramisu down to the Android 7 Nougat. If you have the Android studio freshly installed and haven't used it yet, then it will start to download the image after selecting one.

After finishing creating a new virtual device, we will be able to see our new device listed in the Device Manager. Click the device's play button(▢️) to run it.

device-created

3. Set up the ADBKeyboard

Until now, we have prepared our Android device and now we are ready to go for testing our Android app. But before we jump into the test phase, we will set up one more utility that will make the test procedure easier.

ADBKeyboard is a virtual keyboard that can be installed on Android devices. It enables us to type within the Android device by using command lines via adb.

One noticeable advantage of using ADBKeyboard is that it can also handle base64 encoding, which becomes handy if you want to type Unicode characters such as emojisπŸ”₯ For more details about this virtual keyboard, see here.

To install the ADBKeyboard on your device,

  1. Download the ADB-Keyboard package from this GitHub Repo (Important: Version 2.0)
  2. Unzip it.
  3. Find your device:

    # make sure that your Android device is connected.
    # in case of using the emulator, it should be running
    adb devices
    
  4. Install the ADBkeyboard on the device:

    # inside ADBKeyBoard-2.0/
    adb -s <your device id> install ADBKeyboard.apk
    
  5. Configure the ADB Keyboard:

    adb -s <your device id> shell settings put secure default_input_method com.android.adbkeyboard/.AdbIME
    
  6. Enable the ADB Keyboard:

    adb -s <your device id> shell ime enable com.android.adbkeyboard/.AdbIME
    
  7. To check if it is enabled:
    Click on a textfield in an app and see if the ADB Keyboard {ON} notification is shown at the bottom of the screen.

4. Done

We are finally done with the preparation for testing apps running on Android devices. In the next post, we will cover a simple test automation case utilizing askui on the device we set up in this article.

If you have a recurring or persisting issue while following this tutorial, don’t hesitate to ask the Discord community for help!

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.