Android Programming

From CSWiki
Jump to: navigation, search

Android is an operating system for mobile devices that runs on a Linux kernel.

Contents

[edit] Setting up an Android Programming Environment

Programs for Android can be written on many different operating systems, including Windows, Linux, and MacOS. The EUP CS Linux and Windows computers in the DH222 and Dundee labs have been configured with all the necessary software to facilitate Android programming in Eclipse.

[edit] Android Programming in the Labs

In order to develop Android applications in the labs, you must first set up the paths to the Android SDK for your user profile. There is a small script called androidpath which will take care of this for you. The androidpath script will:

  • Generate the necessary configuration files, and populate these files with the location of the Android SDK for Eclipse.
  • Create an Android Virtual Device (AVD) based on the Android 1.6 platform.

You should only need to run this command once. Android applications are forward compatible, meaning an app created for the 1.6 platform will work on versions greater than 1.6.

[edit] Android Programming in the Linux Lab

To program Android applications in the Linux lab, start by opening a terminal window and running the androidpath command. You will see output similar to the following:

$ androidpath
Android 1.6 is a basic Android platform.
Do you wish to create a custom hardware profile [no]Created AVD 'my_avd' based on Android 1.6
$

After executing the androidpath script, you are ready to open Eclipse and start programming! To start Eclipse, you can either run the eclipse command from the command line, or open it from the Applications -> Programming -> Eclipse. After opening Eclipse, you may need to wait a short amount of time (1-2 minutes) for the Android SDK to be loaded; you can see the loading progress in the lower right hand corner of Eclipse.

For an example of a basic "Hello, World" program, see Hello World | Android Developers

[edit] Android Programming in the Windows Lab

To program Android applications in the Windows lab, start by opening a command prompt and running the androidpath command. You will see output similar to the following:

C:\>androidpath
A subdirectory or file C:\Documents and Settings\username\workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings already exists.
Android 1.6 is a basic Android platform.
Do you wish to create a custom hardware profile [no]Created AVD 'my_avd' based on Android 1.6
C:\>

You can start a command prompt in Windows by going to Start -> All Programs -> Accessories -> Command Prompt, or by going to Start -> Run and typing the command cmd. You can also skip the command prompt, and just go to Start -> Run and enter the androidpath command.

After executing the androidpath script, you are ready to open Eclipse and start programming! To start Eclipse, go to Start -> All Programs -> Eclipse -> Eclipse. After opening Eclipse, you may need to wait a short amount of time (1-2 minutes) for the Android SDK to be loaded; you can see the loading progress in the lower right hand corner of Eclipse.

For an example of a basic "Hello, World" program, see Hello World | Android Developers

[edit] Android Programming at Home

In order to write Android applications on your computer, you will need to install a few supporting software programs. Here are some basic instructions for installing Android on Fedora and Windows.

[edit] Android Programming on Windows

These instructions are for Eclipse 3.5. Installation procedures for other versions of Eclipse may differ.

  1. Install the Java Development Kit.
    • The Java Development Kit can be downloaded from the Java SE Downloads Page.
    • You must install the JDK package; JRE alone is not adequate!
  2. Install Eclipse.
    • You will need to download the Eclipse Classic platform from the Eclipse Download Page.
    • There is no installer for Eclipse, so you can simply extract the Eclipse files into the Program Files directory, and manually create a shortcut to Eclipse in your preferred location.
  3. Install the Android Software Development Kit
    • The Android SDK can be downloaded from the Android SDK Page.
    • There is no installer for the Android SDK, so you can simply extract the files into a folder within your Program Files directory. Make note of this directory, it will be needed in the next step.
  4. Set your PATH variable to include the Android SDK Tools Location (optional).
    • Right click on My Computer and Select Properties, click on the Advanced tab, click Environment Variables, find the Path variable in the System Variables section, click Edit, and append the location to the \tools folder within the Android SDK folder (something like C:\Program Files\android-sdk-windows\tools\).
  5. Update the Android SDK with the latest SDK Platforms and APIs.
    • The Android SDK does not come with any development platforms, so you must add at least one before you can begin programming!
    • Run the android application within the \tools directory of the Android SDK installation.
      • Select Settings, and put a checkmark in the box next to Force https://... sources to be fetched using http://..., then click Save & Apply.
      • Select Installed Packages, click the Update All... button, wait for the sources to be refreshed, select the Accept All radio button, and click Install Accepted. Once this has finished, close the Android SDK and AVD Manager, and close the command window (if needed).
  6. Open Eclipse and update with the necessary Android Software
    • Within Eclipse, go to Help -> Install New Software.
    • Click the Add... button and Add the following two sites, and install all software contained within those sites.
      • http://dl.google.com/eclipse/plugin/3.5
        • Plugin
          • Google Plugin for Eclipse 3.5
        • SDKs
          • Google App Engine Java SDK 1.3.0
          • Google Web Toolkit SDK 2.0.0
      • http://dl-ssl.google.com/android/eclipse/
        • Developer Tools
          • Android DDMS
          • Android Development Tools
  7. After accepting and notices, installing the packages, and restarting Eclipse, you must set the Android SDK Location within Eclipse.
    • Within Eclipse, go to Window -> Preferences
    • Click on Android in the left column.
    • Enter the path to the Android SDK (ex.: C:\Program Files\android-sdk-windows)
  8. You are now ready to start writing programs for Android!

