Testing Applications with Android Studio: Development Mode and Virtual Machine

Android Studio is the most complete programming IDE for developing applications for the Google operating system. In it we can find all the libraries, a complete help for the creation of code and even all kinds of tools, such as debugging or compilation, that will help us to give the final touches to our programs. Before publishing an application in the Google Play Store, it is necessary to check that it works correctly. And this is how we can do it thanks to this IDE.

What do we need to test an Android app

The essential thing, obviously, is to have the latest version of Android Studio installed on the computer, regardless of the method we are going to use to compile and test the application.

Testing Applications with Android Studio

If we are going to test it on a physical Android device (a mobile, a tablet, etc.) it is very important that it is relatively new (since, if it is old and not updated, it may not work depending on the SDK that we have configured) and that is updated to a modern version of Android. Surely many of us have a mobile with Android Ginger or Ice Cream at home. These, of course, are not recommended at all. We also need to have a USB cable to connect the phone to the computer, and, from the developer options, enable “USB debugging”. We may need to install the manufacturer’s OEM drivers for it to work.

On the other hand, if we are going to use the Android emulator included in Android Studio , then we do not need a physical smartphone, but our computer must meet certain requirements. Ideally, you should have 8GB of RAM, 4GB of hard drive space, and an Intel i3 processor, or better, or AMD equivalent. It will also be necessary to have an Internet connection, since from it we will download the Android images for the virtual machines and other necessary packages.

Test and debug applications with Android Studio

Next, we are going to see how we can test Android applications from Android Studio, both on a real mobile and in the virtual machine that we can create thanks to its included emulator.

Compile the app directly on a smartphone

If we have a new mobile, this is the best debugging method we can choose. Thanks to it, we can get a very precise idea of how the application is going to work on a real smartphone, something difficult to know in the virtual machines that we can create.

This is possible thanks to the Android Debug Bridge , a kind of tunnel through which a computer can communicate with Android in developer mode. In order to carry out this practice, it is necessary to activate the developer options of our phone. As each interface is different, it is difficult to indicate the exact steps to carry out this task, but, broadly speaking, what we must do is:

  • Activate the developer options (hidden by default) by clicking 5 times on the Android build number.
  • Go to Developer Options and enable USB Debugging .
  • Connect the smartphone by cable to the computer.
  • Install ADB drivers (if applicable) from our manufacturer. These we can download from here .

Activar depuración USB en el móvil

Once the previous steps have been carried out, we can check if the mobile is correctly connected to the PC. To do this, we must go to the Android Studio installation directory, inside the android_sdk / platform-tools folder, open a CMD window and execute the following command: adb devices . If the mobile is connected in debugging mode, it will appear in the list.

Since Android 11, the operating system supports Android Debug Bridge over Wi-Fi. If we want to save the USB cable (something that, on the other hand, is an advantage) we must activate the wireless debugging option from the Android Developer Options. Now, from the Android SDK, we will execute the following commands to link the mobile to the PC, changing ipaddr: port for the corresponding IP and port. When you ask us for a PIN, it will appear on your mobile, and we will enter it anyway.

  • adb pair ipaddr: port
  • adb connect ipaddr: port

If the wireless connection gives us problems, then we should better use USB debugging.

Create a virtual machine with the Android Studio emulator

The Android Studio emulator, which is included by default with the IDE, will allow us to test our applications on many devices and versions of Android at the same time. Instead of having many telephones at home or in the office, each configured in a different way, we can do it all thanks to these virtual machines.

To create our own Android virtual machine, the first thing we must do is open Android Studio (and update, if we have something pending) and open, within the Tools menu, the ADV Manager section.

Android Studio - Depurar app - 1

If we have virtual machines created, they will appear in the new window that will open. Otherwise, we will see a button to start the wizard to create the new Android virtual machine.

Android Studio - Depurar app - 2

The first thing that we must indicate to the program is the type of device that we are going to emulate. We can choose between TV, Smartphone, Tablet, WearOS (watch) or car.

Android Studio - Depurar app - 3

We can choose any of the smartphones that are already created as standard, with their own specifications (size, screen, memory, etc.) or we can create our own smartphone with the specifications that we want.

In the next step we can choose the version of Android that we want our virtual machine to have. In addition to the name, and the version to which it corresponds, we can also see the API level to which it corresponds. This is important since an app with API 30 (for example) will not work in versions prior to Android 11. But, the other way around, it will. If we do not have the Android image downloaded, we can download it in this same step.

Android Studio - Depurar app - 6

We give the name that we want to the VM, we check that the settings are correct, and that’s it. Clicking on “Finish” will create the virtual machine.

Android Studio - Depurar app - 7

Our virtual mobile already appears in the AVD Manager list. And, to run the virtual machine, we simply have to click on the Play button that appears to its right. After a few seconds, the Android will be up and running.

Android Studio - Depurar app - 8