Android Software Development – The First Few HoursCoast Nerds – 15 March 2011Image: www.android.com
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 AvoidWhat is Android all about? Image: www.metalmickey.com
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)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++.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 dayImage:http://t3.gstatic.com/images?q=tbn:ANd9GcSGt5iAisqb6Do_Fj6PgF6xtvWjghsrEVmdwi-mRXmMDv8pCCCUImage: http://t1.gstatic.com/images?q=tbn:ANd9GcQyIOqpf4sm4__JsRfCE8bIoIh4ayh16VJkxHZ66tyFOF1cba_ZiA
Why did I choose this Platform?Image: www.popsiculturereviews.blogspot.com
The Alternatives
Apple iPhone
Windows Phone
Symbian
Research In Motion (RIM/Blackberry)
HP WebOS (Palm)
AndroidCanalysis – Worldwide Q4 2010
Apple iPhoneImage: http://www.esarcasm.com
Windows Phone 7Image: windowsphonejunky.com
SymbianImage: www.toptechviews.com
AndroidWhat do you need to get started developing Android Applications?Image: www.conspiracygrimoire.com
Install Java Development Kit (JDK) http://www.oracle.com/technetwork/java/javase/downloads/index.htmlInstall Eclipse for Java EE Developers* http://www.eclipse.org/downloads/Install the Android SDK http://developer.android.com/sdk/index.htmlWINDOWS: 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
Install and configure the Android Plug-in for Eclipse (ADT)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 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).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.  NOTE: Selecting all tools will take some time to download.Read and accept the license agreements, then click Finish.When the installation completes, restart Eclipse.More Details Here http://developer.android.com/sdk/eclipse-adt.html
Test InstallationIn Eclipse choose File -> New Project from the menu.You should see an option to create an Android Project and an Android Test Project
The SDK / AVD ManagerThe Android SDK is componentised allowing you to customise your development environment for your target platformThe 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.exeYou can also access the SDK Manager from within Eclipse by clicking on the toolbar icon as shown belowAVD = Android Virtual Device
SDK Manager showing Available packages to download
SDK Manager showing installed packages
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.
How to create your first App.  Hello World!Image:  www.jeffbots.com
Create the AppFrom the File Menu in Eclipse choose Create New ProjectThe New Project Dialog will open.  Choose Android Project and click Next
Enter Project NameChoose a Target Platform (if the list of platforms are blank you will need to use the SDK Manager to install some for your PC).Enter PropertiesApplication NamePackage NameEnsure “Create Activity” is checked and enter the default Activity Name.Enter the Min SDK VersionClick Next
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!)Click FinishAt this point your Hello World Application is done.  By default a simple “Hello World” app is created.
Explore the Application ManifestFrom 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.The Application Manifest is the main configuration point for you app.  Here you can control versioning, register activities and security (among other things).
View the Layout ResourceFrom the Package Explorer, expand out the project folder for you app.  Then expand out res=>layout, then double click on main.xml.Layout resources define the layout of the various screens in your app.  A default main.xml layout is created but you can create others.You can edit the layout using the designer or switch to xml view.
ResourcesIf 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.You can view and edit the string resource to change the value of the text displayed.In the Package Explorer navigate to res=>values=>strings.xmlYou 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
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.  Create an AVDLaunch the SDK/AVD Manager (discussed in an earlier slide).Click on the New buttonFill out the details as shown (creating an Android 2.1 target)Click “Create AVD”It will take a couple of minutes to create the AVD.  Your AVD should be shown in the list on completion.
Create a Debug ConfigurationFrom the Run menu choose Debug Configurations…Choose “Android Application” from the list and then click on the New button at the top of the screen.Give your Debug Configuration a name and click Browse to select your app’s project
Create a Debug Configuration cont…Click on the Target tabChoose Automatic Choose an AVD (you should see the AVD you created earlier in the list)Click Apply

