In this topic:
- Before you start
- Choosing the module type you need
- Creating a project with an Android module from scratch
- Adding an Android module to a project
- Importing an Android-Gradle project
- Attaching an Android facet to an existing Java module
- Configuring the code style of Android-specific XML definition files
-
Download and extract
the Android SDK
.
We strongly recommend that the path to the Android SDK home directory does not contain spaces.
Note that the Android SDK is not a substitute for a Java SDK (JDK). You need to download and configure a Java SDK for your project anyway.
-
Add SDK packages. For detailed instructions and download links, refer to Adding SDK Packages
.
- Configure the Android SDK in IntelliJ IDEA, see Configuring Global, Project and Module SDKs.
- Make sure that the bundled Android Support plugin is activated. This plugin provides Android support at the IntelliJ IDEA level and is enabled by default. If the plugin has been disabled, enable it in the Plugin Configuration Wizard, or in the Plugins page of the Settings dialog box.
- Depending on your task, choose the module type you need for Android development.
-
Create a project with an Android module from scratch, add an Android module to a project, import a Gradle-Android project,
or attach an Android facet to an existing Java module.
Depending on the chosen module type, IntelliJ IDEA automatically sets up the correct module structure with the
resandgenfolders, downloads the necessary libraries, and generates various Android-specific descriptors.
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:
genandsrc. -
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
.apkfiles 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.
This procedure explains how to create an Android Application Module.
-
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 from the main menu.
The New Project wizard opens.
- In the left-hand pane, select Android. In the right-hand pane, select Application Module.
- 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.
-
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
.imlmodule file, and the content root of the module. - Project format.
This procedure explains how to add an Android Test Module to your project. Test modules are intended for creating and
running Android unit tests
.
-
Choose from the main menu or
from the context menu of the Project tool window.
The New Module wizard opens.
- In the left-hand pane, select Android. In the right-hand pane, select Test Module.
- On the next page of the wizard, specify the module name, the location of the
.imlmodule file, the content root of the module and select the target module that is going to be tested.
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.
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.
- Open the Project Structure dialog box.
- Under Project Settings, select Modules.
-
Select the module you want to add an Android facet to, click
, and choose Android.
-
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.
-
To make the module source code and resources available from other projects
,
select the Library module check box on top of this page.
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.
- Open the Settings / Preferences Dialog by choosing for Windows and Linux or for OS X. Expand the Editor node, and then click XML under Code Style.
- On the Code Style:XML page that opens, switch to the Android tab.
-
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.