Lesson 2
Android Development Tools =
Eclipse + ADT + SDK
VictorMatos ClevelandStateUniversity
PortionsofthispagearereproducedfromworkcreatedandsharedbyGoogleandusedaccordingtoterms describedintheCreativeCommons3.0AttributionLicense.
2.
DevelopmentEnvironment=Eclipse+ADT+SDK
• AndroidapplicationsareusuallycreatedusingtheJava programminglanguage[1]
• YourJavaprojectmustimportvariousAndroidLibraries(suchasandroid.jar, maps.jar,etc)togainthefunctionalityneededtoworkinsidetheAndroidOS. • EventhesimplestofAndroidappsiscomposedofseveralelementssuchas:
userͲdefinedclasses,androidjars,thirdͲpartylibraries,XMLfilesdefiningtheUIs orviews,multimediaresources,dataassetssuchasdiskfiles,externalarraysand strings,databases,andfinallyaManifest summarizingthe‘anatomy’and permissionsrequestedbytheapp.
• The package(s) holding the raw app components are given to the compiler toThepackage(s)holdingtherawappcomponentsaregiventothecompilerto obtainasinglesignedanddeployableAndroidPackage(an.apk file).
2.
DevelopmentEnvironment=Eclipse+ADT+SDK
• Creating,organizingandmanagingthecomponentsofanAndroidappis betterdoneusinga‘friendly’workbench. • TheAndroiddeveloper’sworkbenchtypicallyincludesthefollowingtools: 1 E li IDE 1. EclipseIDE 2. AndroidDevelopmentTools(ADT),and 3. AndroidSystemDevelopmentKit(SDK) • EclipseIDEallowsyoutocreateanddebugyourJavacode,andmanagethe variousresourcesthatnormallyareusedinthemakingofanAndroidapp. • TheADTplugin extendsEclipsesoyoucaneasilyreachthetoolsoftheSDK2.
DevelopmentEnvironment=Eclipse+ADT+SDK
TypicalLayoutoftheEclipseIDEforAndroidDevelopment(details…) Theseicons
areaddedto Eclipsebythe ADT plugin OpensAndroidSDKmanager O d id i l i ADTplugin 5 5 OpensDDMSPerspective Dalvik DebuggingMonitoringSystem
OpensAndroidAVD VirtualDevice Manager
Wizard createsanewAndroidProject
Note:TheDDMS andHierarchyViewcanbemanuallyaddedbytheusertoEclipse’stoolbar
2.
DevelopmentEnvironment=Eclipse+ADT+SDK
SETUP
Prepare
yourcomputer– InstallSDK:Windows,Mac,Linux
2.
DevelopmentEnvironment=Eclipse+ADT+SDK
Aside
Note:
SDKsarenamedafteradessert item.Availableversionsatthetimeofwriting are: 1.5Cupcake, 1.6Donut, 2.1Eclair, 2.2Froyo, 2.3Gingerbread[1], 3.xHoneycomb, 4.xIceCreamSandwich 7 7 [1]ByMarch2012Gingerbreadaccountedforapproximately66%oftheAndroidmarketshare. Seepage:http://www.appbrain.com/stats/topͲandroidͲsdkͲversions2.
DevelopmentEnvironment=Eclipse+ADT+SDK
SETUP
(a) UsersWantingtoUpdateanOlderAndroidWorkbench
2.
DevelopmentEnvironment=Eclipse+ADT+SDK
SETUP
(b)FirstTimeUsers(Windows,Mac,Linux)
1. InstalltheappropriateSDKstarterpackagefromthepage
http://developer.android.com/sdk/index.htmlp // p / /
2. InstalltheADTPlugin forEclipse
1. StartEclipse,thenselectHelp >InstallNewSoftware.... 2. ClickAdd button(topͲrightcorner)
3. InthenextdialogͲboxenter"ADTPlugin"fortheName andthefollowing URLfortheLocation:https://dlͲssl.google.com/android/eclipse/ 4. ClickOK
5 Select the checkbox next toDeveloper Toolsand click Next > Next
9 5. SelectthecheckboxnexttoDeveloperToolsandclickNext > Next
6. Acceptthelicenseagreements,thenclickFinish. 7. AftertheinstallationendyouneedtorestartEclipse. 3. AddAndroidplatformsandothercomponentstoyourSDK(seeprevious option(a)) 9
2.
DevelopmentEnvironment=Eclipse+ADT+SDK
ConfiguringtheADTPlugin ThenextstepistomodifyyourADTpreferencesinEclipsetopointtothe A d id SDK di t AndroidSDKdirectory:1. Select Window > Preferences... toopenthePreferencespanel (MacOSX: Eclipse > Preferences).
1. Select Android fromtheleftpanel.
2. Tosetthe boxSDKLocationthatappearsinthemainpanel, click Browse... andlocateyourdownloadedSDKdirectory(usually
c:/Program/ g Files(x86)/Android/androidͲsdk( )/ / )) 3. Click Apply,then OK.
2.
DevelopmentEnvironment=Eclipse+ADT+SDK
CreatinganAndroidVirtualDevice(AVD) Youshouldtestyourapplicationsonarealphone(ortablet). However,theSDKallowsyoutocreaterealisticvirtualdevicesonwhichyour li ti ld b t t d applicationscouldbetested. 1. Tocreateanemulator,clickontheAVDManager 2. Click New.The CreateNewAVD dialogappears. 3. TypethenameoftheAVD,suchas“NexusͲS" 4. Chooseatarget(suchas“GoogleAPIs…APILevel8”). 5. Indicatehowmuchmemorythesimulatorwilluse. 6 Tick option box “Snapshot” to load faster11 6. Tickoptionbox“Snapshot”toloadfaster.
7. Indicatescreensize(HVGAissufficientingeneral) 8. Optionallyspecifyanyadditionalhardwarecomponents
(suchasSDͲcard,camer,accelerometer,GPS,…) 9. Click CreateAVD.
2.
DevelopmentEnvironment=Eclipse+ADT+SDK
TestingtheEmulator ClickontheAVDManager.Chooseanemulator,clickStart. 13 13Android
SetupTutorial
Afteryoucompleteyoursetuplookforthefollowingtwosubdirectoriesin yourfilesystemC:\Program Files (x86)\Android\android-sdk
Appendix.
CreatinganAndroidProject
(madeforSDK2.2Ͳ Froyo) Anunabridgedversionof“HelloWorld”Testing
SetupͲ Example:HelloWorld
15
Testing
SetupͲ Example:HelloWorld
Creating
anAndroidProject
Tocreateanewproject: 1. StartEclipse
2. SelectFile >New >AndroidProject a
ll l 3. EnterProjectname:01ͲHelloͲWorld 4. ClickNext 5. OnSelectBuildTargetchooserow GoogleAPIsGoogleInc.2.28 6. ClickNext 7. OntheApplicationInfoformenter Pacakage Name:csu.matos
CheckboxCreateActivity Activity name: HelloActivity
OBSERVATION:CreatinganAndroidProjectusingEclipse
TheNewAndroidProjectWizardcreatesthefollowingfoldersandfilesinyournew projectspace:
Testing
SetupͲ Example:HelloWorld
• src/IncludesyourskeletonActivityJavafile.AllotherJavafilesforyour applicationgohere.
• <AndroidVersion>/(e.g.,Android2.2/)Includestheandroid.jarfilethatyour applicationwillbuildagainst.
• gen/ThiscontainstheJavafilesgeneratedbyADT,suchasyourR.javafile • assets/Thisisempty.Youcanuseittostorerawassetfiles.
• res/Thisfolderholdsapplicationresourcessuchasdrawable files,layout files, string al es et
17 string values,etc.
• bin/Thebytecode (.apk)versionofyourappisstoredhere • AndroidManifest.xmlTheAndroidManifestforyourproject.
• default.propertiesThisfilecontainsprojectsettings,suchasthebuildtarget.
Creating
anAndroid
Project
Testing
Setup–
Example:
HelloWorld
Project
Thefollowingfoldersandfiles arecreatedforthe 01ͲHelloͲWorldproject. Totesttheapplication,position thecursoronthecodepanel, andthenclickonthe
Volume StatusBar– NotificationLine Camera NumericID:5554 Hangup Home Call Power Search 19 19 Back Menu Tab Launch Pad
Android
Emulator
Keyboard OSfunction Escape Backbutton Home Homebutton F2,PageUp Menu(SoftͲLeft)button ShiftͲF2,PageDown Start(SoftͲRight)button F3 Call/Dial button ControllingtheAndroidEmulator through(yourcomputer’s) keyboardkeysKeypad keys only work when
F3 Call/Dialbutton F4 Hangup/EndCallbutton F5 Searchbutton F7 Powerbutton CtrlͲF3,CtrlͲKEYPAD_5 Camerabutton CtrlͲF5,KEYPAD_PLUS Volumeupbutton CtrlͲF6,KEYPAD_MINUS Volumedownbutton KEYPAD_5 DPadcenter KEYPAD_4 DPadleft KEYPAD_6 DPadright KEYPAD_8 DPad up KEYPAD 2 DP d d Keypadkeysonlyworkwhen NumLockisdeactivated. KEYPAD_2 DPaddown F8 togglecellnetworkon/off
F9 togglecodeprofiling(when Ͳtrace optionset) AltͲENTER toggleFullScreenmode