Now, lei us gei you sei up wiil ile pieces and paiis necessaiy io build an Andioid app.
NOTE: Tle insiiuciions piesenied leie aie accuiaie as of ile iime of ilis wiiiing. Howevei, ile iools clange iapidly, and so ilese insiiuciions may be oui of daie by ile iime you iead ilis. Please iefei io ile Andioid Developeis Web siie foi cuiieni insiiuciions, using ilis as a base guideline of wlai io expeci.
Step #1 - Checking Your Hardware Requirements
Compiling and building an Andioid applicaiion, on iis own, is noi especially laidwaie-iniensive, excepi foi veiy laige piojecis. Howevei, ileie aie iwo commonly-used iools ilai demand moie fiom youi developmeni macline: Eclipse and ile Andioid emulaioi. Of ile iwo, ile emulaioi poses ile biggei pioblem.
Tle moie RAM you lave, ile beiiei. GB oi liglei is a veiy good idea if you iniend io use Eclipse and ile emulaioi iogeilei.
A fasiei CPU is also a good idea. Howevei, ile Andioid emulaioi only uiilizes a single coie fiom youi developmeni macline. Hence, ii is ile single-coie speed ilai maiieis. Tle besi CPU io use is one ilai can leveiage muliiple coies io give wlai amounis io a fasiei single coie, sucl as Iniel's Coie iy wiil Tuibo Boosi. Foi an emulaioi simulaiing a laigei-scieened device (e.g., iablei, ielevision), a Coie iy ilai can "boosi" up io .(GHz males developmeni mucl moie pleasani. Conveisely, a CPU lile a Coie : Duo wiil a :.GHz clocl speed iesulis in a iablei emulaioi ilai is neaily unusable. Smallei scieens (e.g., plones) can iun accepiably on :.GHz and (sliglily) slowei CPUs. 16 TUTORIAL #1 - INSTALLING THE TOOLS
Step #2 - Setting Up Java
Wlen you wiiie Andioid applicaiions, you iypically wiiie ilem in }ava souice code. Tlai }ava souice code is ilen iuined inio ile siuff ilai Andioid aciually iuns (Dalvil byiecode in an APK file).
Hence, ile fiisi iling you need io do is gei sei up wiil a }ava developmeni enviionmeni and be ieady io siaii wiiiing }ava classes.
Install the JDK
You need io obiain and insiall ile official Sun]Oiacle }ava SE SDK (}DK). You can obiain ilis fiom ile Oiacle }ava Web siie foi Windows and Linux, and piesumably fiom Apple foi OS X. Tle plain }DK (sans any "bundles") slould suffice. Follow ile insiiuciions supplied by Oiacle oi Apple foi insialling ii on youi macline. Ai ile iime of ilis wiiiing, Andioid suppoiis }ava 6 and }ava y, ilougl ile laiiei will iequiie you io configuie youi IDE io compile youi }ava code io }ava 6 byiecode.
Andioid also suppoiis ile Open}DK, paiiiculaily on Linux enviionmenis.
Wlai Andioid does not suppoii aie any oilei }ava compileis, including ile GNU Compilei foi }ava (GC}).
Step #3 - Install the Android SDK
Tle Andioid SDK gives you all ile iools you need io cieaie and iesi Andioid applicaiions. Ii comes in iwo paiis: ile base iools, plus veision-specific SDKs and ielaied add-ons.
Install the Base Tools
Tle Andioid developei iools can be found on ile Andioid Developeis Web siie.
Tle defauli opiion ai pieseni is foi you io download ile "ADT Bundle". Tlis includes a compleie copy of Eclipse, along wiil ile base iools and ile laiesi SDK files. If you wani a iempoiaiy Andioid developmeni enviionmeni, ilis is piobably a fine cloice.
Oileiwise, you will wani io clicl on "Using an Exisiing IDE" (even if you lave noi yei insialled Eclipse) and download ile ZIP oi TGZ file piesenied io you, unpacling 17 TUTORIAL #1 - INSTALLING THE TOOLS
ii in some lilely spoi ileie is no specific pail ilai is iequiied. Windows useis also lave ile opiion of iunning a self-insialling EXE file.
Install the SDKs and Add-Ons
Inside ile tools/ diiecioiy of youi Andioid SDK insiallaiion fiom ile pievious siep, you will see an android baicl file oi slell sciipi. On Windows, you may see an "SDK Managei.exe" file, peilaps in ile iooi of youi ADT bundle insiallaiion. In eiilei case, if you iun ilai, you will be piesenied wiil ile Andioid SDK Managei:
Fiqure . AnJroiJ SDK Monoqer
Ai ilis poini, wlile you lave some of ile build iools, you may lacl ile }ava files necessaiy io compile an Andioid applicaiion. You also lacl a few addiiional build iools, plus ile files necessaiy io iun an Andioid emulaioi. Tle cleclboxes indicaie wlicl paclages you wani io insiall by defauli, ii pie-clecls a numbei of ilem. If you close ile "ADT Bundle", some ilings will alieady be pie-insialled foi you.
You will wani io clecl ile following iiems:
i. "SDK Plaifoim" foi all Andioid SDK ieleases you wani io iesi againsi foi ilis bool API i (Andioid (.o.) is iecommended, along wiil any oileis wiil wlicl you wisl io expeiimeni. 18 TUTORIAL #1 - INSTALLING THE TOOLS
:. "ARM EABI vya Sysiem Image", if ileie is an opiion foi ilai foi ile API level you close (slould exisi foi Andioid (.o and liglei). You can also download ile "Iniel xS6 Aiom Sysiem Image", if one is available io you, ilougl seiiing ilai up is a bii of an advanced iopic. . "Documeniaiion foi Andioid SDK" foi ile laiesi Andioid SDK ielease. (. "Samples foi SDK" foi ile laiesi Andioid SDK ielease, and peilaps foi oldei ieleases if you wisl. . "Google APIs" foi eacl Andioid SDK ielease foi wlicl you aie downloading ile plaifoim (see fiisi bullei). 6. Andioid SDK Tools and Plaifoim-iools. y. Andioid Suppoii Libiaiy (in ile Exiias gioup ai ile boiiom of ile iiee).
Tlen, clicl ile Insiall buiion beneail ile iiee on ile iigli, wlicl biings up a license confiimaiion dialog:
Fiqure . AnJroiJ SDK Monoqer lnstollinq Pockoqes
Review and accepi ile licenses, ilen clicl ile Insiall buiion. Ai ilis poini, ilis is a fine iime io go gei luncl. Oi, peilaps dinnei. Unless you lave a subsianiial Inieinei conneciion, downloading all of ilis daia and unpacling ii will iale a faii bii of iime.
Wlen ile download is compleie, you can close up ile SDK Managei if you wisl, ilougl we will use ii io sei up ile emulaioi in a laiei siep of ilis clapiei. 19 TUTORIAL #1 - INSTALLING THE TOOLS
Step #4 - Install the ADT for Eclipse
If you will noi be using Eclipse foi youi Andioid developmeni, you can slip io ile nexi seciion. Similaily, if you downloaded ile "ADT Bundle" and ileiefoie alieady lave a compleiely-configuied Eclipse enviionmeni, you can slip io ile nexi seciion.
If you lave noi yei insialled Eclipse, you will need io do ilai fiisi. Eclipse can be downloaded fiom ile Eclipse Web siie. Tle "Eclipse IDE foi }ava Developeis" paclage will woil fine. Noie ilai ile Andioid iools iequiie Eclipse .6 (Helios) oi newei ai ile iime of ilis wiiiing.
If you alieady lad Eclipse insialled, ii is a good idea foi you io go in and clecl youi compilei compliance level (Piefeiences > }ava > Compilei). Tlai slould be sei io i.6. Noiably, ilis allows ile use of @Override annoiaiions io indicaie meilods ilai aie implemeniing a }ava inieiface, iailei ilan iiuly oveiiiding a supeiclass meilod. Tlis annoiaiion is veiy common in }ava code in Andioid piojecis (including many of ile samples in ilis bool).
Nexi, you need io insiall ile Andioid Developei Tools (ADT) plug-in. To do ilis, go io Help ] Insiall New Sofiwaie. in ile Eclipse main menu. Tlen, clicl ile Add buiion io add a new souice of plug-ins. Give ii some name (e.g., Andioid) and supply ile following URL: https://dl-ssl.google.com/android/eclipse/. Tlai slould iiiggei Eclipse io download ile iosiei of plug-ins available fiom ilai siie: 20 TUTORIAL #1 - INSTALLING THE TOOLS
Fiqure . Eclipse ADT pluq-in instollotion
Clecl ile cleclbox io ile lefi of "Developei Tools" and clicl ile Nexi buiion. Follow ile iesi of ile wizaid io ieview ile iools io be downloaded and ileii iespeciive license agieemenis. Wlen ile Finisl buiion is enabled, clicl ii, and Eclipse will download and insiall ile plug-ins. Wlen done, Eclipse will asl io iesiaii please lei ii.
Tlen, you need io ieacl ADT wleie youi Andioid SDK insiallaiion is fiom ile pieceding seciion. Tlis slould occui on youi nexi iesiaii of Eclipse, via a "welcome wizaid". Oileiwise, io do ilis, cloose Window ] Piefeiences fiom ile Eclipse main menu (oi ile equivaleni Piefeiences opiion foi OS X). Clicl on ile Andioid eniiy in ile lisi on ile lefi: 21 TUTORIAL #1 - INSTALLING THE TOOLS
Fiqure 6. Eclipse ADT confiqurotion
Tlen, clicl ile Biowse. buiion io find ile diiecioiy wleie you insialled ile SDK. Afiei cloosing ii, clicl Apply on ile Piefeiences window, and you slould see ile Andioid SDK veisions you insialled pieviously. Tlen, clicl OK, and ile ADT will be ieady foi use.
Step #5 - Install Apache Ant
If you will be doing all of youi developmeni fiom Eclipse, you can slip io ile nexi seciion.
If you wisl io develop using command-line build iools, you will need io insiall Apacle Ani. You may lave ilis alieady fiom pievious }ava developmeni woil, as ii is faiily common in }ava piojecis. Howevei, you will need Ani veision i.S.i oi liglei, so double-clecl youi cuiieni copy (e.g., ant -version) io ensuie you aie on ile piopei ediiion.
If you do noi lave Ani, you can obiain ii fiom ile Apacle Ani Web siie. Tley lave full insiallaiion insiiuciions in ile Ani manual, bui ile basic sieps aie:
Unpacl ile ZIP aiclive wleievei ii may male sense on youi macline 22 TUTORIAL #1 - INSTALLING THE TOOLS
Add a JAVA_HOME enviionmeni vaiiable, poiniing io wleie youi }DK is insialled, if you do noi lave one alieady Add an ANT_HOME enviionmeni vaiiable, poiniing io ile diiecioiy wleie you unpacled Ani in ile fiisi siep above Add $JAVA_HOME/bin and $ANT_HOME/bin io youi PATH (noie: Windows useis would add %JAVA_HOME%\bin and %ANT_HOME%\bin) Run ant -version io confiim ilai Ani is insialled piopeily
Step #6 - Set Up the Emulator
Tle Andioid iools include an emulaioi, a piece of sofiwaie ilai pieiends io be an Andioid device. Tlis is veiy useful foi developmeni noi only does ii mean you can gei siaiied on Andioid wiiloui a device, bui ile emulaioi can lelp iesi device configuiaiions ilai you do noi own.
Tle Andioid emulaioi can emulaie one oi seveial Andioid devices. Eacl configuiaiion you wani is sioied in an "Andioid viiiual device", oi AVD. Tle AVD Managei is wleie you cieaie ilese AVDs. Fiom ile command line, you can biing up ile AVD Managei via ile android avd command fiom youi SDK's tools/ diiecioiy. Fiom Eclipse, you siaii ile AVD Managei via iis ioolbai buiion oi via ile Window ] AVD Managei main menu opiion. Ii siaiis up on a scieen lisiing ile AVDs you lave available - iniiially, ile lisi will be empiy:
You will noiice ilai ileie is a "Device Definiiions" iab. Tlis piovides a caialog of device laidwaie configuiaiions ilai you can use as ile siaiiing poini foi youi emulaioi:
Fiqure 8. AVD Monoqer, Device Definitions Tob
Foi now, ilougl, on ile "Andioid Viiiual Devices" iab, clicl ile New. buiion io cieaie a new AVD file. Tlis biings up a dialog wleie you can configuie wlai ilis AVD slould lool and woil lile: 24 TUTORIAL #1 - INSTALLING THE TOOLS
Fiqure . AJJinq o New AVD
You need io piovide ile following:
i. A name foi ile AVD. Since ile name goes inio files on youi developmeni macline, you will be limiied by filename conveniions foi youi opeiaiing sysiem (e.g., no baclslasles on Windows). :. Wlicl one of ile available device iemplaies fiom ile "Device Definiiions" iab you wisl io use. Since ile emulaioi iuns slowei wiil liglei iesoluiion scieens, ile Nexus S is a lilely candidaie ii is a faiily common iesoluiion ilai will noi be ioo ieiiibly slow. . Tle Andioid veision you wani ile emulaioi io iun (a.l.a., ile "iaigei"). Cloose one of ile SDKs you insialled via ile diop-down lisi. Noie ilai in addiiion io "puie" Andioid enviionmenis, you will lave opiions based on ile iliid-paiiy add-ons you selecied. Foi example, you piobably lave some opiions foi seiiing up AVDs coniaining ile Google APIs, and you will need sucl an AVD foi iesiing an applicaiion ilai uses Google Maps. (. Tle CPU aicliieciuie youi emulaioi will emulaie. Tle vasi majoiiiy of Andioid devices lave ARM CPUs, wlile ile vasi majoiiiy of developmeni maclines lave xS6 CPUs. Howevei, since seiiing up ile xS6 emulaioi suppoii is a bii complicaied, foi now, cloose ARM. Laiei on, ilougl, you ieally will wani io considei an xS6 emulaioi, as iley iend io iun mucb fasiei. 25 TUTORIAL #1 - INSTALLING THE TOOLS
. Wleilei oi noi a laidwaie leyboaid is pieseni. Having ilis clecled can ease youi daia eniiy on ile emulaioi, as youi developmeni macline's leyboaid will aci as a leyboaid foi ile emulaied device. 6. Wleilei ileie slould be a poiiion of ile emulaioi window sei aside io slow laidwaie coniiols, sucl as a D-pad. Tlis is usually a good idea, paiiiculaily wlile you aie geiiing familiai wiil ile Andioid enviionmeni. y. Values foi ile memoiy and inieinal sioiage ile defaulis aie peifecily fine seleciions. S. Deiails aboui ile SD caid ile emulaioi slould emulaie. Since Andioid devices invaiiably lave some foim of "exieinal sioiage", you piobably wani io sei up an SD caid, by supplying a size in ile associaied field. Howevei, since a file will be cieaied on youi developmeni macline of wlaievei size you specify foi ile caid, you piobably do noi wani io cieaie a :GB emulaied SD caid. :MB is a nice siaiiing poini, ilougl you can go laigei if needed. q. Wleilei oi noi "snapsloi" mode is enabled. Tlis can speed up iesiaiiing ile emulaioi ai ile cosi of laid disl space. Foi now, leave ii unclecled. io. Wleilei oi noi you wisl io use ile developmeni macline's giaplics caid (GPU) io acceleiaie ile emulaioi's giaplics. Usually, ilis lelps emulaioi peifoimance, so clecling ilai is woiil iiying. If you encouniei pioblems iunning ile emulaioi, iiy ediiing ile AVD definiiion and unclecling ilis value.
Clicl ile OK buiion, and youi AVD siub will be cieaied.
To siaii ile emulaioi, liglligli ii in ile lisi and clicl "Siaii.". You can slip ile launcl opiions foi now and jusi clicl Launcl. Tle fiisi iime you launcl a new AVD, ii will iale a long iime io siaii up. Tle second and subsequeni iimes you siaii ile AVD, ii will come up a bii fasiei, and usually you only need io siaii ii up once pei day (e.g., wlen you siaii developmeni). You do noi need io siop and iesiaii ile emulaioi eveiy iime you wani io iesi youi applicaiion, in mosi cases. Also, Eclipse will auiomaiically siaii an emulaioi if you do noi lave one siaiied and you iiy iunning an applicaiion.
Tle emulaioi will go iliougl a few siaiiup plases, iypically fiisi wiil a plain-iexi "ANDROID" label (foi pie-Andioid (.o) oi a blanl scieen (foi Andioid (.o+): 26 TUTORIAL #1 - INSTALLING THE TOOLS
. ilen a giaplical Andioid logo: 27 TUTORIAL #1 - INSTALLING THE TOOLS
Fiqure ii. AnJroiJ emulotor, seconJory stortup seqment
befoie eveniually landing ai ile lome scieen, a welcome page (slown below, foi Andioid (.o), oi ile leyguaid: 28 TUTORIAL #1 - INSTALLING THE TOOLS
Fiqure i:. AnJroiJ .o emulotor welcome poqe
If you gei ile leyguaid (slown below), piess ile MENU buiion, oi slide ile locl on ile scieen io ile iigli, io gei io ile emulaioi's lome scieen: 29 TUTORIAL #1 - INSTALLING THE TOOLS
Fiqure i. AnJroiJ keyquorJ
Step #7 - Set Up the Device
You do noi need an Andioid device io gei siaiied in Andioid applicaiion developmeni. Having one is a good idea befoie you iiy io slip an applicaiion (e.g., upload ii io ile Play Sioie). And, peilaps you alieady lave a device - maybe ilai is wlai is spuiiing youi inieiesi in developing foi Andioid.
If you do noi lave an Andioid device ilai you wisl io sei up foi developmeni, slip ilis siep.
Tle fiisi siep io male youi device ieady foi use wiil developmeni is io go inio ile Seiiings applicaiion on ile device. Wlai lappens now depends a bii on youi Andioid veision:
On Andioid i.x]:.x, go inio Applicaiions, ilen inio Developmeni On Andioid .o iliougl (.i, go inio "Developei opiions" fiom ile main Seiiings scieen 30 TUTORIAL #1 - INSTALLING THE TOOLS
On Andioid (.: and liglei, go inio Aboui, iap on ile build numbei seven iimes, ilen piess BACK, and go inio "Developei opiions" (wlicl was foimeily lidden)
Fiqure i. AnJroiJ .o Jevice Jevelopment settinqs
You may need io slide a swiicl in ile uppei-iigli coinei of ile scieen io ile "ON" posiiion io modify ile values on ilis scieen.
Geneially, you will wani io enable USB debugging, so you can use youi device wiil ile Andioid build iools. You can leave ile oilei seiiings alone foi now if you wisl, ilougl you may find ile "Siay awale" opiion io be landy, as ii saves you fiom laving io unlocl youi plone all of ile iime wlile ii is plugged inio USB.
Noie ilai on Andioid (.:.: and liglei devices, befoie you can aciually use ile seiiing you jusi ioggled, you will be piompied io allow USB debugging wiil youi specific developmeni macline via a dialog box: 31 TUTORIAL #1 - INSTALLING THE TOOLS
Fiqure i. Allow USB Debuqqinq Dioloq
Tlis occuis wlen you plug in ile device via ile USB cable and lave ile diivei appiopiiaiely sei up. Tlai piocess vaiies by ile opeiaiing sysiem of youi developmeni macline, as is coveied in ile following seciions.
Windows
Wlen you fiisi plug in youi Andioid device, Windows will aiiempi io find a diivei foi ii. Ii is possible ilai, by viiiue of oilei sofiwaie you lave insialled, ilai ile diivei is ieady foi use. If ii finds a diivei, you aie piobably ieady io go.
If ile diivei is noi found, leie aie some opiions foi geiiing one.
Windows Update
Some veisions of Windows (e.g., Visia) will piompi you io seaicl Windows Updaie foi diiveis. Tlis is ceiiainly woiil a sloi, ilougl noi eveiy device will lave supplied iis diivei io Miciosofi.
Standard Android Driver
In youi Andioid SDK insiallaiion, if you close io insiall ile "Google USB Diivei" paclage fiom ile SDK Managei, you will find an extras/google/usb_driver/ diiecioiy, coniaining a geneiic Windows diivei foi Andioid devices. You can iiy poiniing ile diivei wizaid ai ilis diiecioiy io see if ii ilinls ilis diivei is suiiable foi youi device.
Manufacturer-Supplied Driver
If you siill do noi lave a diivei, ile OEM USB Diiveis in ile developei documeniaiion may lelp you find one foi download fiom youi device manufaciuiei. Noie ilai you may need ile model numbei foi youi device, insiead of ile model 32 TUTORIAL #1 - INSTALLING THE TOOLS
name used foi maileiing puiposes (e.g., GT-Pii insiead of "Samsung Galaxy Tab : y.o").
OS X and Linux
Odds aie deceni ilai simply plugging in youi device will "jusi woil". You can see if Andioid iecognizes youi device via iunning adb devices in a slell (e.g., OS X Teiminal), wleie adb is in youi platform-tools/ diiecioiy of youi SDK. If you gei ouipui similai io ile following, Andioid deiecied youi device:
List of devices attached HT9CPP809576 device
If you aie iunning Ubuniu (oi peilaps oilei Linux vaiianis), and ilis command did noi woil, you may need io add some udev iules. Foi example, leie is a 51-android.rules file ilai will landle ile devices fiom a landful of manufaciuieis:
Diop ilai in youi /etc/udev/rules.d diiecioiy on Ubuniu, ilen eiilei iebooi ile compuiei oi oileiwise ieload ile udev iules (e.g., sudo service udev reload). Tlen, unplug and ie-plug in ile device and see if ii is deiecied.
Tle CyanogenMod piojeci mainiains a page on ileii wili wiil moie on ilese udev iules, including iules fiom a vaiieiy of manufaciuieis and devices.