First steps with Android on Intellij IDEA (Windows 7)
This is my personal view on beginning with Android development and is intended for Android beginners with at least some Java experience. I did some Java development before, but had no experience with mobile development at all. I got myself Nexus device and dived into it in October 2012. In the bottom of article you can find couple of useful links which will help you with your development.
I know that Windows isn’t the best environment for development, yet this tutorial should help everyone struggling or having fear to try it on Windows.
First you need to download Android SDK. It comes in two versions:
- Bundled with Eclipse, so you just unpack it and it works . Google pushes this version as default, but I don’t like having the bundle of software and not knowing what’s inside
- SDK Tools only. It’s in closed menu on the same page as bundled version. It’s distributed as an installer or a zip. I recommend to go for installer, as it may set some background stuff as environment variables for you automatically.
Installer needs to have set JAVAHOME environment variable. If your Java installer didn’t set it, you need to do it manually. Open start menu and type “edit environment variables for your account”. Then click new button, name the variable JAVAHOME and set the value to your JDK installation (e.g. c:\Program Files\Java\jdk1.7.0_17).
After successful installation, open your SDK Manager and install API libraries you want. I recommend to use latest version and the milestone versions such as Gingerbread, which you’ll probably want to support for a while. This is also the place to install Google Maps SDK libraries, Google Play Services libraries or Intel x86 driver for virtual devices.
Android Studio @ Google I/O 13
This year guys from Google decided to directly support new IDE - to be honest my favourite: Intellij IDEA. I know you guys probably like and use Eclipse, but JetBrains IDE family for Java, PHP, Ruby… provide me features under one hood, which no other IDE does.
At Google I/O 2013 Xavier Ducrohet, Tor Norbye and CTO of JetBrains Dmitry Jemerov presented features of new Android plugin for Intellij and IDE based on Intellij IDEA - Android Studio.
I’ve tried Android studio myself. It comes bundled with SDK and everything starting Android developer needs, but it’s still early version and has some bugs. I personally recommend EAP (early access preview) version of Intellij IDEA, which has almost same features and is stable. Play the talk and see the magic.
Setting up Intellij IDEA is easy. After clean install, first you need to set two main things:
- Paths to your JDK. You can do that from welcome page: configure - project defaults - project structure - new (JDK). I set the path to C:\Program Files\Java\jdk1.7.0_17.
- Next you need to set your Android SDK path, which should be somewhere at C:\Program Files (x86)\Android\android-sdk.
That’s everything. Now you can create new project and start trying stuff.
Everything related to build (such as paths, libraries, JAR) is available in Module settings - right click on project root in project explorer or F4 keyboard shortcut. I will go through main options there and try to explain them. To not be just theoretical, imagine Android project with main module with app itself, test module with jUnit tests and library module with ActionBarSherlock library for having action bar in <IceCreamSandwich versions of Android.
If you used Eclipse before, you are probably used to library projects, test projects etc. In IntelliJ, project is created from set of modules - one of them is your main application, another is test module, another library module. See the difference…
In project settings you can go through:
- Project. Here you can set up Android SDK version which will be used in compilation process (I recommend to use the latest), JDK of the project (IntelliJ allows you to use even JDK7+, not like Eclipse) and compile output target folder.
- Modules. You can order dependencies of modules and libraries in build paths and set scope of each record (whether it is provided as compiled JAR or it needs to be compiled).
- Libraries. Here you can aggregate your libraries into “packages” e.g. debug libraries or just all libraries used in project, and then use the package in dependency part of Modules section - instead of adding every JAR separately.
- Facets let’s you setup project related paths to files of each module. If your module is library (such as ActionBarSherlock), don’t forget to tick the library module checkbox in the detail view of facet.
- Artifacts is place for configuration of future build stuff such as JAR files, JavaFX apps etc.
After having everything properly configured here, you are ready to build your application.
Building & Running
IntelliJ let’s you run directly from the toolbar or from run menu. However I recommend to create run configurations from the run - edit configurations submenu. You can preset target device, build params, Activity you want to enter (without editing android.manifest) and many more. Except the main application, you can create configurations for unit test or even XSLT transformation.
When this is ready, you can choose your configuration directly in toolbar and run it without further dialogs. It can be really handy if you need to switch from one configuration to another (e.g. running the tests before deploying the app to your device).
I hope the article gave you some basic overview how things might work. Don’t forget to check references below and feel free to join the discussion.