Computer

Test your apps created with Android Studio in real time

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 that we are going to use to compile and test the application.

If we are going to test it in a physical Android device (a mobile phone, 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 it 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 StudioSo we don’t need a physical smartphone, but our computer does have to 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 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 work, 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 the Developer options and activate the USB debugging.
  • Connect the smartphone by cable to the computer.
  • Install ADB drivers (if applicable) from our manufacturer. These we can download from here.

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 option of wireless debugging from the Developer options from Android. 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 section ADV Manager.

Android Studio - Debug 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 - Debug 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 - Debug 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 android version 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 - Debug 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 - Debug App - 7

Our virtual mobile already appears within 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 - Debug App - 8

Related Articles

Leave a Reply

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