This tutorial describes how to create Android applications with Eclipse. It is based on Eclipse 4.2 (Juno), Java 1.6 and Android 4.1 (Jelly Bean).
The great thing with Android programming is that all needed tools are free and you can use Linux, Windows or Mac operating systems.
We're going to install and configure the following software in order to start Android programming:
- Java JDK
- Android SDK
- Android Development Tools (ADT)
- Android Virtual Device (AVD)
The Android SDK required the Java SE Development Kit (JDK), so if you do not have it installed get it from www.oracle.com/technetwork/java/javase/downloads/index.html
The main tools is Android SDK (software development kit). It contains libraries, debugger, documentation and tutorials, Android emulator and you can get it on http://developer.android.com/sdk/index.html
After downloading unzip the content into desired folder (e.g. /opt/android-sdk on GNU/Linux)
Note: If you are a Windows user, Google recommends getting the installer (the latest version is installer_r20.0.3-windows.exe) that will configure the tools automatically. Download, run the installer file and follow the steps.
When you start the Android SDK Manager you will see a list of items and whether or not they are currently installed on your machine.
After you select the items to be installed, click the Install button. The download process could take a time depending on your selection, so we advise to get only what you need at that time and install other items later. For the purpose of this tutorial install the following items:
Note: You should at least choose the latest Android SDK platform and the Extras. At the time of writing, the latest SDK platform is SDK Platform Android 4.1, API 16.
Each version of the Android OS is identified by an API level number. For example, Android 4.1 is level 16 (API 16). For each level, two platforms are available, e.g.:
- SDK Platform
- Google APIs by Google Inc.
The main difference is that Google API contains some additional APIs provided by Google (e.g. Google Maps). So, if you need these additional features you need to create an AVD with Google APIs platform.
You will be asked to choose the packages to install, select the Accept All option and click the Install button.
The installation process could take some time, so be patient. After the installation, you will be asked to restart the ADB (Android Debug Bridge); choose Yes.
The recommended IDE (integrated development environment) for Android programming is Eclipse.
For Android development, you should download the Eclipse IDE for Java EE Developers. Visit www.eclipse.org/downloads/ and download proper edition for your environment(Linux, Windows, Mac, 32- or 64-bit...)
After download, uncompress the content into e.g. /opt/eclipse on Ubuntu or C:\Program Files\eclipse on Windows. Start Eclipse by double-clicking the file, choose default workspace folder and click OK button.
Android Development Tools (ADT)
The next step is to install ADT (Android Development Tools) plug-in for Eclipse. The ADT is an extension to the Eclipse IDE that supports the creating and debugging of Android applications.
Run Eclipse and select Help > Install New Software.
Enter https://dl-ssl.google.com/android/eclipse/ and hit Enter. You'll see the Developer Tools item and you need to expand it to see its content (e.g. Android Development Tools, Android DDMS, Android Hierarchy View, Android Traceview). Select all items and click Next button twice.
Note: If you have any problems downloading the ADT, consult Google's help at http://developer.android.com/sdk/eclipse-adt.html#installing.
Accept the offered licenses - select "I accept the terms of the license agreements" and click Finish button. Restart Eclipse after the installation is finished. When Eclipse is restarted, you will be asked to configure your Android SDK. Because the Android SDK has already been downloaded earlier in the previous section, check the "Use existing SDKs" option and specify the directory where you have installed the Android SDK. Click Next. After this step, you will be asked to send your usage statistics to Google. Once you have selected your choice, click Finish.
Note: The installation steps could be slightly different in different SDK versions, so if you don't experience the same steps as we described, just follow the instructios on screen.
AVD (Android Virtual Device)
The next task to do is to create an Android Virtual Device (AVD) to be used for running and testing your Android applications. An AVD is an emulator instance that enables you to model an actual device. Each AVD consists of a hardware profile; a mapping to a system image; as well as emulated storage, such as a secure digital (SD) card. You can create as many AVDs as you want in order to test your applications with several different configurations. This testing is important to confirm the behavior of your application when it is run on different devices with varying capabilities.
To create an AVD, select Window > AVD Manager
In the "Android Virtual Device Manager" dialog, click the "New..." button to create a new AVD.
In the "Create new Android Virtual Device (AVD)" dialog, enter the items as displayed below.
Click the "Create AVD" after you select desired items.
In this case, you have created an AVD (simply saying, an Android emulator) that emulates an Android device running version 4.1 of the OS with a built-in 10-MB SD card. In addition to what you have created, you also have the option to emulate the device with different screen densities and resolutions.
It is preferable to create a few AVDs with different API levels and hardware configurations so that your application can be tested on different versions of the Android OS.
After ADV has been created, it is time to test it. Select the AVD that you want to test and click the "Start..." button. The Launch Options dialog will appear.
Click the Launch button to start the emulator.
Tip: If you have a small monitor, it is recommended that you check the "Scale display to real size" option so that you can set the emulator to a smaller size.
The Android emulator will start, and after a while it will be ready for use. It will behave just like a real Android device so go ahead and try it out.
Now, you're ready for Android programming. In one of the next articles we'll teach you how to create your first Android application. Stay with us!