After opening Eclipse, you may need to wait a short amount of time (1-2 minutes) for the Android SDK to be loaded; you can see the loading progress in the lower right hand corner of Eclipse.

For an example of a basic "Hello, World" program, see Hello World | Android Developers

[edit] Android Programming on Linux

These instructions are for Fedora Eclipse 3.4 on Fedora 10. Installation procedures for other versions of Eclipse or other distributions of Linux may differ. You will need to be logged in to the GUI as root to complete some of these steps!!!

  1. Install the Eclipse, Java Development Kit, and Apache Ant (if desired).
    • # yum -y install eclipse-platform java-1.6.0-openjdk ant
  2. Install the Android Software Development Kit
    • The Android SDK can be downloaded from the Android SDK Page.
    • There is no installer for the Android SDK, so you can simply extract the files to your desired location. Make note of this directory, it will be needed in the next step (we use /usr/local/android/).
  3. Set your PATH variable to include the Android SDK Tools and Platform-Tools Location (optional).
    • Create a file in the /etc/profile.d/ folder containing the following:
      • export PATH=$PATH:[REPLACE THIS WITH THE FULL PATH TO THE ANDROID/TOOLS FOLDER FROM ABOVE]:[REPLACE THIS WITH THE FULL PATH TO THE ANDROID/PLATFORM-TOOLS FOLDER FROM ABOVE]
      • Ex: export PATH=$PATH:/usr/local/android/tools:/usr/local/android/platform-tools
  4. Create a temporary folder for Android, and set permissions so everyone can use it.
    • # mkdir /tmp/android
    • # chmod 777 /tmp/android
    1. Update the Android SDK with the latest SDK Platforms and APIs.
    • The Android SDK does not come with any development platforms, so you must add at least one before you can begin programming!
    • Run the android application within the \tools directory of the Android SDK installation.
      • Select Settings, and put a checkmark in the box next to Force https://... sources to be fetched using http://..., then click Save & Apply.
      • Select Installed Packages, click the Update All... button, wait for the sources to be refreshed, select the Accept All radio button, and click Install Accepted. Once this has finished, close the Android SDK and AVD Manager.
  5. Open Eclipse and update with the necessary Android Software
    • Within Eclipse, go to Help -> Software Updates.
    • Click on the Manage Sites... button.
      • Put a check in the box next to the Ganymede Update Site (http://download.eclipse.org/ganymede) and click OK.
    • In the text search box, type WST Common UI. Install the WST Common UI package.
    • After restarting Eclipse following the previous package installation, go back to Help -> Software Updates.
    • Click the Add Site... button, add the following two sites, and install all software contained within those sites.
      • http://dl-ssl.google.com/android/eclipse/
        • Plugin
          • Google Plugin for Eclipse 3.4
        • SDKs
          • Google App Engine Java SDK 1.3.0
          • Google Web Toolkit SDK 2.0.0
      • http://dl-ssl.google.com/android/eclipse/
        • Developer Tools
  6. After accepting and notices, installing the packages, and restarting Eclipse, you must set the Android SDK Location within Eclipse.
    • Within Eclipse, go to Window -> Preferences
    • Click on Android in the left column.
    • Enter the path to the Android SDK (ex.: /usr/local/android)
  7. You are now ready to start writing programs for Android!

After opening Eclipse, you may need to wait a short amount of time (1-2 minutes) for the Android SDK to be loaded; you can see the loading progress in the lower right hand corner of Eclipse.

For an example of a basic "Hello, World" program, see Hello World | Android Developers

[edit] More Information

Personal tools