Perfecto's Remote Device Access feature provides the ability to debug Android mobile apps on real devices under realistic conditions. This speeds the process of validating new features and fixing bugs that only show up under specific environments or conditions.

 

Watch the video above, or follow the step-by-step below to debug an app...


Prerequisites

  1. Install Android Studio
    https://developer.android.com/studio/index.html
  2. Install Perfecto plugin for Android Studio
    http://developers.perfectomobile.com/display/PD/Android+Studio
  3. Download sample app (.apk)
    https://github.com/PerfectoCode/AndroidDemoApp

Download the app as .zip file and extract it.

Debug native android screen

Debug an App on a Mobile Device

1. Open the android-calculator-master app project.

2. Click the ‘Launch Mobile’ icon in the Perfecto Android Studio plugin toolbar.

Debug native android screen 2

3. Select an Android device and click “open”

Debug native android screen 3

 

 

 

 

 

 

 

 

 

 

4. Switch to the Widgets menu and click the ‘DevTunnel’ widget.

Debug native android screen 4

 

 

 

 

 

 

 

 

 

 

 

5. If you have not done so already, download and install the DevTunnel installer. Wait for the installation to complete.

Debug native android screen 5

 

 

 

 

 

6. Click the ‘Start Dev Tunnel Session’ step to establish a direct connection to the device.

Debug native android screen 6

 

 

 

 

 

 

 

7. Open the application code file, here it is in the file MainActivity.java

Debug native android screen 7

8. Set the breakpoints in the code where you suspect that there are problems.

Debug native android screen 8

9. While Android Studio is focused on the app code, click on the Debug icon.

Debug native android screen 9

10. Select the Android device you opened from the Perfecto cloud plugin that appears in the Select Deployment Target window and click ‘OK’ to launch the application in debug mode on the device.

Debug native android screen 10

11. After Gradle build is successful, note that Android Studio utilizes ADB commands against the device to copy .apk resources to the device, and launch the app in debug mode.

Debug native android screen 11

12. Interactively, exercise the application and activate the suspicious interface elements. In this case, it is the input field of the “Split Number”. Enter a number, then delete it, and the application crashes with an Exception.

Debug native android screen 12
Debug native android screen 13
Debug native android screen 14

13. When we enter ‘3’ into the field – the debugger stops at the breakpoint, stepping through the method shows that it works fine.

Debug native android screen 15

14. Now, we delete the ‘3’ in the field. The debugger again stops at the breakpoint. And we examine the variable values.

Debug native android screen 16

15. Performing a “step over (F8)” command causes the application to crash. So, we know that we need to analyze and understand what is causing the crash. 

16. The problem seems to be with the call to “Integer.parseInt(s.toString())” when the string is an empty string (as noted above). So, we change the code to check for this occurrence:

Debug native android screen 17

17. Rerun the app with the debugger and note that it works as planned even when the “input” is empty.

18. When finished, click the ‘Disconnect’ button from the Perfecto Widgets frame to close your DevTunnel session.

Debug native android screen 18

 

 

 

 

19. Click the ‘X’ on the device window to release the mobile device.

Debug native android screen 19

 

 

 

Congratulations! You now know how to debug an app when you connect a real, cloud-based mobile device from the Perfecto Lab into your IDE. Try it out with the next feature you’re building or run some of your own tests on different devices to see if your apps pass with flying colors on other platforms.