Android software development – the first few hours

  • 1.
    Android Software Development– The First Few HoursCoast Nerds – 15 March 2011Image: www.android.com
  • 2.
    What am Igoing to talk about?What is Android all about?
  • 3.
    Why did Ichoose this platform?
  • 4.
    What do youneed to get started developing Android Applications?
  • 5.
    How to createyour first App?
  • 6.
  • 7.
    Things to AvoidWhatis Android all about? Image: www.metalmickey.com
  • 8.
    Android is anOpen Source “Software Stack” targeted at mobile devices.
  • 9.
    Built on modifiedversion of the Linux Kernel
  • 10.
    Android Inc. foundedin 2003. Purchased by Google in 2005 as wholly owned subsidiary
  • 11.
    The Open HandsetAlliance (est. 2007) collaborated on development, release and on-going maintenance/development.
  • 12.
  • 13.
    First Android MobilePhone: T-Mobile G1 (or HTC Dream) Released October 2008
  • 14.
    Android consists ofJava Applications running on Java core libraries running on a Dalvic Virtual Machine. Some core libraries also written in C/++
  • 15.
    Consists of 12million 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++.Q2 2009 Android had 2.8% share of Worldwide handset shipments
  • 16.
    Grew to 33%by Q4 2010
  • 17.
    In February 2011Android has reached 350,000 activations per dayImage:http://t3.gstatic.com/images?q=tbn:ANd9GcSGt5iAisqb6Do_Fj6PgF6xtvWjghsrEVmdwi-mRXmMDv8pCCCUImage: http://t1.gstatic.com/images?q=tbn:ANd9GcQyIOqpf4sm4__JsRfCE8bIoIh4ayh16VJkxHZ66tyFOF1cba_ZiA
  • 18.
    Why did Ichoose this Platform?Image: www.popsiculturereviews.blogspot.com
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
    Research In Motion(RIM/Blackberry)
  • 24.
  • 25.
  • 26.
  • 27.
    Windows Phone 7Image:windowsphonejunky.com
  • 28.
  • 29.
    AndroidWhat do youneed to get started developing Android Applications?Image: www.conspiracygrimoire.com
  • 30.
    Install Java DevelopmentKit (JDK) http://www.oracle.com/technetwork/java/javase/downloads/index.htmlInstall Eclipse for Java EE Developers* http://www.eclipse.org/downloads/Install the Android SDK http://developer.android.com/sdk/index.htmlWINDOWS: 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
  • 31.
    Install and configurethe Android Plug-in for Eclipse (ADT)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 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).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. NOTE: Selecting all tools will take some time to download.Read and accept the license agreements, then click Finish.When the installation completes, restart Eclipse.More Details Here http://developer.android.com/sdk/eclipse-adt.html
  • 32.
    Test InstallationIn Eclipsechoose File -> New Project from the menu.You should see an option to create an Android Project and an Android Test Project
  • 33.
    The SDK /AVD ManagerThe Android SDK is componentised allowing you to customise your development environment for your target platformThe 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.exeYou can also access the SDK Manager from within Eclipse by clicking on the toolbar icon as shown belowAVD = Android Virtual Device
  • 34.
    SDK Manager showingAvailable packages to download
  • 35.
    SDK Manager showinginstalled packages
  • 36.
    Android SDK SupportedOperating 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.
  • 37.
    How to createyour first App. Hello World!Image: www.jeffbots.com
  • 38.
    Create the AppFromthe File Menu in Eclipse choose Create New ProjectThe New Project Dialog will open. Choose Android Project and click Next
  • 39.
    Enter Project NameChoosea Target Platform (if the list of platforms are blank you will need to use the SDK Manager to install some for your PC).Enter PropertiesApplication NamePackage NameEnsure “Create Activity” is checked and enter the default Activity Name.Enter the Min SDK VersionClick Next
  • 40.
    The next screenasks about creating a test project for your application. At this stage ignore this option and click next (… sorry to the TDD faithful!)Click FinishAt this point your Hello World Application is done. By default a simple “Hello World” app is created.
  • 41.
    Explore the ApplicationManifestFrom 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.The Application Manifest is the main configuration point for you app. Here you can control versioning, register activities and security (among other things).
  • 42.
    View the LayoutResourceFrom the Package Explorer, expand out the project folder for you app. Then expand out res=>layout, then double click on main.xml.Layout resources define the layout of the various screens in your app. A default main.xml layout is created but you can create others.You can edit the layout using the designer or switch to xml view.
  • 43.
    ResourcesIf you viewthe 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.You can view and edit the string resource to change the value of the text displayed.In the Package Explorer navigate to res=>values=>strings.xmlYou 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
  • 44.
    Debug & RunYour App
  • 45.
    Before you canrun 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. Create an AVDLaunch the SDK/AVD Manager (discussed in an earlier slide).Click on the New buttonFill out the details as shown (creating an Android 2.1 target)Click “Create AVD”It will take a couple of minutes to create the AVD. Your AVD should be shown in the list on completion.
  • 46.
    Create a DebugConfigurationFrom the Run menu choose Debug Configurations…Choose “Android Application” from the list and then click on the New button at the top of the screen.Give your Debug Configuration a name and click Browse to select your app’s project
  • 47.
    Create a DebugConfiguration cont…Click on the Target tabChoose Automatic Choose an AVD (you should see the AVD you created earlier in the list)Click Apply
  • 48.
    Launch/Debug your appwith the emulatorWith 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)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.
  • 50.
    Playing with theEmulatorUse the Emulator Control Window to simulate phone calls or text messages.If you cannot see the Emulator Control Window, choose Window from the menu then Show View=>Other=>Android=>Emulator ControlNB. Mobile phone numbers should not contain spaces.
  • 51.
    Launch/Debug your appwith your Android phone or mobile deviceYou 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:Close Eclipse if it is openConnect the phone to your PC via the USB CableOpen Settings (on the phone)Choose ApplicationsChoose DevelopmentEnable USB DebuggingEnable Stay AwakeNB. The first time you do this you may have to install additional driver software to you PC.
  • 52.
    Launch/Debug your appwith your Android phone or mobile deviceYou 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:Close Eclipse if it is openConnect the phone to your PC via the USB CableOpen Settings (on the phone)Choose ApplicationsChoose DevelopmentEnable USB DebuggingEnable Stay AwakeNB. The first time you do this you may have to install additional driver software to you PC.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
  • 53.
    Launch/Debug your appwith your Android phone or mobile device cont…Open your app project in EclipseGo to the Debug Configuration (created in an earlier slide)Click on the Target TabChoose ManualClick on the Debug buttonYou will be prompted to choose an Android device. 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)Select your phone from the listClick OKAfter 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.
  • 54.
    Launch/Debug your appwith your Android phone or mobile device cont…Choosing your phone from the Debug Configuration
  • 55.
    Launch/Debug your appwith your Android phone or mobile device cont…
  • 56.
    Note that youdo not need to stop the debugger or close the application in any way from Eclipse.
  • 57.
    When finished debuggingsimply 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.
  • 58.
    You may findthat your app is still installed on your phone. Uninstall it if required.Things to avoidImage: http://www.lz95.net/lzhs/english/isilverman/policies.htm
  • 59.
    The standard Eclipsefor 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.
  • 60.
    While the standardinstall will still work you will need to download more add-ins to start developing. 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.)Where to next?Image: www.heightofhappiness.wordpress.com
  • 61.
    In a futurepresentation I will discuss:
  • 62.
    Debugging using theDalvik Debug Monitor Service (DDMS). This is a more advanced debugging tool that give you more visibility and control over the debugging process.
  • 63.
    Application Design –Context, Activities and Intents. These are the main building blocks to an Android app. This is where the actual coding begins!
  • 64.
    More on Resourcesand State management. Using images and how to store app/user settings.
  • 65.
    Anything else Ican fit in.Questions?Image: www.alaskacommons.wordpress.com
  • 66.

