2013 Introduction to Android Development Keshav Bahadoor An basic guide to setting up and building native Android applications Science Technology Workshop & Exposition University of Nigeria, Nsukka Keshav Bahadoor Software Developer, Software House Ltd 6/18/2013 www.keshav.ocsdev.org
Table of Contents 1. Terms and Definitions...3 2. Overview...3 3. Setting up... 3 3.1 Installing the Java JDK...3 3.2 Installing the Android ADT Bundle... 4 3.3 Setting up the Android Development Environment...4 3.3.1 Select the Workspace...5 3.3.2 Welcome Screen... 5 3.3.3 Eclipse overview... 6 4. Running Example Android Applications... 8 4.1 Importing existing Android projects into Eclipse... 8 4.2 Setting up the Android Emulator...12 4.3 Running a Project...16 5. Further Reading...17 2 P a g e
1. Terms and Definitions This section presents some common technological jargon and their explanations. Term Native Application Application Operating System Cross platform IDE SDK Definition An application that is made to run on solely on a particular operating system, such as Android or ios. The software or product that is created to run on mobile devices or computers. The idea of writing code once and having it work across all platforms or operating systems / devices. Integrated Development Environment Software Development Kit 2. Overview Android applications can be created in the following ways: 1. Programming the application specifically for Android devices using the Android SDK (Software Development Kit) and a development environment such as Eclipse. 2. Using an app building tool such as App Inventor (insert link). 3. Programming a solution that works across all platforms or devices, using a cross platform tools (PhoneGap, LibGDX, etc). This document will focus on the first way of creating Android applications. 3. Setting up This section provides a guide to install and setup the software required for building Android applications. 3.1 Installing the Java JDK The Java JDK or Java Development Kit is a release of Java that is aimed at software developers. It is used for developing Java based applications using the Java programming language. The Java JDK can be found at: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html There are two versions of the Java JDK available for the Windows platform, the 32 bit (x86) version and the 64 bit version. Install the version of the JDK that is compatible with your computer. 3 P a g e
To find out if your Windows computer is 32bit or 64bit: Right click on My Computer then select Properties. The version should be displayed here. 3.2 Installing the Android ADT Bundle The android ADT or Android Development Tools bundle is an integrated development environment for the use creation of Android applications. It is a customized version of the Eclipse Integrated Development Environment (IDE). Note on Eclipse Eclipse IDE is a tool that allows you to create various types of Java based applications, including Android applications. It facilitates the creation of projects, adding and deleting of files to the projects, and the editing of code. The ADT Bundle can be downloaded at: http://developer.android.com/sdk/index.html Ensure that you download the correct version of the ADT Bundle (32 bit or 64 bit). After downloading the ADT bundle, it will need to be extracted. This can be done by using winzip, winrar, or 7-zip. You can download 7-zip from here: http://www.7-zip.org/download.html 3.3 Setting up the Android Development Environment After you have installed the Java JDK and the ADT Bundle, you can now open the Eclipse folder and run Eclipse by double clicking on the eclipse icon. 4 P a g e
3.3.1 Select the Workspace When launched, Eclipse will then ask you to select a workspace. The workspace is a location on your computer that Eclipse will use to store all your projects and applications. You can leave the default workspace that Eclipse suggests. You may also select the option Use this as the default and do not ask again. This option tells Eclipse that you will be working with that location always. Note that you can change the workspace at anytime if you wish. Click the OK button to start Eclipse. 3.3.2 Welcome Screen The following screen will be shown. 5 P a g e
Click close button to proceed You may read the welcome note, and then click the close button to proceed. 3.3.3 Eclipse overview The following is an overview of the main windows of the Eclipse environment. 6 P a g e
Package Explorer Code Area Console Memory usage Package Explorer Shows your current packages, projects or applications that you are working on. Code Area Area to edit code files. Console This area displays to the user output, warnings and other messages. Memory Usage Displays the amount of memory Eclipse is currently using. 7 P a g e
4. Running Example Android Applications You can visit the following website to download the android application examples that were covered during the workshop. http://keshav.ocsdev.org/mlearning/ 4.1 Importing existing Android projects into Eclipse Download the Anroid Application Examples zip file, and extract the contents to your computer. You may use winzip, winrar or 7-zip to extract the files. Now, open Eclipse if not already opened. Click File from the top menu bar, and then select the Import menu option. In the resulting dialog box, expand the General folder, and select the Existing Projects into Workspace option. 8 P a g e
Click on the Next button to proceed. In the resulting dialog window, click the Browse button next to Select root directory. Use the resulting file browser to select the Android Application Examples folder that you have extracted. 9 P a g e
Click on the OK button. You should now see the GuessingGame and SpellingGame projects listed in the Projects area as shown below. 10 P a g e
Ensure that both projects are checked. If they are not checked, click the checkbox next to the projects. Next, ensure that the Copy projects into workspace option is checked. This option instructs Eclipse to copy the projects into the workspace. If this is not selected, Eclipse will use the projects from the location specified earlier. It is recommended to copy the projects into workspace to avoid unwanted changes or file deletions to the original projects. After the projects have been imported, they should be visible in the Project Explorer window of Eclipse, as seen below. 11 P a g e
Imported Projects 4.2 Setting up the Android Emulator The Android emulator allows you to emulate an Android device on the computer. This enables you to test or debug Android applications without using a physical Android mobile handset. The main disadvantage of the Android emulator is that it performs much slower than a physical Android device. The Android emulator can be setup as follows. Click Window from the top menu options then select Android Virtual Device Manager (also referred to as the AVD Manager). 12 P a g e
The resulting dialog box that opens is the Android Virtual Device manager (see below). It lists the virtual devices or Android Emulators that are created. For a new installation of Eclipse, there will be no virtual devices. 13 P a g e
A new virtual device or Android emulator must be created by clicking on the New button. The following dialog box will open. 14 P a g e
In this dialog box, you must give the Android virtual device a name. Type the name you want in the AVD Name field. In this example the name AndroidEMU was used. Next, a Device should be specified. This is the virtual android mobile device that the AVD manager will create for you. It is based on some common screen sizes available to consumers. Target sets the version of the Android Operating system you wish you emulate. For now you will leave this as the default setting. The Use Host GPU option at the bottom is a new feature that attempts to produce better performance for the emulator by using various components on your computer. For now you will leave this option unchecked. When you have finished setting up your Android virtual device, click the OK button. The window will close and your Android virtual device will be present on the list of devices available on the AVD manager, as seen below. 15 P a g e
To run the Android virtual device, select it from the AVD list, then click the Start.. button. A window that resembles an android mobile smart phone will appear. It is common for the Android virtual device to take a couple minutes to start. 4.3 Running a Project A project present in the Package Explorer of Eclipse. You can run projects by right clicking on the required project from the Package Explorer, then selecting Run As Android Application. 16 P a g e
5. Further Reading The following is a great video resource on building Android applications using the Java programming language. It is aimed at beginners. Although some things may be outdated, I highly recommend using these videos. http://thenewboston.org/list.php?cat=6 There is a lot of information on the Android Developers official website which will be very useful. http://developer.android.com/index.html 17 P a g e