IntelliJ IDEA 13.1 Web Help

On this page:

Preparing for Android development

Choosing the module type you need

IntelliJ IDEA distinguishes among the following types of Android modules: Application Module, Empty Module, Library Module, and Test Module. You choose the type of the module for Android development either when creating the module from scratch or when adding a module to an existing 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:

  1. The src folder for the sources that implement the application behaviour.
  2. The res folder with dedicated subfolders to store definitions of visual application resources: images, strings, layouts, etc.
  3. The gen folder. The folder contains the application package com.example.<application name> with the following files:
    • R.java file that links the visual resources and the Java source code.
    • Manifest.java file stub for referencing custom permissions.
    • BuildConfig.java file where the mode of the Android Application package is defined through the public final static boolean DEBUG field. If the field value is set to true, the APK is generated in the debug mode, which means that the application will not be intended for publishing.

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 be only added to an existing project.

Creating a project with an Android module from scratch
  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 on the main menu.
    The New Project Wizard starts.
  2. On the Main Settings page, choose the type of the module to create among the types listed in the Android area:
    • An Application Module is ready for developing an Android application.
    • 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.
  3. Specify the following settings regardless of the selected module type:
    1. The name of the project, its location, and format.
    2. The Android SDK to use in the project and in the module.
    3. The name of the module, the location of the .iml module file, and the content root of the module.
  4. Depending on the selected module type, specify the following:
    • For an Application module, click Next and specify the following on the second page of the wizard:
      • The name of the application that will be implemented in the module and the package to store the application classes in.
      • Optionally, enable creation of a sample "Hello, World!" application and specify the title of the window to be displayed on the sample application start.
      • Specify the target device to run the application on.
    • For a Library module, specify the name of the application and the destination package to store the application classes in.
Adding an Android module to a project
  1. Choose File | New Module on the main menu or New | Module on the context menu of the Project tool window.
  2. On the Main Settings page, choose the type of the module to create among the types listed in the Android area:
    • An Application Module is ready for developing an Android application.
    • 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.
    • Test Module is intended for creating and running Android unit tests.
  3. Regardless of the chosen module type, specify the name of the module, the location of the .iml module file, and the content root of the module.
  4. Depending on the chosen module type, specify the following:
    • For an Application module, click Next and specify the following on the second page of the wizard:
      • The name of the application that will be implemented in the module and the package to store the application classes in.
      • Optionally, enable creation of a sample "Hello, World!" application and specify the title of the window to be displayed on the sample application start.
      • Specify the target device to run the application on.
    • For a Library module, specify the name of the application and the destination package to store the application classes in.
    • For a Test module, specify the target module to run unit tests against.
Attaching an Android facet to an existing module
  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 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..

    The controls in the tab shows default settings. You can edit them if necessary. To return to the default Android facet settings, click the Reset paths to defaults button.

  5. To make the module source code and resources available from other projects, select the Library project check box.
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 the code style settings for them.

  1. Open the project settings by choosing File | Settings, click Code Style, then click XML.
  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

Procedures:

Reference:

Web Resources: