android software development – the first few hours

47
Coast Nerds – 15 March 2011 Android Software Development – The First Few Hours Image: www.android.com

Upload: sjmarsh

Post on 17-May-2015

1.581 views

Category:

Technology


2 download

DESCRIPTION

My challenge for this year is to learn a new programming language or software development technology. While I don’t intend adopting the suggestion of The Pragmatic Programmer and learning one new language each year, I do think that there is much to be gained by seeing what else is out there. With the booming popularity of the Android platform for mobile devices I thought what better place to start? Over the past few weeks I have taken the first few steps in learning about Android application development.

TRANSCRIPT

Page 1: Android software development – the first few hours

Coast Nerds – 15 March 2011

Android Software Development – The First Few Hours

Image: www.android.com

Page 2: Android software development – the first few hours

What am I going to talk about?

• What is Android all about?• Why did I choose this platform?• What do you need to get started

developing Android Applications?• How to create your first App?• Where to Next?• Things to Avoid

Page 3: Android software development – the first few hours

What is Android all about?

Image: www.metalmickey.com

Page 4: Android software development – the first few hours

• Android is an Open Source “Software Stack” targeted at mobile devices.

• Built on modified version of the Linux Kernel

• Android Inc. founded in 2003. Purchased by Google in 2005 as wholly owned subsidiary

• The Open Handset Alliance (est. 2007) collaborated on development, release and on-going maintenance/development.

• Ref http://en.wikipedia.org/wiki/Android_(operating_system)

Page 5: Android software development – the first few hours

• Android SDK first released to developers in November 2007

• First Android Mobile Phone: T-Mobile G1 (or HTC Dream) Released October 2008

• Android consists of Java Applications running on Java core libraries running on a Dalvic Virtual Machine. Some core libraries also written in C/++

• Consists of 12 million lines of code including 3 million lines of XML, 2.8 million lines of C, 2.1 million lines of Java, and 1.75 million lines of C++.

Page 6: Android software development – the first few hours

• Q2 2009 Android had 2.8% share of Worldwide handset shipments

• Grew to 33% by Q4 2010

• In February 2011 Android has reached 350,000 activations per day

Platform API Level Distribution

Android 2.3 (Gingerbread) 9/10 0.8%

Android 2.2 (Froyo) 8 57.6%

Android 2.0/2.1 (Eclair) 7 31.4%

Android 1.6 (Donut) 4 6.3%

Android 1.5 (Cupcake) 3 3.9%

Page 8: Android software development – the first few hours

Why did I choose this Platform?

Image: www.popsiculturereviews.blogspot.com

Page 9: Android software development – the first few hours

• The Alternatives• Apple iPhone• Windows Phone• Symbian• Research In Motion

(RIM/Blackberry)• HP WebOS (Palm)• Android

Canalysis – Worldwide Q4 2010

Page 10: Android software development – the first few hours

• Apple iPhonePros Cons

Large market share and brand familiarity/loyalty

Only 16% market share (½ of Android / Symbian)

Single Platform target development (Closed System)

Closed System – less flexibility, limited to the capabilities of the iPhone

Well defined capabilities and limitations

Objective C programming language (primarily used on Apple only). MacOS Only.

Can also target iPad Java and Flash not supported

Apps can only be published through App Store.

$99.00 Annual Subscription to distribute apps through the App Store.

Developer only gets 70% of sale revenue.

Image: http://www.esarcasm.com

Page 11: Android software development – the first few hours

• Windows Phone 7Pros Cons

Familiar platform for a .Net Developer

Minute market share. Lot of catching up to do.

Silverlight/XNA Framework. Well documented and supported.

Marketplace is only method to publish apps. (Future releases may support enterprise development).

Compatibility with MS Windows/Office which still dominate the desktop market

$99.00 Annual Subscription to distribute apps through Windows Phone Marketplace

Nokia Partnership looks promising

MS get 30% commission per paid app.

Only 5 free apps per year – then $19.00 each

Image: windowsphonejunky.com

Page 12: Android software development – the first few hours

• SymbianPros Cons

Well established mobile OS and Long-time Market dominance.

Nokia plans to phase out Symbian by 2013. Symbian is open source but is maintained by Nokia.

Wide range of development platforms inc. Nokia Qt, C/++, Java, Flash and Web

Using the Ovi Store (primary app. Store) Developer only gets 60-70% of revenue.

Variety of distribution methods – not limited to app store.

Image: www.toptechviews.com

Page 13: Android software development – the first few hours

• AndroidPros Cons

Market Leader (… or soon to be).

Many active versions – 1.6 through to 2.3 (and soon 3.0)

Open system. Not limited to a particular hardware device. Can target features of specific hardware. Not just for mobile phones.

Open system means it can be difficult to ensure your app will work on all devices.

Well documented API using Java. Can also use C/++. Also MonoDroid (.net for Android)

Using the Market Place developer only gets 70% of sales revenue

Variety of distribution methods – not limited to market place.

