Part 2: IntelliJ and Android

In my previous post I talked about installing and setting up Android to work with the JetBrains IntelliJ because in my view the development experience is a huge improvement over what is afforded to developers by Eclipse.  In this post, I will talk about how to use emulators and the other various tools you may or may not be familiar with

Setting up an Emulator

Working with any mobile operating system is going to require emulation to mimic various devices and situations.  Android is not only the exception, but with its proliferation as an open operating system it finds itself on a wide variety of devices.  Use the SDK Manager tool to install skins and other emulator profiles, this will be essential in your test.

To create an emulator, use the SDK Manager that comes with Android, it is accessible from directly within IntelliJ (see below)

2011-07-30_2314

The option you will want out of the submenu is “Android SDK and AVD Manager”.  The SDK Manager is responsible for adding/removing various optional components from the SDKs that you have installed, as well as adding new Android SDKs.  The AVD Manager is responsible for managing the emulators.  As you can see, I currently have a wide variety of emulators available on my current system.

2011-07-30_2317

To add a new one, press the New button.  This will bring up the next screen where you provide the configurations for your emulator of AVD.

2011-07-30_2318

The main things to be concerned with here is the Name, which I have provided as Gingerbread_WVGA, indicating the SDK name and the resolution the emulator will run at.  At this point you could hit Create AVD and be done, but lets explain the other sections.

  • SD Card : Specifying this size allows you to mimic a device with an SD Card.  If your app is going to save anything to the phone, you will need this as a storage mechanism
  • Skin : This is the device you want to mimic, it could be a Galaxy or Milestone.  I generally leave as default with a standard resolution (HVGA or WVGA).  You can download additional skins through the SDK Manager
  • Hardware : Depending on what you want to do with your app, you may want to add certain hardware features to the emulator to more closely simulate an actual device.

The end result, if successful, is the device should now appear in your AVD list.

Using an Emulator

For most apps, I recommend using an emulator set to the lowest possible version you want to support, 2.1 is the most common platform target since 2.x makes up roughly 90% of the platform distribution for the Android platform.

To set a certain emulator to run when running the app, you will need to set a Run Configuration (shown below)

2011-07-30_2326

This will bring up the Run/Debug Configurations screen where you can configure the run.  For this particular application I have two configurations PayItSquare and PISDevice.  The second one is more manual and allows me to target an actual device if one is plugged in.  The first one is my default and runs my Éclair emulator to emulate a device running Android 2.1-update 1.

Configuration 1

2011-07-30_2331

Configuration 2

2011-07-30_2329

We are going to demonstrate the second configuration since it gives the most flexibility.  I would encourage a new user to explore the various options on all the tabs (Emulator, Logcat as well) to get a good feel for how to bring the emulator as close as possible to the device a user will be using.

Hitting Play with the second configuration selected will bring up the following screen:

2011-07-30_2334

As you can see, at the current moment I have no Emulators running or devices plugged in.  If I press the Launch Emulator button, I can select which emulator I wish to run the app in (see below).

2011-07-30_2335

This display is even nice enough to tell us which emulators would not be compatible with our projects target SDK.  In this case, I would pick the Eclair _HVGA emulator.

Note: when you press OK your app will NOT be deployed to the emulator.  You will have to keep the other window open until the emulator instance shows up.  I generally wait till the emulator reaches the start screen before hitting Refresh.

Once you see the emulator instance in the selector window (hit Refresh) you can select it and indicate to IntelliJ to deploy your app to that emulator:

2011-07-30_2338

This will launch your app.

Using Logcat

Logcat is the secret weapon of most Android developers, it provides information, straight from the phone, about what is happening (or happened) under the hood.  It will even give you stack trace information when an error is encountered, its damn handy, and IntelliJ makes it really easy to use.

Mine is located at the bottom of my development environment

2011-07-30_2354

Clicking on this will bring up the Logcat for all connected Android devices and emulators.  There does tend to be a lot of data, so look for Red if you trying to determine the cause of an error.

I hope this helps people looking to use IntelliJ as their new development environment over Eclipse.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s