IntelliJ IDEA 2016.3 Help

Running and Debugging Android Applications

On this page:

    Running or Debugging an entire Android application

    1. 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.
    2. Choose the Default APK from the Deploy drop-down list in the Installation Options area and Default Activity from the Launch drop-down list in the Launch Options 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.
    3. Appoint the device where the application will run:
      • To use a virtual device, select the Emulator option from the Target drop-down list in the Deployment Target Options area. Select a device from the Prefer Android Virtual Device list, or click /help/img/idea/2016.3/browseButton.png to configure a new emulator.
      • To use a physical device, select the USB device option from the Target frop-down list in the Deployment Target Options area, and plug-in the device through a USB cable.
      • Select the Show Device Chooser Dialog option if you want to select the target manually each time upon the application launch.
    4. Start running or debugging the target activity. If you have not specified a target device, choose it manually.
    5. View and analyze Android system messages in the Logcat tab of the Android Monitor tool window.

    Running or debugging a custom .apk that will be later embedded in an application

    1. Configure an artifact to generate the .apk from:
      • In the main menu, navigate to File | Project Structure .
      • In the left-hand pane, click Artifacts. In the central pane, click the Add button /help/img/idea/2016.3/new.png 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 Output Layout Tab.
    2. 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.
    3. To run or debug a custom .apk, choose the Custom Artifact option from the Deploy drop-down list in the Installation Options 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 Working with Artifacts for details). Then select the Specified Activity option from the Launch drop-down list in the Launch Options area, and specify the start-up activity from the chosen artifact (.apk). Type the activity name manually or click the Browse button browseButton.png and select it in the Select Activity Class dialog box that opens.

      The list of available activities is determined by the choice of the module.

    4. Appoint the device where the application will run:
      • To use a virtual device, select the Emulator option from the Target drop-down list in the Deployment Target Options area. Select a device from the Prefer Android Virtual Device list, or click /help/img/idea/2016.3/browseButton.png to configure a new emulator.
      • To use a physical device, select the USB device option from the Target frop-down list in the Deployment Target Options area, and plug-in the device through a USB cable.
      • Select the Show Device Chooser Dialog option if you want to select the target manually each time upon the application launch.
    5. Start running or debugging the target activity. If you have not specified a target device, choose it manually.
    6. View and analyze Android system messages in the Logcat tab of the Android Monitor 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:
      1. Click the Attach debugger to Android process button /help/img/idea/2016.3/addAndroidDebuggerToProcess.png in the main toolbar.
      2. In the Choose Process dialog that opens, select a process from the list that shows all currently active processes grouped by the devices where they are running.
    • Start a run/debug configuration without deploying a package and launching an activity
      1. 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.
      2. Select the Nothing option from the Deploy drop-down list in the Installation Options area and Nothing from the Launch drop-down list in the Launch Options area.
      3. Appoint the device where the application will run:
        • To use a virtual device, select the Emulator option from the Target drop-down list in the Deployment Target Options area. Select a device from the Prefer Android Virtual Device list, or click /help/img/idea/2016.3/browseButton.png to configure a new emulator.
        • To use a physical device, select the USB device option from the Target frop-down list in the Deployment Target Options area, and plug-in the device through a USB cable.
        • Select the Show Device Chooser Dialog option if you want to select the target manually each time upon the application launch.
      4. Start running or debugging the target activity. If you have not specified a target device, choose it manually.
      5. View and analyze Android system messages in the Logcat tab of the Android Monitor tool window.

    See Also

    Last modified: 21 March 2017