IntelliJ IDEA 15.0 Help

Getting Started with Android Development

In this topic:

Before you start

Choosing the module type you need

IntelliJ IDEA distinguishes between the following types of Android modules: Gradle: Android Module, Application Module, Empty Module, Library Module, and Test Module. You can choose the type of module for Android development either when creating a module from scratch, or when adding a module to an existing project.

  • A Gradle: Android Module lets you create Android applications or libraries that are compiled and built with the Gradle build tool. For instructions on how to create a Gradle-Android module, refer to Creating a Gradle-Android Project.
  • An Application Module is a module that is ready for developing an Android application. IntelliJ IDEA will create an application package and set up the Android-specific module structure.
  • An Empty Module contains two empty folders: gen and src.
  • A Library Module is intended for holding shared Android source code and resources. Other Android application projects can reference a library project and include its compiled sources in their .apk files at build time. When you choose the Library module type, IntelliJ IDEA sets up almost the same module structure as for an Application Module, but does not suggest generating a sample application. Another difference is that IntelliJ IDEA updates the Android facet of the module: the Library project check box is automatically selected in the module settings.
  • A Test Module is intended for creating and running Android unit tests. Modules of this type can only be added to an existing project.

Creating a project with an Android module from scratch

This procedure explains how to create an Android Application Module.

  1. Do one of the following:
    • If no project is currently opened in IntelliJ IDEA, click Create New Project on the Welcome screen.
    • If you already have an opened project, choose File | New | Project from the main menu.

    The New Project wizard opens.

  2. In the left-hand pane, select Android. In the right-hand pane, select Application Module.
  3. On the next page of the wizard, specify the name of the application that will be implemented in this module, and the package where the application classes will be stored. Optionally, enable the creation of a sample "Hello, World!" application and specify the title of the window that will be displayed on the sample application start.
  4. On the last page of the wizard, specify:
    • The name of the project and its location.
    • The Android SDK to be used in this project and in this module.
    • The target device where the application will be run and debugged. The available options are:
      • Do not create run configuration: select this option if you do not want to set the Run/Debug configuration at this point. You will be prompted to configure it when you first launch a run or a debug session.
      • Show device chooser dialog: if this option is selected, the Choose Device Dialog will be displayed each time you start a run or a debug session.
      • USB device: if this option is selected, IntelliJ IDEA will automatically detect a plugged-in USB device upon the application start.
      • Emulator: if this option is selected, the preferred Android Virtual Device will be launched when you start a run or a debug session. If you have no Android Virtual devices configured, the Create Android Virtual Device dialog will be displayed.
    • The name of the module, the location of the .iml module file, and the content root of the module.
    • Project format.

Adding an Android module to a project

This procedure explains how to add an Android Test Module to your project. Test modules are intended for creating and running Android unit tests.

  1. Choose File | New | Module from the main menu or New | Module from the context menu of the Project tool window.

    The New Module wizard opens.

  2. In the left-hand pane, select Android. In the right-hand pane, select Test Module.
  3. On the next page of the wizard, specify the module name, the location of the .iml module file, the content root of the module and select the target module that is going to be tested.

Importing an Android-Gradle project

One of the most common scenarios of starting Android development with IntelliJ IDEA is importing an existing Android-Gradle project. For detailed instructions refer to Importing Project from Gradle Model.

Attaching an Android facet to an existing Java module

You need to perform this procedure if you want to attach an Android facet to an existing Java module. Android modules have this facet applied by default.

  1. Open the Project Structure dialog box.
  2. Under Project Settings, select Modules.
  3. Select the module you want to add an Android facet to, click add, and choose Android.
  4. On the Facet 'Android' page that opens, specify the location of the key application components in the Structure tab: the AndroidManifest.xml file, the application resources, the application assets, and the Android native libraries..

    If necessary, you can edit the default paths. To return to the default Android facet settings, click Reset paths to defaults.

  5. To make the module source code and resources available from other projects, select the Library module check box on top of this page.

Configuring the code style of Android-specific XML definition files

Android development involves working with dedicated XML files, such as layout and resource definition files, manifest files, etc. You can have IntelliJ IDEA apply the standard XML code style to such files, or configure custom code style settings for them.

  1. Open the Settings / Preferences Dialog by choosing File | Settings . Expand the Editor node, and then click XML under Code Style.
  2. On the Code Style:XML page that opens, switch to the Android tab.
  3. Do one of the following:
    • To define a custom code style for Android-specific XML files, select the Use custom formatting settings for Android XML files check box and configure the settings to be applied to various types of Android XML files using the controls of the tab as described in Code Style:XML - Android.
    • To have IntelliJ IDEA format Android-specific XML files according to the standard XML code style settings defined in the other tabs of the page, clear the Use custom formatting settings for Android XML files check box.

See Also

Last modified: 10 December 2015