Skip to content

Android (Eclipse) HowTo

cdm2012 edited this page Jun 2, 2015 · 40 revisions

This MAC Guide describes how to run your first Android application using the Eclipse IDE.

Prerequisites for this guide are HowTo:

In this guide, you will be covering the following topics:

Note: If you have eclipse with the Android Plugin already you can skip to section 2, where there is a supplementary video that shows how to use Android Eclipse in action.

The guide concludes with running the Android sample source code from section 2 on a hardware device.

1 Set Up Eclipse Environment for Android

Note: With this guide you can learn the basics of how to work with Eclipse projects and some of its nifty features.

The most relevant section is #1 Download, Extract and Open an Eclipse Version, and the remaining sections help to familiarize with eclipse.

1.2 Add Android Plugin

To add the ADT plugin to Eclipse:

  • Start Eclipse, then select Help > Install New Software.

  • Click Add, in the top-right corner.

  • In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the

URL:

https://dl-ssl.google.com/android/eclipse/

Note: The Android Developer Tools update site requires a secure connection. Make sure the update site URL you enter starts with HTTPS. Click OK.

  • In the Available Software dialog, select the checkbox next to Developer Tools and click Next.

  • In the next window, you'll see a list of the tools to be downloaded. Click Next.

  • Read and accept the license agreements, then click Finish.

If you get a security warning saying that the authenticity or validity of the software can't be established, click OK.

  • When the installation completes, restart Eclipse.

Note: Check out Installing the Eclipse Plugin for more detail on this configuration process (or for troubleshooting).

2 Import API Demos Sample project from Android SDK

2.0 Download API Demos Sample from Android 2.3 SDK

The image below links to a video that provides an example of how to import an Android SDK sample. (CTRL + Click to open video in a new window or tab).

Download/Import API Demos Sample

The steps from the video can be followed in section 2.1+

2.1 Open SDK Manager

Click the icon on the Menu bar that resembles a Box (with an Android in it).

Open SDK Manager

Then click "Deselect All" on the bottom center of SDK Manager, to only download the needed content.

Deselect All

2.2 Download Samples from Android Version 2.3

The SDK Manager will open and you can then select "Samples For SDK" under "Android 2.3.3 (API 10)".

Note: If you do not have "Android 2.3.3 (API 10)", "SDK Platform" you will need it as well for the sample to work.

Select Samples

Click "Install 1 Package" on the bottom right of SDK Manager, or "Install 2 Packages" if adding "SDK Platform".

Install 1 Package

2.3 Select API Demos Sample from Version 2.3

Create New Android Sample Project, under the other category

New Android Sample Project

In the Wizard options select "Android Sample Project"

Wizard options

Select the SDK Version 2.3 for its samples

Select the SDK Version

Select API Demos from the list of 2.3 samples

Select API Demos

2.4 Fix Bug in Android SDK Sample

Finally, there is a small bug in the Android XML file progressbar_2.xml that needs to be fixed.

Bug From Android SDK

To fix this bug you can simply replace all instances of "+android:" with "+" within progressbar_2.xml.

Bug Fix For API Demos

3 Run sample implementation on Emulator

3.0 Run API Demos Sample from Android 2.3 SDK on Emulator

The image below links to a video that provides an example of how to run an Android SDK sample. (CTRL + Click to open video in a new window or tab).

Run API Demos

The steps from the video can be followed in section 3.1+

3.1 Create the Emulator

Click the icon on the Menu bar that resembles a phone (with an Android inside of it).

Create the Emulator

The AVD Manager will open and you can then select "Create" on the top right of dialog.

Create

Note: If you do not have "Android 2.3.3 (API 10)" or higher, "SDK Platform" you will need it for the emulator to run the sample.

You will now see the "Create new Android Virtual Device (AVD)".

Create new Android Virtual Device

You will then fill in details for the AVD, please take note of the defaults used in example.

Android Virtual Device Details

Once the details are fill into the device, you can then start the emulator.

3.2 Starting the Emulator

After selecting the emulator that you created, click the Start button on the right hand side of the AVD Manager.

Starting the Emulator

There will be another dialog titled "Launch Options" that will show, but you can simply press "Launch" to start the emulator.

Launch the Emulator

The Emulator will launch and load (for the next minute roughly).

Loading Emulator

3.3 Run API Demos sample on Emulator

The emulator is now ready for the API Demos App, so we can go to the "Run" Menu (or right click in Package Explorer) to run the application.

Run API Demos

Now Right Click project for "Context Menu" -> "Run As" -> "Android Application"

The API Demos Application running on the emulator will look as follows:

Running on Emulator

4 Run sample implementation on Actual Device

4.1 Enabling On-device Developer Options

To access Developer settings, open the Developer options in the system Settings. On Android 4.2 and higher, the Developer options screen is hidden by default.

To enable it, you can go to System Settings (where you can set date and time settings).

  • Scroll to the bottom and click on "About phone".

About Phone

About Phone

  • In the list displayed, find the heading called "Build number". It is usually at the bottom of the list.

Build Number

Build Number

  • Tap on the "Build number" seven times (sounds funny, I know).

Developer options

Developer options is now turned on. You will find it in the Settings (the previous menu) usually right above "About phone".

After returning to the previous screen to find Developer options at the bottom, enter "Developer Options" and Enable debugging over USB.

Note: Check out Using Hardware Devices for more detail on this configuration process (or for troubleshooting).

4.2 Run API Demos sample on Device

The device is now ready for the API Demos App, so we can go to the "Run" Menu (or right click in Package Explorer) to run the application.

Run API Demos

Now Right Click project for "Context Menu" -> "Run As" -> "Android Application"

The API Demos Application running on the device will look as follows:

Running on Emulator

Clone this wiki locally