When you run, debug, or test your code, Android Studio uses a run/debug configuration to determine how to perform the operation. Typically, the default configuration is sufficient and you can simply run or debug your app. However, you can modify and create new configurations, and modify the default templates, to suit your development process.
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.
When you first create a project, Android Studio creates a default 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 this configuration.
Run/debug configurations and template changes apply to the current project only. If you choose to share a run/debug configuration and then check your project into a version control system, the configuration is shared with anyone who checks out the project. You can’t share templates.
The Run/Debug Configurations dialog displays your run/debug configurations and the available default templates. In this dialog, you can:
To open the dialog, do one of the following:
The drop-down list is to the left of Run and Debug ; for example, .
If the toolbar isn’t currently displayed, select View > Toolbar to display it.
The Run/Debug Configurations dialog appears, as shown in Figure 1.
In the left panel, the dialog displays default templates in the Defaults folder. It groups your defined configurations by template type. You can resize the dialog to see any items that are hidden.
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 default template.
In the Run/Debug Configurations dialog, 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 Tests, or JUnit default 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, in the Run/Debug Configurations dialog, click the Defaults folder and type a value in the Temporary Configurations Limit field. For more information on temporary configurations, see Creating and Saving Temporary Run/Debug Configurations.
You can share a run/debug configuration (but not a template) through your version control system. If you select Shared in your run/debug configuration and then check your project into a version control system, anyone who checks out the project receives the configuration.
To define a run/debug configuration based on a template, follow these steps:
Be sure to correct any errors displayed at the bottom of the dialog.
To define a run/debug configuration starting from a copy of another configuration, follow these steps:
Be sure to correct any errors displayed at the bottom of the dialog.
Android Studio can automatically create a run/debug configuration for some items displayed in the Project window. The configuration is based on a default template:
Note: For a build.gradle
or
settings.gradle
file, Android Studio uses the Groovy
template. Instead, you should use the Gradle Console
to run or debug a build.gradle
file.
To create a run/debug configuration for an item in your project, follow these steps:
Android Studio creates a temporary run/debug configuration and launches your app.
The drop-down list is to the left of Run and Debug ; for example, .
Alternatively, right-click the item again and select Save.
Or, select the configuration in the Run/Debug Configurations dialog and click Save Configuration on the upper left.
Except for an activity, if you right-click and then run or debug the same item again, Android Studio creates a new configuration.
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 Tests or 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:
androidTest
to create an instrumented test or test
to
create a local unit test. Click OK.The new test appears in the Project window in the corresponding test source set.
The drop-down list is to the left of Run and Debug ; for example, .
Alternatively, right-click the item again and select Save.
Or, select the configuration in the Run/Debug Configurations dialog and click Save Configuration on the upper left.
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:
The drop-down list is to the left of Run and Debug ; for example, .
Alternatively, click Run or Debug .
Note: During an Instant Run session, selecting a different run/debug configuration, and then clicking Run or Debug again, ends the current session.
To edit a run/debug configuration, follow these steps:
Be sure to correct any errors displayed at the bottom of the dialog.
You can edit the default 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:
Be sure to correct any errors displayed at the bottom of the dialog.
In the Run/Debug Configurations dialog, you can order your configurations to be able 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:
To group configurations in folders, follow these steps:
You can specify tasks to execute before applying the run/debug configuration. The tasks are performed in the order they appear in the list. 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
building from the command line.
To create a task list, follow these steps:
This option is deselected by default.
This option is selected by default.
To remove a task from the list, follow these steps:
To edit a task, follow these steps:
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 does a build of the module. |
Android Studio provides default configuration templates to help you get started quickly. The following templates are applicable 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 automatically converts it to Android App when you load the project. A Convert Project dialog guides you through the process.
The following unsupported templates come from IntelliJ IDEA and aren’t specific to Android development with Android Studio:
Follow the links to the IntelliJ IDEA documentation for details on using these templates.
You can run or debug Android apps and activities on virtual or hardware devices by using configurations based on this template.
A run/debug configuration has the Name and Share options, while the template doesn’t.
Field | Description |
---|---|
Name | The name of the run/debug configuration. |
Share | Select this option to make the run/debug configuration available to other team members through version control. You can share a run/debug configuration, but not a template. If you select this option, when the project is checked into Git (or another version control system), the run/debug configuration is included when someone checks out the project.
Android Studio stores the shared run/debug configuration in an individual XML
file in the Default: deselected |
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: Install Flags | Type any adb pm
install options you want to use. Format the options as you would on
the command line, but without a path. Here are some examples:
and
Default: no options |
Launch Options: Launch | Select an option:
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> |
Launch Options: Launch Flags | Type any adb am
start options you want to use. Format the options as 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 |
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. |
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 tab of Android Monitor activates automatically every time you successfully deploy and launch an app using this configuration. Otherwise, the focus doesn’t move to the logcat tab automatically on app start. 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 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. |
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:
See Debug Your App for more information about debugging in Android Studio.
Field | Description |
---|---|
Debug type | Select one of the following options:
The Auto option is recommended because it automatically chooses the right debug type for your project. |
Experimental: Use Java aware C++ debugger - Android N+ only | Select this option to debug both C++ and Java Android code within the same LLDB debug session. The Java-aware C++ debugger is an extension of the Native debugger mode; along with C++ debugging, it supports Java as well. To be able to use this feature, the project must
If you selected a Debug type of Auto, Android Studio automatically selects this option if the project meets the requirements. Note that if you have a Java-only project and want to use LLDB to debug it, you can select this option and Native. As of Android Studio 2.2, this feature is experimental. For more information, see Use the Experimental Java-aware C++ Debugger. Default: deselected |
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 should 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. |
Specify GPU Debugger profiling options for Android Monitor in the Profiling tab.
Field | Description |
---|---|
Graphics Trace Options: Capture GPU Commands | If enabled, running this run/debug configuration will build, install, and run the app with GPU tracing. Tracing isn't supported when debugging an app. If you debug an app with GPU tracing, you'll receive a message and the debugger launches without tracing. This option is relevant for the GPU Debugger tool. Note that after you enable this checkbox, every time you launch the app it will block and wait for you to attach either the debugger or the GPU Debugger. |
Graphics Trace Options: Disable precompiled shaders and programs | Select this option to disable OpenGL ES graphics driver support for precompiled shader and program binaries during tracing. This option is relevant for the GPU Debugger tool.
Precompiled shaders aren’t supported for replaying traces, and so only shaders
compiled at runtime using the
Apps should always query for precompiled shader support before using the
Default: deselected |
Before Launch | See Defining Before Launch Operations. |
The tests template that you should use depends on your source set. The Android Tests template is for an instrumented test. The JUnit template is for a local unit test.
If you're using Firebase Test Lab to test on a variety of devices, you can use this template to define your instrumented tests. For more information, see Run Your Tests with Firebase Test Lab.
A run/debug configuration has the Name and Share options, while the template doesn’t.
Field | Description |
---|---|
Name | The name of the run/debug configuration. |
Share | Select this option to make the run/debug configuration available to other team members through version control. You can share a run/debug configuration, but not a template. If you select this option, when the project is checked into Git (or another version control system), the run/debug configuration is included when someone checks out the project.
Android Studio stores the shared run/debug configuration in an individual XML
file in the Default: deselected |
In the 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 … 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 the Android
Testing Support Library .
|
Extra options | Type any adb am
instrument options you want to use. Don’t type the component. For example,
if you’re using AndroidJUnitRunner
from the Android
Testing Support Library, you can use this field to pass additional options
to the runner, such as -e size small . 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. |
The Miscellaneous tab contains logcat and installation options.
Field | Description |
---|---|
Logcat: Clear log before launch | Select this option if you want data from previous sessions to be removed 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. |
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:
See Debug Your App for more information about debugging in Android Studio.
Field | Description |
---|---|
Debug type | Select one of the following options:
The Auto option is recommended because it automatically chooses the right debug type for your project. |
Experimental: Use Java aware C++ debugger - Android N+ only | Select this option to debug both C++ and Java Android code within the same LLDB debug session. The Java-aware C++ debugger is an extension of the Native debugger mode; along with C++ debugging, it supports Java as well. To be able to use this feature, the project must
If you selected a Debug type of Auto, Android Studio automatically selects this option if the project meets the requirements. Note that if you have a Java-only project and want to use LLDB to debug it, you can select this option and Native. As of Android Studio 2.2, this feature is experimental. For more information, see Use the Experimental Java-aware C++ Debugger. Default: deselected |
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 should 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. |
Specify GPU Debugger profiling options for Android Monitor in the Profiling tab.
Field | Description |
---|---|
Graphics Trace Options: Capture GPU Commands | If enabled, running this run/debug configuration will build, install, and run the app with GPU tracing. Tracing isn't supported when debugging an app. If you debug an app with GPU tracing, you'll receive a message and the debugger launches without tracing. This option is relevant for the GPU Debugger tool. Note that after you enable this checkbox, every time you launch the app it will block and wait for you to attach either the debugger or the GPU Debugger. |
Graphics Trace Options: Disable precompiled shaders and programs | Select this option to disable OpenGL ES graphics driver support for precompiled shader and program binaries during tracing. This option is relevant for the GPU Debugger tool.
Precompiled shaders aren’t supported for replaying traces, and so only shaders
compiled at runtime using the
Apps should always query for precompiled shader support before using the
Default: deselected |
Before Launch | See Defining Before Launch Operations. |
This run/debug configuration applies to the Google Cloud Platform. For more
information, see Adding
an App Engine Java Servlet Module and 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 | Name | The name of the run/debug configuration. |
---|---|
Share | Select this option to make the run/debug configuration available to other team members through version control. You can share a run/debug configuration, but not a template. If you select this option, when the project is checked into Git (or another version control system), the run/debug configuration is included when someone checks out the project.
Android Studio stores the shared run/debug configuration in an individual XML
file in the Default: deselected |
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 Tools > Android >
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. |