Getting Started with Android Studio – from an Eclipse ADT user’s perspective

Introduction

I you have seen my previous post you will know that I’m migrating from Eclipse to Android Studio as part of a routine update onLearning Tree’s course on  Developing Android Applications. As discussed there:  it is going to be, like it or not the official Android Development tool. As a seasoned Android developer, I’ve been using Eclipse and ADT for many years this post is primarily intended for others starting from that position.

Versions of Android Studio

There are two ways of getting hold of Android Studio. You can either visit the downloads page at developer. URL and get a Beta copy or for the more daring, go to the Canary channel and take the latest build. If you need stability then go with the beta versions. This review is based on the latest build from the Canary channel which was 0.8.14. Purely by chance, the day I completed this post, the very same version became available in the beta channel!

 

Start Android Studio

As soon as you start Android Studio (if you don’t mind, I’ll refer to it as AS most times I use it), you will see the Welcome screen. Most of the options here are self-explanatory but there are couple I’d like to focus on for this post.

Select import to migrate from eclipse to android studio
Android Studio Welcome Screen

The first option is Configure it is here that you define settings which apply to all projects and one in particular which is the location of the Android SDK . If like me, you need to maintain projects which use both Eclipse ADT and Android Studio: it is really useful to be able to share a single SDK installation.

“How to I set the Android SDK location?”

From the Welcome screen select Configure | Project Defaults | Project Structure. This should take you to a screen where you can set both the Android SDK and Java JDK locations. If you want to get back to the Welcome screen at any time simply close all existing projects from within AS.

Importing Eclipse Projects

The second very useful option from the Welcome screen is Import Project this allows you to import an existing Eclipse ADT project into AS which hugely simplifies the process of migrating from Eclipse to Android Studio. It takes a minute or two whilst various Gradle scripts are run to configure your environment. What you should see on completion is something like this:

 

migrating from Eclipse
An Eclipse ADT project migrated into Android Studio

Project Structure

On first glance, there is a big difference between the project structures of Eclipse and Android Studio. In AS, projects consist of multiple modules. By convention, the Android application module is called app. To locate your code and resources, you first need to expand app | src | main from there on, the Java code is under java, resources under res much as in Eclipse. You will also find the manifest under main but be very careful: unlike Eclipse, the manifest does not define the SDK versions you are building for!

Specifying build versions

The manifest must still contain declarations for build versions eg the target SDK versions and minimum SDK versions. These are now specified with the project structure settings. To access them, you simply right-click on the app directory in the project structure view and select Open Module Settings. Clicking on the Flavors tab brings up the screen shown below.

Android studio build flavors on a project imported from Eclipse
Specifying Android build flavors.

When the project is built, the values from this screen are copied into the manifest automatically. Notice that middle pane? It allows multiple sets of options to be specified so that a single project can be built in lots of different ways. It is of course Gradle which handles all the build options for us. This is a key element in maintaining multiple versions of you application to cope with issues such variation in API support, touch-screen compatibility (TV?) etc.

Type to search blog.learningtree.com

Do you mean "" ?

Sorry, no results were found for your query.

Please check your spelling and try your search again.