Android 101: Development environment and project creation

The first step you need to do is to install your development environment. We will be using Eclipse, the recommended IDE.

Installing and configuring the Android SDK and the development environment

Here's what you need to get started:

I also recommend that you use a source control system and the necessary plugins for Eclipse, although that's outside the scope of this article. You can browse the Eclipse Marketplace from within Eclipse (through the Help menu) for a lot of different plugins.

Creating your first Android project

Creating your first Android project is easy.

  • Go to File > New > Project...
  • Select Android Project from Android .
  • Specify the project details:
    • Project name: Honeybuzz in this case.
    • Build target: we will be targeting Android 3.0 for this application.
    • Application name: the name of your application (usually it will be similar or the same as the project name, but not necessarily).
    • Package name: this is a unique name that identifies your application. You should be careful in choosing this name to avoid conflicts with other applications. It's common to write the package name in the form of com.domain.application . In this case we chose com.quasibit.Honeybuzz (because we own the domain).
    • Create activity: this should be checked for most applications (an Activity is basically a screen in a Android application) and you should choose a descriptive name. For example, the main Activity in our application is called HoneybuzzListActivity (because it shows a listing of the most recent buzzes).
    • Min SDK version: minimum compatible version. For Honeycomb that is 11.

Adding external libraries

After creating the project we will add the libraries that we need. There are different ways in which you can manage your dependencies. A popular way is by using Maven. Using Maven has a few advantages such as automatically download Java libraries, but it also has some drawbacks: it is more complex to get started and in the case of Android it is not possible to start a debugging session on your device from within Eclipse, because the libraries will not be included in your APK (Android Application Package) in this case.

We will add the libraries manually:

  • Download all the necessary libraries:
  • Make a new folder libraries in your project.
  • Add the libraries, sources and available JavaDoc to this folder. Make sure they are copied, not linked. I do it this way so I can store everything in the source control. I added these libraries:
    • google-api-client-1.4.1-beta
    • google-api-client-extensions-android2-1.4.1-beta
    • google-api-client-extensions-android3-1.4.1-beta
    • google-api-client-googleapis-1.4.1-beta
    • google-api-client-googleapis-extensions-android2-1.4.1-beta
    • google-api-services-buzz-v1-1.0.0-beta
    • And these dependencies:
      • gson-1.6
      • guava-r09
      • jackson-core-asl-1.6.7
      • jsr305-1.3.9
    • In later articles we will also add libraries for analytics, ads and error reporting.
  • Specify the libraries in the project properties.
    • Right click the project and open its properties.
    • Go to Java Build Path and open the Libraries tab.
    • Add all the libraries using the Add JARs... option:
      • Expand your project and the libraries folder and select the JAR.
      • Expand the JAR's details and specify the sources and JavaDoc location when available.
    • You should end up with something similar to this:

The Google Plugin for Eclipse also helps adding Google APIs to your project, but we haven't used it in this case.

Setting up ProGuard

We will do an extra configuration step to help reduce the application size. ProGuard will shrink and optimize your Java files by stripping out unused code and performing code optimizations.

How to configure ProGuard for your Android application:

  • Edit the file and add the line:
  • Edit your proguard.cfg file and add the following lines:
# Needed by google-api-client to keep generic types and @Key annotations accessed via reflection

-keepclassmembers class * { <fields>;

-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault

# Needed by Guava

-dontwarn sun.misc.Unsafe

This is the basis for the initial configuration of your project. Next we will do a very brief introduction to Android development.

Android Development Overview

The best resource for Android development is the Android Developers site: it has development guides, references and resources.

In this guide we will be talking about several different topics, but we won't go deep into Android fundamentals, because the Android Developers site already does a good job in that. For starters I would recommend reading What is Android? and Application Fundamentals.

Here is a very brief overview of an Android application:

  • Most applications have Activities. An Activity is basically a screen in your application.
  • Some applications use Services that run in the background. A Service doesn't have an interface and is usually used to perform long-running processes, such as updating the data for an application.
  • When you want to start an Activity or a Service you declare an Intent. An Intent doesn't have to be exclusive to your application. One example of an Intent is to open a web page in the user's browser.
  • Your application has a manifest. In the manifest you specify all your Activities, Services, your widgets, the required permissions and much more. It is at the root of your project and is called AndroidManifest.xml.
  • You define the interface for your Activities using layout files. Layouts usually contain one or more Views.
  • Resources are stored in the res folder. All your project images, layout files, strings, preferences, configuration values and more are stored here.
  • An Android application is delivered using an APK (Android Application Package): it is a compiled package with all the resources of your application. This is what gets installed on Android devices.

Before continuing I recommend that you read at least the first 4 tutorials found on the Android Developers site. A basic knowledge of Activities, layouts and resources will be required for the reminder of the development guide.

Related articles