The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Android Studio Editors and Dialogs

Eclipse, with the ADT plugin, had many structured editors and specialized dialogs for modifying Android project files and otherwise configuring Android project behavior.

Android Studio has fewer of those, and they are generally less critical. The editors and dialogs presented in this chapter can be useful, at least in some cases, but you do not need to use any of them to be able to create your Android projects. However, some may speed up your Android development a bit over working with bare resource and Gradle files.

Prerequisites

Understanding this chapter requires that you have read the core chapters of this book, along with the chapter on Gradle and build variants.

Project Structure

The Project Structure dialog allows you to configure many aspects of your build.gradle files from a tabbed property-style dialog, as opposed to having to work with the Gradle scripts directly. On the plus side, this can be easier. However, since Gradle is built on the Groovy scripting language, build.gradle files are not simple XML or JSON data structures. It remains to be seen how well the Project Structure dialog will be able to handle complex Gradle scripts.

To access the Project Structure dialog, choose File > Project Structure from the main IDE menu.

The left-hand side lists major areas of the dialog; choosing one of those switches to that area’s form on the right.

The sections that follow outline each of the major areas and what you can configure in them.

SDK Location

The Project Structure dialog opens up on the SDK Location area, where you can configure where your Android SDK is located, where your JDK is located, and where your NDK is located:

Project Structure Dialog, SDK Location Category
Figure 917: Project Structure Dialog, SDK Location Category

For new Android Studio 2.2+ installations, the default is for Android Studio to use a version of the Java JDK that ships with the IDE itself, in which case “Use embedded JDK (recommended)” will be checked.

Adjusting these in Project Settings affects this specific project. There is also File > Other Settings > Default Project Structure, where you can edit the default values to be used for new projects and projects that you import in the future.

Project Settings

The second entry in the Project Structure dialog category list is “Project”. This allows you to configure four items found by default in the build.gradle file in your project root or in the gradle-wrapper.properties file:

Project Structure Dialog, Project Settings Category
Figure 918: Project Structure Dialog, Project Settings Category

Developer Services

If you are using select portions of the Play Services SDK, the items under the “Developer Services” divider allow you to configure those portions. By default, they amount to checkboxes, to enable certain features:

Project Structure Dialog, Notifications Category
Figure 919: Project Structure Dialog, Notifications Category

Module Settings

Below the “Modules” divider in the category list on the left will come all of your modules. If you are not using modules, there will be a single entry in the category list with the same name as your project, as a quasi-module.

Clicking on a module will bring up a set of tabs on the right to edit various properties of that module, independently of any other module in your project. The following sections outline the contents of those tabs.

Properties

The first tab is labeled “Properties” and allows you to adjust various top-level settings in your module’s build.gradle file.

Project Structure Dialog, Module Category, Properties Tab
Figure 920: Project Structure Dialog, Module Category, Properties Tab

These include:

Signing

If your module’s build.gradle file has a signingConfigs closure, the “Signing” tab will let you edit those signing configurations:

Project Structure Dialog, Module Category, Signing Tab
Figure 921: Project Structure Dialog, Module Category, Signing Tab

Each signing configuration that you have defined will appear in the list on the left side of the tab. On the right are fields for you to fill in the signing configuration name, the keystore file and key alias to use, and the passwords to use for accessing that file and alias.

The green plus (“+”) icon on the right side of the list lets you define a new signing configuration, while the red minus (“-”) icon lets you delete an existing signing configuration.

Flavors

The “Flavors” tab starts off with a single “flavor”, representing your build.gradle file’s defaultConfig settings. The green plus icon next to the list of flavors lets you define a new flavor, while the red minus icon lets you remove an existing flavor. Note that you cannot remove defaultConfig, as it is defined by the Gradle for Android plugin.

Project Structure Dialog, Module Category, Flavors Tab
Figure 922: Project Structure Dialog, Module Category, Flavors Tab

On the right side of the tab, you can set or change the name of the flavor, plus you can adjust various flavor (or defaultConfig) settings, including:

Build Types

The “Build Types” tab allows you to adjust settings for the debug and release build types. The green plus icon next to the list of build types lets you define a new build type, while the red minus icon lets you remove an existing build type. Note that you cannot remove debug or release, as they are defined by Gradle.

Project Structure Dialog, Module Category, Build Types Tab
Figure 923: Project Structure Dialog, Module Category, Build Types Tab

On the right side of the tab, you can set or change the name of the build type, plus you can adjust various settings in your buildTypes closure, including:

Dependencies

If your project has any defined dependencies in a dependencies closure, these will appear in the “Dependencies” tab:

Project Structure Dialog, Module Category, Dependencies Tab
Figure 924: Project Structure Dialog, Module Category, Dependencies Tab

The tab is dominated by a two-column table, where the left column is the dependency itself. The right column is the “scope”, where the cell shows the current scope, and if you click on it, you get a drop-down list of available scopes:

Dependencies Tab, Showing Scope Drop-Down
Figure 925: Dependencies Tab, Showing Scope Drop-Down

Those scopes include:

The latter two scopes will be used infrequently.

If you click the green + button, you will be able to add a new dependency. A drop-down menu will let you choose between a library dependency (i.e., for an artifact in a repository), a file dependency, and a module dependency (i.e., to depend upon another module in your project).

Typically, you will be adding library dependencies. When you choose that option, another dialog appears to allow you to search for likely dependencies or type in the full dependency identifier (group ID:artifact ID:version).

Choose Library Dependency Dialog, As Initially Launched
Figure 926: Choose Library Dependency Dialog, As Initially Launched

Choose Library Dependency Dialog, With Search Results for greenrobot
Figure 927: Choose Library Dependency Dialog, With Search Results for “greenrobot”

The red - icon in the same toolbar as the green + will remove a dependency, while the up and down arrows allow you to reorder the dependencies.

Translations Editor

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.