Running and Debugging Android Applications
In this section
- Creating an Android Run/Debug Configuration
- Choosing the Target Device Manually
- Debugging with Logcat
- Managing Virtual Devices
On this page:
- Running or debugging an entire Android application
- Running or debugging a custom .apk that will be later embedded in an application
- Debugging an already running application
Note that you can also monitor an application behavior via the Android Device Monitor tool (to launch it, navigate to Tools | Android | Android Device Monitor).
Running or debugging an entire Android application
- Start creating an Android run/debug configuration.
- On the Run/Debug Configuration: Android page that opens, specify the configuration name and select the module to which this configuration will be applied.
-
Choose the Deploy default APK option in the Package area
and Launch default Activity in the Activity area.
IntelliJ IDEA will upload the
.apk
built from the module specified in the Module drop-down list above. The.apk
is built automatically, no preliminary artifact configuration is required from your side. -
Appoint the device where the application will run:
- To use a virtual device, select the Emulator option in the Target Device area, choose an emulator from the drop-down list or create a new one.
- To use a physical device, select the USB device option in the Target Device area and plug-in the device through a USB cable.
- Start running or debugging the target activity. If you have not specified a target device, choose it manually.
- View and analyze Android system messages in the Logcat tab of the Android tool window.
Running or debugging a custom .apk that will be later embedded in an application
-
Configure an artifact to generate the
.apk
from:- In the main menu, navigate to .
-
In the left-hand pane, click Artifacts. In the central pane, click the Add
button
in the toolbar.
- Select Android Application from the list of available artifact types and then select Empty from the context menu.
-
In the right-hand pane, add the artifact components. The artifact must contain all resources and code that want packaged in the
.apk
. For details, refer to Generating a Signed Release APK Through an Artifact and Configuring Artifacts.
- Start creating an Android run/debug configuration.
- On the Run/Debug Configuration: Android page that opens, specify the configuration name and select the module to which this configuration will be applied.
-
To run or debug a custom
.apk
, choose the Deploy custom artifact option in the Package area and select the artifact to build the.apk
from. In this case, you have to define the artifact manually before creating a run/debug configuration (see Generating a Signed Release APK Through an Artifact and Configuring Artifacts for details). Then select the Launch option in the Activity area and specify the start-up activity from the chosen artifact (.apk
). Type the activity name manually or click the Browse buttonand select it in the Select Activity Class dialog box that opens.
The list of available activities is determined by the choice of the module.
-
Appoint the device where the application will run:
- To use a virtual device, select the Emulator option in the Target Device area, choose an emulator from the drop-down list or create a new one.
- To use a physical device, select the USB device option in the Target Device area and plug-in the device through a USB cable.
- Start running or debugging the target activity. If you have not specified a target device, choose it manually.
- View and analyze Android system messages in the Logcat tab of the Android tool window.
Debugging an already running application
Apart from debugging an Android application by initiating a debugging session, you can apply the debugger to an already running application. You can do this in one of the following two ways:
- Attach the debugger to a running process:
-
Start a run/debug configuration without deploying a package and launching an activity
- Start creating an Android run/debug configuration. On the Run/Debug Configuration: Android page that opens, specify the configuration name and select the module to which this configuration will be applied.
- Select the Do not deploy anything option in the Package area and Do not launch Activity in the Activity area.
-
Appoint the device where the application will run:
- To use a virtual device, select the Emulator option in the Target Device area, choose an emulator from the drop-down list or create a new one.
- To use a physical device, select the USB device option in the Target Device area and plug-in the device through a USB cable.
- Start running or debugging the target activity. If you have not specified a target device, choose it manually.
- View and analyze Android system messages in the Logcat tab of the Android tool window.
See Also
Last modified: 13 July 2016