April 20, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Getting Started with Google's Android Studio

  • July 5, 2013
  • By Jessica Thornsby
  • Send Email »
  • More Articles »

In contrast to last year's Google I/O event, where consumer-focused highlights included Google Glass and the Nexus 7, this year's conference had some big announcements for the developer community, most notably the first integrated development environment (IDE) dedicated entirely to Android.

Android Studio is essentially the community edition of JetBrains' IntelliJ IDEA with an Android plugin; a setup that will sound familiar to anyone who's used Eclipse with ADT. Previously, Eclipse has been Google's recommended IDE for Android, but now the search giant is shaking things up by giving developers a choice of supported development environments. But how does Android Studio stack up against Eclipse?

In this post, we look at what Android Studio has to offer Eclipse users, before showing you how to try this brand-new IDE for yourself by installing Android Studio and creating the obligatory Hello World app.

Do You Need to Make the Switch?

If you're already using Eclipse for Android development, you may be wondering how it compares to this tried-and-tested IDE. As is often the case with competing software, there are advantages and disadvantages to making the switch.

Firstly, Android Studio is currently only available as an early access preview, so you should expect missing functionality and perhaps even the odd bug, whereas Eclipse is an established and long-standing IDE. However, Android Studio is built on the proven IntelliJ platform and has the weight of Google behind it, so it's no surprise to find that it's very reliable and stable, especially for an early access release. In terms of future development, we've already seen bugs fixed in these early releases, so it seems likely that they'll be a fully-featured public release of Android Studio soon.

Another issue that all new software must address when it's trying to replace an established solution is users who are interested in trying something new, but have ongoing work tied to another solution. The early access preview handles this with wizards dedicated to migrating projects created within Eclipse, to Android Studio. This ensures that a half-completed Eclipse project is no barrier to trying out the new IDE. As an added bonus, once users have migrated they'll find many familiar tools waiting for them, such as the SDK and AVD managers.

In terms of new functionality, Android Studio offers template-based wizards for some of the most common Android designs and components, making it easier for developers to achieve a standard look and feel. Developers can also use the 'Gradle' build system that's included in Android Studio to automate building, testing, publishing and deployment. You can learn more about Gradle at Gradle.org.

One of the most exciting features of Android Studio is the innovative live layout editing mode that lets you preview an app's user interface across a range of devices. You can even preview an app across multiple devices simultaneously using the 'Preview All Screen Sizes' option, or toggle between different orientations, themes and platform versions. This functionality could prove to be a real time-saver for developers wrestling with the tricky task of designing for multiple screens.

Getting Started: Install Android Studio

Now you're familiar with what Android Studio has to offer and the current drawbacks, it's time to get some hands on experience with Android Studio. Grab the all-in-one bundle. Once the download is complete, open the .exe file and follow the instructions in the setup wizard.

Create a New App with Android Studio

Once you've installed Android Studio, you're taken straight to the welcome screen. Select 'New Project.'

Welcome to Android Studio
Welcome to Android Studio

Enter a project name, package name, specify the target platform and choose a theme. For the purposes of this tutorial, we're creating an app called 'Hello Studio' with a single MainActivity, and a corresponding activity_main.xml layout file.

New Project
New Project

Click 'Finish' to create the project and get your first real look at the Android Studio IDE.

Android Studio IDE
Android Studio IDE

Exploring the Android Studio IDE

Before fleshing out your app, it's worth taking some time to explore the main parts of the IDE.

1. Project Pane

The 'Project' pane is how you explore your project's different files and folders. If it doesn't open automatically, click the vertical 'Project' tab on the left-hand side of the screen.

The Project Pane
The Project Pane

2. AVDs

To launch an AVD, open the 'Tools' menu and select 'Android,' followed by AVD Manager. From here, you can create a new AVD or open any AVD previously created in Eclipse.

3. Preview Mode

As already mentioned, the live layout editor is one of the IDE's most impressive features. Access it by opening your XML layout file and selecting the 'Text' tab beneath the main editing window. Select the vertical 'Preview' tab on the right-hand side of Android Studio to launch Preview mode.

The first thing you'll want to do is choose a device to preview your app in. Either choose one of the pre-defined configurations from the device drop-down menu, or select 'Add Device Definition' and create a new configuration.

Choose a Device
Choose a Device

To toggle between landscape and portrait modes, click the 'Configuration' icon in the Preview window's left-hand corner and select either 'switch to layout-land' or 'switch to layout.'

Landscape and Portrait Mode
Landscape and Portrait Mode

Want to compare and contrast your UI across multiple devices simultaneously? Select 'Preview All Screen Sizes' from the device drop-down menu.

Preview All Screen Sizes
Preview All Screen Sizes

You can also toggle between different platform versions and themes, using the remaining drop-down menus. Spend some time exploring everything this powerful feature has to offer.

4. Palette

The Palette and Canvas are present and correct in Android Studio, and they function exactly the same as in Eclipse. To access the Canvas, open an XML layout file and select the 'Design' tab beneath the main editing window. From here, select the 'Palette' tab on the left-hand side of the IDE, and you're ready to start designing your UI using drag and drop.

Palette and Canvas
Palette and Canvas

Create a Basic App with Android Studio

Now you know your way around Android Studio, it's time to make your Hello World app more interesting by adding some text and a string resource.

In the Palette, scroll down to 'Text Fields' and drag a Plain Text item onto the Canvas. For our next trick, we'll create a string resource without even opening the strings.xml file.

Double-click the Plain Text item within Canvas to open a popup. In the 'text' section, enter the reference for the string resource we'll create in the next step. In this example, we'll use @string/hello.

Enter the Reference for the String Resource
Enter the Reference for the String Resource

Click the three-dotted icon next to '@string/hello' to launch the 'Resources' dialog. Click the 'New Resource' button, followed by 'New string value.' You should now be looking at the 'New String Value Resource' dialog.

New String Value Resource
New String Value Resource

The 'Resource name' is the identifier you created earlier, in this instance that's 'hello.' Give your string resource a value (we're using the cheery greeting of 'Hello, Android Studio!') and click 'OK.' The Canvas updates automatically to display the new text.

Finally, change your app's theme. Return to the Preview panel and open the 'Theme' drop-down. This launches a 'Select Theme' dialog, where you can browse all of the pre-defined themes. Use this dialog in conjunction with the Preview mode to quickly and easily experiment with different themes.

Select Theme
Select Theme

Once you're ready to test drive your app, open the 'Tools' menu, followed by Android and 'AVD Manager.' Choose an AVD from the list and press 'Start…' to launch the emulator.

Congratulations, you've developed your first app in Android Studio!

Conclusion

In this article we compared the early access preview of Android Studio to Eclipse, before test driving Android Studio by creating a Hello World app. There's much more to explore, so why not build on this basic app by adding color resources, more UI elements and new activities?

You can get more information about using Android Studio at the Developers portal.

About the Author

Jessica Thornsby is a Sheffield-based technical writer.


Tags: Java, Eclipse, Google, Android, development, IDE, android studio




Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel