Perfecto DevTunnel 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.
- Install Android Studio
- Install Perfecto plugin for Android Studio
- Download sample app (.apk) - https://github.com/PerfectoCode/AndroidDemoApp
Download the app as .zip file and extract it.
Debug on a Mobile Device
- Open the android-calculator-master app project.
- Click the ‘Launch Mobile’ icon in the Perfecto Android Studio plugin toolbar
- Select an Android device and click “open”
- Switch to the Widgets menu and click the ‘DevTunnel’ widget
- If you have not done so already, download and install the DevTunnel installer. Wait for the installation to complete.
- Click the ‘Start Dev Tunnel Session’ step to establish a direct connection to the device
- Open the application code file, here it is in the file MainActivity.java
- Set the breakpoints in the code where you suspect that there are problems.
- While Android Studio is focused on the app code, Click on the Debug icon
- 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.
- 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.
- 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.
- When we enter ‘3’ into the field – the debugger stops at the breakpoint, stepping through the method shows that it works fine
- Now, we delete the ‘3’ in the field. The debugger again stops at the breakpoint. And we examine the variable values.
- 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.
- 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:
- Rerun the app with the debugger and note that it works as planned even when the “input” is empty.
- When finished, click the ‘Disconnect’ button from the Perfecto Widgets frame to close your DevTunnel session
- Click the ‘X’ on the device window to release the mobile device
Congratulations! You now know how to 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.