Tuesday, April 17, 2012

Using IntelliJ IDEA for Android development

Eclipse is a default IDE for Android development. But personally I have always hated it since the first try. Its UI is very obscure and unobvious. There are really annoying things, like Android Logcat log displayed not as a text, but in a grid, which is difficult to view and copy from; the Logcat window itself being always on top when detached; inability to open two files with the same name from different folders. There are at least five different search commands (three of which open the same Search dialog), but there is no simple "Find Word at Caret" function, which I use a lot. Some other functionality I am used to after many years of work with Visual Studio is missing as well, like quick simple bookmarks, which could be added or navigated to with just one key press.

A while ago I was recommended to try IntelliJ IDEA, and liked it much more! Its developers at JetBrains definitely kept good IDEs in mind while creating their IDEA.

Originally Android development in IntelliJ IDEA was supported via a 3rd-party plugin, then it was included into the Ultimate Edition, but in the latest versions it comes with the Community Edition as well.

The only problem when you are using IntelliJ for Android development is the initial setup for the IDE itself, and for each new project. Every time I start using it on a new system, I spend some time trying to figure out, which bits and pieces have to be configured. Finally I've decided to write this post, so that next time when I'll need it, I'll use this information myself. :)

Here's a brief list of configuration options to set. I am not providing step-by-step instructions at the moment - may do this later, now just trying to document what I've just done, while I still remember it.

Prerequisites: Java SDK (you need v1.6 for Android development) and Android SDK are already downloaded and installed on your machine.

All the options are in the Project Structure dialog, which opens through the main File menu.

Platform Settings section - SDKs:
- Add JSDK: select where Java SDK is located on your system;
- Add Android SDK: browse for the android-sdk-xxx folder, choose it, then when prompted select the JDK first, then the Android target platform;

Project Settings - Project:
- Check the Project SDK - it should have the selected Android platform.

Project Settings - Modules:
- Add Android module by clicking the [+] button on the toolbar;
- Press OK to apply the changes (just Apply does not work for some reason).

Project Settings - Facets:
- Make sure there is Android facet for your module.

If you have several modules, set the proper dependencies in the Modules section.

You'll also need to add Run/Debug configuration. It is done using Run - Edit Configurations menu command. Just click the [+] button on the toolbar in that dialog, select Android Application, type the name for it, select the module to run, and set other parameters if needed.

You are all set!

No comments: