Developing mobile applications requires constant testing of the functionality of the code in real conditions, and not just in the emulator. Running the project Android Studio on a physical smartphone provides more accurate testing of performance, sensor operation and interaction with hardware. This process is critical to identifying bugs that may not appear in a virtual environment. In this article, we will look in detail at how to properly connect the device and set up the development environment for successful deployment.
Many novice developers are faced with the fact that the launch button remains inactive or the device simply does not appear in the list of available targets. Often the problem lies in the absence of drivers or incorrectly enabled debugging mode. Correctly setting up the USB connection and configuration ADB (Android Debug Bridge) is the foundation for further work. You will learn how to avoid common mistakes and speed up the process of building and installing an APK file.
Preparing a smartphone for debugging
The first step is to activate hidden features on your mobile device, which are disabled by default for security reasons. You need to go to the Settings menu and find the About Phone or Phone Details section. Here you should repeatedly click on the item Build number (Build Number) until the system notifies you that you have become a developer. Usually it takes from 7 to 10 clicks.
After the new item appears in the main settings menu, go to the “For Developers” or “System → For Developers” section. In this menu there is a switch USB debuggingthat must be activated. It is also recommended to enable the "Keep screen on" option to prevent the device from going to sleep during long testing sessions. This will prevent the connection from being broken at a critical moment.
When you first connect your phone to a computer running the development environment, a dialog box will appear on the smartphone screen asking for debugging permission.
⚠️ Attention: Always check the RSA key fingerprint displayed on the screen computer before clicking Allow on your phone. Confirming an unknown computer may create a vulnerability in the security of your device.Make sure you are on a secure network and trust the computer you are working from. If you accidentally click “Cancel”, simply unplug and reconnect the cable so that the request appears again.
Setting up a USB connection and drivers
The quality of the physical connection plays a decisive role in the stability of data transfer between the PC and the smartphone. Use the original USB cable that came with the device, as cheap alternatives often only support charging and do not have data lines. Connect the cable to a USB 3.0 or higher port on your computer's motherboard, avoiding the use of low-quality USB hubs and extenders.
Depending on your computer's operating system, additional steps may be required to recognize the device. Windows users often need to install universal Google USB Drivers via SDK Manager in Android Studio. In Linux, rules are usually required to be configured udev, and in macOS, drivers are installed automatically along with platform tools.
- 🔌 Check whether the device is detected in Device Manager (Windows) or through the command
lsusb(Linux/Mac). - 🔄 Try changing the USB port if the system does not see the connected gadget.
- 🛡️ Make sure that your antivirus or firewall is not blocking the connection to ADB.
If the computer sees the phone as a drive, but not as a debugging device, change the USB operating mode in the notification shade of the smartphone. Select File Transfer (MTP) or PTP mode as Charge Only mode blocks the transmission of debug commands. In some cases, switching between these modes helps the system reinitialize the connection with the correct drivers.
Android Studio and Gradle configuration
After physically connecting, you need to make sure that the development environment is correct configured to work with real hardware. Open the file build.gradle of your application and check the value minSdkVersion. It must be less than or equal to the version of Android installed on your phone. If the minimum SDK version is higher than the OS version on the device, the project will not be able to install.
In the Android Studio toolbar, find the drop-down list of devices next to the launch button (green triangle). Your device should appear there with its model name and API version. If the word “Offline” is displayed instead of the model name or the device is missing altogether, try restarting the debug server through the terminal. To do this, enter the command:
adb kill-server
adb start-server
It is also worth paying attention to the build settings Gradle. Make sure AndroidX support is enabled in the file if your project uses modern libraries. Sometimes clearing the build cache helps solve problems with the deployment process hanging. To do this, use the menu gradle.properties AndroidX support is enabled if your project uses modern libraries. Sometimes clearing the build cache helps solve problems with the deployment process hanging. To do this, use the menu File → Invalidate Caches / Restart and select the cleanup option.
What to do if Gradle freezes during the build?
A common cause of freezing is lack of RAM for the Gradle daemon. Try increasing the org.gradle.jvmargs parameter in the gradle.properties file by adding the line: org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m. Also check the stability of the Internet connection, as the builder may try to download missing dependencies.
The process of launching and installing the application
When all the preparatory steps are completed and the device is visible in the list, you can proceed to the actual launch. Press the button Run 'app' or use the hotkey Shift + F10. Android Studio will begin the process of compiling the code, packaging the assets, and signing the APK file. In the bottom panel of the window you will see a progress bar for completing tasks Gradle.
After successful assembly, the system will automatically transfer the package to the device and launch it. On the smartphone screen you will see a standard installation window or the app will open immediately if it has already been installed previously. In the window logs Logcat at this moment system messages from your application will begin to appear, which allows you to monitor its operation in real time.
| Status in Logcat | Description | Action |
|---|---|---|
ActivityManager |
The system registers the launch activity | Normal, can be ignored |
FATAL EXCEPTION |
Critical error that caused a crash | Examine the call stack (Stack Trace) |
Install |
Package installation process | Waiting for completion |
debug |
Debugging messages from the developer | Analysis of operating logic |
If the application is installed, but immediately closes (“crashes”), most likely the problem is in the code logic or lack of necessary permissions.
⚠️ Attention: On Android 6.0 and higher, dangerous permissions (camera, geolocation, contacts) must be requested at runtime, and not just written in the manifest. The absence of a request will cause the application to crash when accessing these functions.Carefully monitor the logs in the first seconds after launch to identify the cause of the failure.
☑️ Checklist before launch
Wireless debugging over Wi-Fi
To test applications that intensively use the USB port (for example, audio interfaces or specific controllers), or just for convenience, you can use wireless debugging. This feature is available in Android 11 and above without the need to use the command line for initial setup if you use the Android Studio interface. Make sure that your computer and phone are connected to the same Wi-Fi network.
In the “Developer Options” menu on your phone, find the “Wi-Fi Debugging” option and turn it on. Click on it to see the IP address and port to connect to. In Android Studio, go to Device Manager, select the "Physical" tab and click "Pair using Wi-Fi". Enter the pairing code that will appear on the smartphone screen.
After successful pairing, the device will appear in the list of available ones in the same way as with a wired connection. Wi-Fi transfer speeds are typically slower than USB 3.0, so installing an app for the first time may take longer. However, subsequent launches and code updates occur quickly enough for comfortable work.
Use wireless debugging only on trusted networks. Transmitting debugging information over open Wi-Fi networks in cafes or airports can lead to data interception by attackers.
Solving common problems
Despite careful preparation, developers are often faced with a situation where the device is displayed as “Unauthorized”. This means that the key fingerprint verification request was ignored or rejected. Unplug the cable, close the dialog box on your phone (if it's frozen), and plug the cable back in. If the window does not appear, try restarting your smartphone.
Another common problem is an error INSTALL_FAILED_VERSION_DOWNGRADE. It occurs if you try to install a version of an application with a lower version code (versionCode) than the one already installed on the phone. In this case, you need to either increase the version number in build.gradleor manually remove the application from the device before launching it again.
- 📉 The “Application not installed” error is often associated with incompatibility of the processor architecture (armeabi-v7a vs arm64-v8a).
- ⏳ A long build may indicate the need to allocate more memory for the JVM in the IDE settings.
- 🔋 It is normal for the phone to drain quickly during debugging, since the screen is constantly active and the processor operates at high frequencies.
Sometimes anti-virus software on the computer blocks the work ADB, considering it a suspicious app. Add the folder with the installed Android SDK and the process itself adb.exe to the exceptions of your antivirus. This will avoid sudden connection breaks while working.
Most connection problems can be solved by simply replacing the USB cable with a high-quality original accessory and restarting the ADB server.
Why doesn't Android Studio see my phone, although it is charging?
Most likely, you are using a cable that Supports only power transfer, not data. Replace the cable with an original or certified one. Also check if the file transfer mode (MTP) is selected in the phone’s notification shade, and not “Charge only”.
Can you run the application on several phones at the same time?
Yes, Android Studio allows you to select multiple devices in the Select Deployment Target window. When you click the Run button, the application will be installed and launched on all marked devices in parallel, which is convenient for cross-device testing.
What is ADB and why do you need it?
ADB (Android Debug Bridge) is a universal command line tool that allows your computer to communicate with an Android device. It makes it easy to install applications, transfer files, and run various shell commands for debugging.
How to disable USB debugging after work?
For security, it is recommended to disable this function. Go to Settings → Developer Options and turn the USB Debugging switch to Off. You can also completely disable the developer menu by toggling the main toggle switch at the top of this section.