Developer/Testing capabilities on handsets with Android OS

Page 14: Android software development – the first few hours

What do you need to get started

developing Android Applications?

Image: www.conspiracygrimoire.com

Page 15: Android software development – the first few hours

1. Install Java Development Kit (JDK) http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. Install Eclipse for Java EE Developers* http://www.eclipse.org/downloads/

3. Install the Android SDK http://developer.android.com/sdk/index.html

- WINDOWS: Upgrade the Path Environment Variable to include the Android Tools directory.

* Eclipse is the most common IDE for Android Development but there are others. See developer.android.com/guide/developing/other-ide.html

Page 16: Android software development – the first few hours

4. Install and configure the Android Plug-in for Eclipse (ADT)

i. Start Eclipse, then select Help > Install New Software....ii. Click Add, in the top-right corner.iii. In the Add Repository dialog that appears, enter "ADT Plugin" for the

Name and the following URL for the Location: https://dl-ssl.google.com/android/eclipse/ Note: If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).

iv. Click OK.v. In the Available Software dialog, select the checkbox next to Developer

Tools and click Next.vi. In the next window, you'll see a list of the tools to be downloaded.

Click Next. NOTE: Selecting all tools will take some time to download.vii. Read and accept the license agreements, then click Finish.viii. When the installation completes, restart Eclipse.

More Details Here http://developer.android.com/sdk/eclipse-adt.html

Page 17: Android software development – the first few hours

5. Test Installationi. In Eclipse choose File -> New Project from the

menu.ii. You should see an option to create an Android

Project and an Android Test Project

Page 18: Android software development – the first few hours

6. The SDK / AVD Manageri. The Android SDK is componentised allowing you

to customise your development environment for your target platform

ii. The SDK Manager allows you to manage components for your specific requirements. It is located in the sdk folder (installed at step 3) android-sdk-windows\SDK Manager.exe

iii. You can also access the SDK Manager from within Eclipse by clicking on the toolbar icon as shown below

AVD = Android Virtual Device

Page 19: Android software development – the first few hours

SDK Manager showing Available packages to download

Page 20: Android software development – the first few hours

SDK Manager showing installed packages

Page 21: Android software development – the first few hours

Android SDK Supported Operating SystemsWindows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit)Mac OS X 10.5.8 or later (x86 only)Linux (tested on Ubuntu Linux, Lucid Lynx)

GNU C Library (glibc) 2.7 or later is required.On Ubuntu Linux, version 8.04 or later is required.64-bit distributions must be capable of running 32-bit applications. For information about how to add support for 32-bit applications, see the Ubuntu Linux installation notes.

Page 22: Android software development – the first few hours

How to create your first App.

Hello World!

Image: www.jeffbots.com

Page 23: Android software development – the first few hours

1. From the File Menu in Eclipse choose Create New Project

2. The New Project Dialog will open. Choose Android Project and click Next

• Create the App

Page 24: Android software development – the first few hours

3. Enter Project Name4. Choose a Target Platform (if

the list of platforms are blank you will need to use the SDK Manager to install some for your PC).

5. Enter Propertiesi. Application Nameii. Package Nameiii. Ensure “Create Activity”

is checked and enter the default Activity Name.

iv. Enter the Min SDK Version

6. Click Next

Page 25: Android software development – the first few hours

7. The next screen asks about creating a test project for your application. At this stage ignore this option and click next (… sorry to the TDD faithful!)

8. Click Finish9. At this point your Hello

World Application is done. By default a simple “Hello World” app is created.

Page 26: Android software development – the first few hours

• Explore the Application Manifest1. From the Package Explorer, expand out the project folder

for you app. Application Manifest is at the root level. Double click on it to open the dialog.

2. The Application Manifest is the main configuration point for you app. Here you can control versioning, register activities and security (among other things).

Page 27: Android software development – the first few hours

• View the Layout Resource1. From the Package Explorer, expand out the project folder

for you app. Then expand out res=>layout, then double click on main.xml.

2. Layout resources define the layout of the various screens in your app. A default main.xml layout is created but you can create others.

3. You can edit the layout using the designer or switch to xml view.

Page 28: Android software development – the first few hours

• Resources1. If you view the properties for the “Hello

World” text box shown on the layout you will notice that the text is not hardcoded and in fact points to a string resource.

2. You can view and edit the string resource to change the value of the text displayed.

3. In the Package Explorer navigate to res=>values=>strings.xml

4. You can view the string resources in a dialog view or in xml. You will also notice that a resource has been created for the app name

Page 29: Android software development – the first few hours

• Debug & Run Your App• Before you can run your app for the first

time you need to create a debug configuration and also an Android Virtual Device (AVD). An AVD is just a virtual target platform that can be used in the emulator. AVDs can be shared between apps so this may be a one-off process until you start needing more varied AVDs to work with.

Page 30: Android software development – the first few hours

• Create an AVD1. Launch the SDK/AVD

Manager (discussed in an earlier slide).

2. Click on the New button3. Fill out the details as