Editor's Notes

  • #5 Software/Solution Stack – OS, Middleware + Key ApplicationsOpen Handset Alliance consists of 80 firms including Google, HTC, Dell, Intel, Motorola, Qualcomm, Texas Instruments, Samsung, LG, T-Mobile, Nvidia, and Wind River Systems.[
  • #6 - Dalvic Virtual Machine also Open Source. Uses different bytecode to standard Java VM. Based on the Apache implementation of Java. - In 2010 Oracle sued Google of infringing it’s Intellectual Property on several patents.- C libraries include Surface manager, SQLite and OpenGL graphics engines
  • #8 - Dalvic Virtual Machine also Open Source. Uses different bytecode to standard Java VM. Based on the Apache implementation of Java. - In 2010 Oracle sued Google of infringing it’s Intellectual Property on several patents.- C libraries include Surface manager, SQLite and OpenGL graphics engines
  • #10 Another survey by Gartner puts Symbian ahead but forecasts Android to lead by 2014.
  • #11 http://www.computerworld.com/s/article/9178684/Developing_for_the_iPhone_and_Android_The_pros_and_cons?taxonomyId=18&pageNumber=2http://developer.apple.com/programs/ios/
  • #12 Feb 2011 Nokia and Microsoft announced strategic partnership which sees Windows Phone 7 as Nokia’s primary OS.http://social.msdn.microsoft.com/Forums/en/mktplace/thread/4b727251-7089-4261-8928-1a218f96a300http://blogs.computerworld.com/16622/windows_phone_7s_achilles_heel_no_enterprise_app_deployment_toolhttp://www.zdnet.co.uk/news/mobile-apps/2010/10/21/microsoft-hints-at-windows-phone-7-enterprise-future-40090605/
  • #13 http://pocketnow.com/windows-phone/nokia-undertaking-two-year-plan-for-wp7-transition-symbian-gone-by-2013
  • #14 http://pocketnow.com/windows-phone/nokia-undertaking-two-year-plan-for-wp7-transition-symbian-gone-by-2013
  • #16 Eclipse for Java EE Developers contains additional plug-ins including the Java Development Tools (JDT) for eclipse as well as the Web Tools Platform (WTP)
  • #17 Eclipse for Java EE Developers contains additional plug-ins including the Java Development Tools (JDT) for eclipse as well as the Web Tools Platform (WTP)
  • #18 Eclipse for Java EE Developers contains additional plug-ins including the Java Development Tools (JDT) for eclipse as well as the Web Tools Platform (WTP)
  • #19 Eclipse for Java EE Developers contains additional plug-ins including the Java Development Tools (JDT) for eclipse as well as the Web Tools Platform (WTP)