When you run, debug, or test your code, Android Studio uses a run/debug configuration to determine how to perform the operation. Typically, the initially-created configuration is sufficient to run or debug an app. However, you can modify and create new configurations, and modify the configuration templates to suit your development process as described on this page.
For more information, also see the following IntelliJ documentation:
About run/debug configurations
Run/debug configurations specify details such as app installation, launch, and test options. You can define a configuration for one-time use, or save it for future use. After you save it, you can select the configuration from the Select Run/Debug Configuration drop-down list within the toolbar. Android Studio saves configurations as part of the project.
Initially-created run/debug configuration
When you first create a project, Android Studio creates a run/debug configuration for the main activity based on the Android App template. To run or debug your project, you must always have at least one run/debug configuration defined. For this reason, we recommend that you don't delete the initially-created configuration.
Project scope and version control
Run/debug configurations and template changes apply to the current project only. You can share a run/debug configuration (but not a template) through your version control system. For more information about how to share a configuration, see Name and Share Configuration Options.
Open the Run/Debug Configurations dialog
To open the Run/Debug Configurations dialog, select Run > Edit Configurations. The Run/Debug Configurations dialog appears, as shown in figure 1.
The left panel of the dialog groups your defined configurations by template type, and allows you to edit configuration templates at the bottom. You can edit the selected configuration in the right panel. Resize the dialog to see any hidden items.
In this dialog, you can:
- Create new run/debug configurations.
- Edit run/debug configurations.
- Edit configuration templates.
- Sort and group configurations.
Create a new run/debug configuration
You can define new run/debug configurations from the Run/Debug Configurations dialog, the Project window, or the Code Editor. The new configuration must be based on a configuration template.
The Run/Debug Configurations dialog displays your run/debug configurations and the available configuration templates. You can start a new configuration directly from a template, or from a copy of another configuration. You can then change the field values as needed.
Alternatively, you can right-click an item in the Project window to automatically create a configuration specific to that item. For example, if you want to run a particular activity, you can right-click the activity Java file and select Run. Depending on the item, Android Studio uses an Android App, Android Instrumented Tests, or JUnit configuration template to create the configuration.
In the Code Editor, you can easily create a test and run/debug configuration for a class or method, and then execute it.
When you create a configuration outside of the Run/Debug Configurations dialog, the configuration is temporary unless you save it. By default, you can have up to five temporary configurations in the project before Android Studio starts to remove them. To change this default, open Android Studio settings, and change Advanced Settings > Run/Debug > Temporary configurations limit. For more information about temporary configurations, see Creating and Saving Temporary Run/Debug Configurations.
Start a configuration based on a template
To define a run/debug configuration based on a template, follow these steps:
- Open the Run/Debug Configurations dialog.
- Click Add New Configuration .
- Select a configuration template.
- Type a name in the Name field.
- Modify the configuration, as needed.
- Click Apply or OK.
Be sure to correct any errors displayed at the bottom of the dialog.
Start a configuration from a copy
To define a run/debug configuration starting from a copy of another configuration, follow these steps:
- Open the Run/Debug Configurations dialog.
- Select an existing run/debug configuration in the left pane.
- Click Copy Configuration .
- Type a name in the Name field.
- Modify the configuration, as needed.
- Click Apply or OK.
Be sure to correct any errors displayed at the bottom of the dialog.
Define a configuration for an item in the project
Android Studio can create a run/debug configuration for some items displayed in the Project window. The configuration is based on a configuration template, as follows:
- Activity Java file: The Android App template.
- Package: Android Instrumented Tests or Android JUnit template, depending on your source set. If you select an instrumented test, then it uses the Android Instrumented Tests template. If you select a local unit test, then it uses the Android JUnit template. For a local unit test, you can optionally run with code coverage. For more information, see Code Coverage.
To create a run/debug configuration for an item in your project, follow these steps:
- Open a project in Android or Project view.
- In the Project window, right-click a testable item and select either Run filename or Debug filename. Android Studio creates a temporary run/debug configuration and launches your app.
- Open the Select Run/Debug Configuration drop-down list in the toolbar.
- Select Save Configuration from the options next to the configuration that you
want to save.
Note: If you right-click and run or debug the same item (but not an activity), Android Studio creates a new configuration.
Define a test configuration for a class or method
Android Studio lets you define a test run configuration for a class or method, and then execute it. For example, if you create a new class, you can create and run a test for it. If the test passes, you can then run the tests for the rest of the project to make sure that your new code doesn't break anything somewhere else.
Android Studio uses the Android Instrumented Tests or Android JUnit template, depending on your source set. For a local unit test, you can optionally run with code coverage.
To create a run/debug configuration for a class or method in your Java code, follow these steps:
- Open a project in Android or Project view.
- Open a Java file in the Code Editor.
- Select a class or method in the code, and then press Control+Shift+T (Command+Shift+T).
- Select Create New Test from the menu that appears.
- In the Create Test dialog, optionally change or set the values and click OK.
- In the Choose Destination Directory dialog, select where in the project you want Android Studio to place the test. You can specify the location by directory structure or by selecting a neighboring class.
- Click OK.
The new test appears in the Project window in the corresponding test source set.
- To run the test, do one of the following:
- In the Project window, right-click the test and select Run or Debug.
- In the Code Editor, right-click a class definition or method name in the test file and select Run or Debug to test all methods in the class.
- Open the Select Run/Debug Configuration drop-down list in the toolbar.
- Select Save Configuration from the options next to the configuration that you
want to save.
Run or debug an app using a saved configuration
If you've saved a run/debug configuration, you can select it before you run or debug your app.
To use a saved run/debug configuration, follow these steps:
- Select the run/debug configuration from the Select Run/Debug Configuration drop-down list within the toolbar.
- Select Run > Run or Run > Debug.
The drop-down list is to the left of Run and Debug ; for example, .
Alternatively, click Run or Debug .
Edit a run/debug configuration
To edit a run/debug configuration, follow these steps:
- Open the Run/Debug Configurations dialog.
- Select a configuration in the left pane.
- Modify the configuration, as needed.
- Click Apply or OK.
Be sure to correct any errors displayed at the bottom of the dialog.
Edit a run/debug configuration template
You can edit the configuration templates provided by Android Studio to suit your development process. When you edit a template, it doesn't affect existing configurations that use the template. So, for example, if you need to create a number of configurations of a certain type, you can edit the template and then change it back when you're done.
Although you can't create new templates, you can create configurations to use similar to a template. You can copy a configuration and edit the copy to create new configurations.
To edit a template, follow these steps:
- Open the Run/Debug Configurations dialog.
- Click Edit configuration templates....
- Select a configuration template.
- Modify the configuration, as needed.
- Click Apply or OK.
Be sure to correct any errors displayed at the bottom of the dialog.
Sort and group configurations
In the Run/Debug Configurations dialog, you can order your configurations to find them quickly. You can sort the items in the folder alphabetically, and create new folders to group configurations.
To sort configurations alphabetically, follow these steps:
- Open the Run/Debug Configurations dialog.
- Select a folder that contains configurations.
- Click Sort Configurations .
- Click OK to close the dialog.
To group configurations in folders, follow these steps:
- Open the Run/Debug Configurations dialog.
- Select a folder that contains configurations.
- Click Create New Folder .
- Type a name in the Folder Name field.
- Click Apply to save the name.
Define before-launch operations
You can specify tasks to execute before applying the run/debug configuration. The tasks are performed in the order they appear in the list.
Note: Defining before launch tasks is an advanced feature. Instead of
using this feature, we recommend that you put any preparation logic as tasks in your
build.gradle
file so they'll be executed when you build from the command line.
To create a task list, follow these steps:
- At the bottom of the Run/Debug Configurations dialog under Before launch (you may need to scroll down), click Add and select a task type. If a dialog opens, fill in the fields and click OK.
- Add more tasks as needed.
- To order the tasks, drag them or select a task and click Up and Down to move it up or down in the list.
- Select Show this page if you want to display the run/debug
configuration settings before applying them.
This option is deselected by default.
- Select Active tool window if you want the
Run
or
Debug
tool window to be activated when you run or debug your app.
This option is selected by default.
To remove a task from the list, follow these steps:
- Select a task.
- Click Remove .
To edit a task, follow these steps:
- Select a task.
- Click Edit .
- Edit the task settings in the dialog that opens, and then click OK.
The following table lists the available tasks you can add.
Task | Description |
---|---|
Run External tool | Run an application that's external to Android Studio. In the External Tools dialog, select one or more applications that you want to run and then click OK. If the application isn't defined in Android Studio yet, add its definition in the Create Tools dialog. For more information, see Configuring Third-Party Tools and External Tools. |
Run Another Configuration | Execute one of the existing run/debug configurations. In the Choose Configuration to Execute dialog, select a configuration to execute and then click OK. |
Make | Compile the project or the module. Android Studio executes the Make Module command if the run/debug configuration specifies a particular module, or it executes the Make Project command if no modules are specified. |
Make Project | Compile the project. Android Studio executes the Make Project command. |
Make, no error check | This option is the same as Make, except that Android Studio executes the run/debug configuration irrespective of the compilation result. |
Build Artifacts | Unsupported in Android Studio. |
Run Gradle task | Run a Gradle task. In the dialog that opens, specify the details and then click OK. For more information, see Gradle. |
Gradle-aware Make | Compile the project and run Gradle. |
App Engine Gradle builder | The App Engine Gradle builder task syncs the project and then builds the module. |
Configuration templates
Android Studio provides configuration templates to help you get started quickly. The following sections describe the templates that apply to Android development with Android Studio:
Note: Android Studio 2.1.x and lower had a Native Application template, which newer versions don't have. If you have a Native Application template in a project, Android Studio converts it to Android App when you load the project. A Convert Project dialog guides you through the process.
Unsupported templates
The following unsupported templates come from IntelliJ IDEA and aren't specific to Android development with Android Studio. For information about using these templates, follow the links to the IntelliJ IDEA documentation.
- Application
- Compound
- Gradle
- Groovy
- JAR Application
- Java Scratch
- JUnit
- Kotlin
- Kotlin Script
- Remote Debug
- Shell Script
- TestNG
Common configuration options
The Name, Allow parallel run, and Store as project file options are common to multiple configuration templates. To learn more about them, see Common settings.
Android Studio stores the shared run/debug configuration in individual XML
files under the project_directory/.idea/runConfigurations/
folder.
For more information, see
Directory-based format in the IntelliJ projects documentation.
Android App
You can run or debug Android apps and activities on virtual or hardware devices by using configurations based on this template.
General tab
In the General tab, you can specify installation, launch, and deployment options. The Miscellaneous tab also contains installation options.
Field | Description |
---|---|
Module | Select a module to apply this configuration to. |
Installation Options: Deploy | Select an option:
|
Installation Options: Deploy as instant app | If your app supports instant experiences—that is, you either add support for instant apps when you create a new project, or you create one or more instant-enabled feature modules—you can choose to deploy those instant-enabled modules by checking the box next to Deploy as instant app. |
Installation Options: Features to deploy |
If your app includes
feature modules,
check the box next to each feature you want to include when deploying your app. You see
this option only if your app includes feature modules.
Note: If you want to test downloading and installing feature modules on demand, you must do so after you publish your app bundle and then use the Play Console internal test track. To learn more, read Upload your app bundle to the Play Console. |
Installation Options: Install Flags | Type any adb pm
install options you want to use. Format the options the same way that you would on
the command line, but without a path. Here are some examples:
and
Default: no options. |
Launch Options: Launch | Select an option:
|
Launch Options: Launch Flags | Type any adb am
start options you want to use. Format the options the same way that you would on the
command line, but without an intent. For example:
This option doesn't appear if you chose a Launch value of Nothing. Default: no options. |
Deployment Target Options: Target | Select an option:
|
Deployment Target Options: Use same device for future launches |
By default this option is deselected so that every time you run an app, the Select Deployment dialog appears for you to select a device. When you select this option and then run an app, the Select Deployment dialog appears for you to select a device. Then, every time you run the app, it launches on the device you selected without displaying the Select Deployment dialog. To run the app on a different device, either deselect Use same device for future launches, or stop the app with Run > Stop app or Stop , and then start it again. The Select Deployment dialog will display so you can select a device. |
Before Launch | See Defining Before Launch Operations. |
Miscellaneous tab
In the Miscellaneous tab, you can specify logcat, installation, launch, and deployment options. The General tab also contains installation options.
Field | Description |
---|---|
Logcat: Show logcat automatically | When this option is selected, the Logcat window opens every time you successfully deploy and launch an app using this configuration. Default: selected. |
Logcat: Clear log before launch | Select this option if you want Android Studio to remove data from previous sessions from the log file before starting the app. Default: deselected. |
Installation Options: Skip installation if APK has not changed. | When selected, Android Studio doesn't redeploy your APK if it detects that it's unchanged. If you want Android Studio to force an install of the APK, even if it hasn't changed, then deselect this option. Default: selected |
Installation Options: Force stop running application before launching activity | If selected, when Android Studio detects that it doesn't have to reinstall an APK because it hasn't changed, it will force-stop the app so that the app starts from the default launcher activity. If this option is deselected, Android Studio doesn't force-stop the app. This option works with the previous option that controls whether an APK is installed or not. For both Installation Options fields, leave them at the default unless you explicitly want to force an install every time. In some cases you might want to deselect this option. For example, if you're writing an input method engine (IME), force-stopping the app deselects it as the current keyboard, which you might not want. Default: selected |
Before Launch | See Defining Before Launch Operations. |
Debugger tab
Specify debug options in the Debugger tab.
For C and C++ code, Android Studio uses the LLDB debugger. In addition to the normal Android Studio UI, the debugger window has an LLDB tab that lets you enter LLDB commands during debugging. You can enter the same commands that Android Studio uses to display information in the debugger UI, and you can perform additional operations.
For C and C++ projects, you can add symbol directories, as well as LLDB startup and post attach commands, in the Debugger tab. To do so, you use buttons similar to the following:
- Add - Add a directory or command.
- Remove - Select a directory or command, and then click this button to remove the item.
- Up - Select a directory or command, and then click this button to move the item up in the list.
- Down - Select a directory or command, and then click this button to move the item down in the list.
See Debug Your App for more information about debugging in Android Studio.
Field | Description |
---|---|
Debug type | Select one of the following options:
The Detect Automatically option is recommended because it chooses the right debug type for your project. |
Symbol Directories | If you want to add symbol files to provide the debugger with C or C++ information generated outside of Android Studio, you can add one or more directories here. Android Studio preferentially uses any files within these directories over files generated by the Android Plugin for Gradle. The debugger searches the directories from top to bottom, in order, until it finds what it needs. It searches recursively through the files in the directory. To optimize the list and save time, put the directories used most often toward the top of the list. If you specify a directory high in the tree, it can take longer to search all of the subdirectories. If you add a very specific directory, it takes less time to search. You need to find the right balance between speed and finding the files you need for debugging. For example, if you have a directory that contains subdirectories for different Android Binary Interfaces (ABIs), you can choose to add a directory for a specific ABI or for all ABIs. Although it can take longer to search through the upper-level directory, it's also more foolproof if you decide to debug on a different device. Note that you don't have to add directories containing Gradle symbol files because the debugger uses them automatically. |
LLDB Startup Commands | Add LLDB commands that you want to execute before the debugger attaches to the process. For example, you can define settings for the environment, as shown in the following command:
LLDB executes the commands in order from top to bottom. |
LLDB Post Attach Commands | Add LLDB commands that you want to execute right after the debugger attaches to the process. For example:
LLDB executes the commands in order from top to bottom. |
Host working directory | Specify the LLDB working directory. |
Logging: Target channels | Specify LLDB log options. Android Studio sets the default options based on the team's experience — so it's not too slow but contains needed information for troubleshooting issues. The log is often requested for Android Studio bug reports. This default is
You can change the default to gather more information. For example, the
following log options gather information about a specific
lldb process
platform:gdb-remote packets
For a complete list of log
commands, enter the
Android Studio places device logs in the following location, where
Or, if
multiple users access a device, it places the logs in the following location,
where
For information about using LLDB for remote debugging, see Remote Debugging. |
Before Launch | See Defining Before Launch Operations. |
Profiling tab
The Enable advanced profiling option must be checked to enable certain features in the Android Profiler when your device is running Android 7.1 or lower.
Android Tests
The test template that you should use depends on your source set. The Android Instrumented Tests template is for an instrumented test. The Android JUnit template is for a local unit test.
Note: If you're using Firebase Test Lab to test on a variety of devices, you can use the Android JUnit template to define your instrumented tests. For more information, see Run Your Tests with Firebase Test Lab.
The following tab descriptions cover the tabs and fields for the Android Instrumented test template. For information about the tabs and fields for the Android JUnit test template, see the IntelliJ Run/Debug Configuration: JUnit page.
General tab
In General tab, you can specify test location, instrumentation runner, adb shell, and deployment options.
Field | Description |
---|---|
Module | Select a module to apply this configuration to. |
Test | In this area, specify the location of tests that you want to run:
|
Specific instrumentation runner (optional) | Type the location of the instrumentation
runner; click More to use a dialog. The
build.gradle file specifies the location of the instrumentation
runner; this value overrides it. The default is typically the AndroidJUnitRunner
class from AndroidX Test.
|
Extra options | Type any adb Default: no options |
Deployment Target Options: Target | Select an option:
|
Deployment Target Options: Use same device for future launches | If you want to automatically use the device you chose through the Select Deployment Target dialog in the future, select this option. If the device isn't available, you'll receive a dialog. Default: deselected |
Before Launch | See Defining Before Launch Operations. |
Miscellaneous tab
The Miscellaneous tab contains logcat and installation options.
Field | Description |
---|---|
Logcat: Clear log before launch | Select this option if you want Android Studio to remove data from previous sessions from the log file before starting the app. Default: deselected. |
Installation Options: Skip installation if APK has not changed | When selected, Android Studio doesn't redeploy your APK if it detects that it's unchanged. If you want Android Studio to force an install of the APK, even if it hasn't changed, then deselect this option. Default: selected |
Installation Options: Force stop running application before launching activity | If selected, when Android Studio detects that it doesn't have to reinstall an APK because it hasn't changed, it will force-stop the app so that the app starts from the default launcher activity. If this option is deselected, Android Studio doesn't force-stop the app. This option works in conjunction with the previous option that controls whether an APK is installed or not. For both Installation Options fields, leave them at the default unless you explicitly want to force an install every time. In some cases you might want to deselect this option. For example, if you're writing an input method engine (IME), force-stopping the app deselects it as the current keyboard, which you might not want. Default: selected |
Before Launch | See Defining Before Launch Operations. |
Debugger tab
Specify debug options in the Debugger tab.
For C and C++ code, Android Studio uses the LLDB debugger. In addition to the normal Android Studio UI, the debugger window has an LLDB tab that lets you enter LLDB commands during debugging. You can enter the same commands that Android Studio uses to display information in the debugger UI, and you can perform additional operations.
For C and C++ projects, you can add symbol directories, as well as LLDB startup and post attach commands, in the Debugger tab. To do so, you use buttons similar to the following:
- Add - Add a directory or command.
- Remove - Select a directory or command, and then click this button to remove the item.
- Up - Select a directory or command, and then click this button to move the item up in the list.
- Down - Select a directory or command, and then click this button to move the item down in the list.
See Debug Your App for more information about debugging in Android Studio.
Field | Description |
---|---|
Debug type | Select one of the following options:
The Detect Automatically option is recommended because it chooses the right debug type for your project. |
Symbol Directories | If you want to add symbol files to provide the debugger with C or C++ information generated outside of Android Studio, you can add one or more directories here. Android Studio preferentially uses any files within these directories over files generated by the Android Plugin for Gradle. The debugger searches the directories from top to bottom, in order, until it finds what it needs. It searches recursively through the files in the directory. To optimize the list and save time, put the directories used most often toward the top of the list. If you specify a directory high in the tree, it can take longer to search all of the subdirectories. If you add a very specific directory, it takes less time to search. You need to find the right balance between speed and finding the files you need for debugging. For example, if you have a directory that contains subdirectories for different Android Binary Interfaces (ABIs), you can choose to add a directory for a specific ABI or for all ABIs. Although it can take longer to search through the upper-level directory, it's also more foolproof if you decide to debug on a different device. Note that you don't have to add directories containing Gradle symbol files because the debugger uses them automatically. |
LLDB Startup Commands | Add LLDB commands that you want to execute before the debugger attaches to the process. For example, you can define settings for the environment, as shown in the following command:
LLDB executes the commands in order from top to bottom. |
LLDB Post Attach Commands | Add LLDB commands that you want to execute right after the debugger attaches to the process. For example:
LLDB executes the commands in order from top to bottom. |
Host working directory | Specify the LLDB working directory. |
Logging: Target channels | Specify LLDB log options. Android Studio sets the default options based on the team's experience — so it's not too slow but contains needed information for troubleshooting issues. The log is often requested for Android Studio bug reports. This default is
You can change the default to gather more information. For example, the
following log options gather information about a specific
lldb process
platform:gdb-remote packets
For a complete list of log
commands, enter the
Android Studio places device logs in the following location, where
Or, if
multiple users access a device, it places the logs in the following location,
where
For information about using LLDB for remote debugging, see Remote Debugging. |
Before Launch | See Defining Before Launch Operations. |
App Engine DevAppServer
This run/debug configuration applies to the Google Cloud Platform. For more
information, see
Running, Testing, and Deploying the Backend. When you follow these steps and sync your project
to the build.gradle
file, Android Studio creates an App Engine DevAppServer
configuration for you.
Note that the IntellJ IDEA App Engine Server template is a different template that's not available in Android Studio.
Field | Description |
---|---|
Single instance only | If you want to make sure that only one instance of the run/debug configuration is currently executed, select this option. It doesn't allow multiple runs of the same configuration at the same time. Default: selected |
Module | Select a module to apply this configuration to. |
Synchronize with build.gradle configuration | If you add an App Engine module and sync to the build.gradle
file, the App Engine DevAppServer configuration fields are filled in for you (recommended).
Selecting File > Sync Project with Gradle Files also syncs the project. Default: selected
|
App Engine SDK | Type a path to a Google App Engine SDK for Java on the local machine. Click ... to select it from a dialog. |
War Path | Type a path to the Web Application Archive (WAR) directory of the app you're deploying on the local development server. Click ... to select it from a dialog. |
VM Args | Specify the command-line options you want to pass to the VM for launching the DevAppServer. When specifying the options:
For more information about VM options, see the documentation for your J2SE
version, such as
Default: no options |
Server Address | Type the host address to use for the server. You might need to provide the address to be able to access the development server from another computer on your network. An address of 0.0.0.0 allows both localhost access and hostname access. Default: localhost |
Server Port | Type the port number to use for the server. Default: 8080 |
Disable Check for App Engine SDK Updates | If given, the development server will not contact App Engine to check for the availability of a new release of the SDK. By default, the server checks for a new version on startup, and prints a message if a new version is available. |
Before Launch | See Defining Before Launch Operations. |
Wear OS run/debug configurations
The Wear OS Complication, Tile, and Watch Face templates let you run or debug Wear OS apps on virtual or hardware devices. Most of the template configuration options are the same as the Android App options. Here are the options that are more specific to the Wear OS run/debug configurations:
- For all Wear run/debug configurations, you have to select a specific complication data source, tile, or watch face (depending on the template) to apply the configuration to. Generally each of these entities corresponds to a class in your code.
- For the Wear OS Complication run/debug configuration, you must choose the Slot where you want to put the complication data provided by the complication data source. You can choose to put it at the top, right, bottom, left, or background of the watch face.
- For the Wear OS Complication run/debug configuration, you must also select the Type of the complication data provided by the complication data source. The types you can choose from are limited to those that are provided by the chosen complication data source and supported by the chosen slot. For a list of complication data types, see Types and fields.
Alternatively, you can also run these surfaces from the gutter icon that is located next to the declaration of the surface, as shown in the following image.