shown (creating an Android 2.1 target)

4. Click “Create AVD”5. It will take a couple of

minutes to create the AVD. Your AVD should be shown in the list on completion.

Page 31: Android software development – the first few hours

• Create a Debug Configuration1. From the Run menu

choose Debug Configurations…

2. Choose “Android Application” from the list and then click on the New button at the top of the screen.

3. Give your Debug Configuration a name and click Browse to select your app’s project

Page 32: Android software development – the first few hours

• Create a Debug Configuration cont…4. Click on the Target tab5. Choose Automatic 6. Choose an AVD (you should see the AVD you

created earlier in the list)7. Click Apply

Page 33: Android software development – the first few hours

• Launch/Debug your app with the emulator

8. With the debug configuration screen still open click on “Debug”. Note you can also launch the debugger from the debug button on the toolbar (be sure to select the correct configuration from the drop-down list)

9. This will launch the emulator and run your app. Note this will take a few minutes the first time you run it in a particular session of Eclipse.

Page 34: Android software development – the first few hours
Page 35: Android software development – the first few hours

• Playing with the Emulator

1. Use the Emulator Control Window to simulate phone calls or text messages.

2. If you cannot see the Emulator Control Window, choose Window from the menu then Show View=>Other=>Android=>Emulator Control

3. NB. Mobile phone numbers should not contain spaces.

Page 36: Android software development – the first few hours

• Launch/Debug your app with your Android phone or mobile device

1. You need to ensure your Android Device is set to Debug mode. You may need to refer to your user manual for more details on how to do this. In my example I followed these steps:

i. Close Eclipse if it is openii. Connect the phone to your PC via the USB Cableiii. Open Settings (on the phone)iv. Choose Applicationsv. Choose Developmentvi. Enable USB Debuggingvii. Enable Stay Awakeviii. NB. The first time you do this you may have to install additional

driver software to you PC.

Page 37: Android software development – the first few hours

• Launch/Debug your app with your Android phone or mobile device

1. You need to ensure your Android Device is set to Debug mode. You may need to refer to your user manual for more details on how to do this. For my phone I followed these steps:

i. Close Eclipse if it is openii. Connect the phone to your PC via the USB Cableiii. Open Settings (on the phone)iv. Choose Applicationsv. Choose Developmentvi. Enable USB Debuggingvii. Enable Stay Awakeviii. NB. The first time you do this you may have to install additional

driver software to you PC.ix. You may also need to add the Google USB Driver package via the

SDK Manager (on your PC) if it has not already been installed

Page 38: Android software development – the first few hours

• Launch/Debug your app with your Android phone or mobile device cont…

2. Open your app project in Eclipse3. Go to the Debug Configuration (created in an earlier slide)4. Click on the Target Tab5. Choose Manual6. Click on the Debug button7. You will be prompted to choose an Android device. 8. Hopefully you will see your phone listed (or something

that resembles it) in the “Choose a running Android device” section (if you don’t you may need to check connections or driver installations)

9. Select your phone from the list10. Click OK11. After a short while your app should appear loaded on

your phone. You should also see an icon for your app amongst all your other installed apps.

Page 39: Android software development – the first few hours

• Launch/Debug your app with your Android phone or mobile device cont…

Choosing your phone from the Debug Configuration

Page 40: Android software development – the first few hours

• Launch/Debug your app with your Android phone or mobile device cont…

• Note that you do not need to stop the debugger or close the application in any way from Eclipse.

• When finished debugging simply go back to your phone and disable the debugging features (enabled in the previous slide) then continue to disconnect your phone in the normal manor.

• You may find that your app is still installed on your phone. Uninstall it if required.

Page 41: Android software development – the first few hours

Things to avoid

Image: http://www.lz95.net/lzhs/english/isilverman/policies.htm

Page 42: Android software development – the first few hours

• The standard Eclipse for Java Developer installation does not include all the necessary components for Android Development. For new installations it is better to download and install the Eclipse for Java EE Developers.

• While the standard install will still work you will need to download more add-ins to start developing.

Page 43: Android software development – the first few hours

• When debugging be sure to use the correct debug configuration. Failing to do so can sometimes add an extra resource file to your project and cause a build error. (I have yet to investigate the cause of this issue. There may be a valid reason.)

Page 44: Android software development – the first few hours

Where to next?

Image: www.heightofhappiness.wordpress.com

Page 45: Android software development – the first few hours

• In a future presentation I will discuss:• Debugging using the Dalvik Debug Monitor Service

(DDMS). This is a more advanced debugging tool that give you more visibility and control over the debugging process.

• Application Design – Context, Activities and Intents. These are the main building blocks to an Android app. This is where the actual coding begins!

• More on Resources and State management. Using images and how to store app/user settings.

• Anything else I can fit in.

Page 46: Android software development – the first few hours

Questions?

Image: www.alaskacommons.wordpress.com

Page 47: Android software development – the first few hours

That’s All.

Image: www.blogs.eveningsun.com