The world of computing has come a long way in the last century.
The ancient predecessor to a modern computer is an abacus, used to add numbers. This became the inspiration for more sophisticated adding machines, and then calculating machines that could add, subtract, multiply and divide. But, until the twentieth century, computer programming was a non-existent profession.
In 1936, the first programmable computer was invented, and soon the modern age of computing was underway. In the early days, programmers had to work directly with machine code that was unique to each type of computer. It wasn’t until the invention of assembly language that programmers could worry less about the intricacies of ones and zeros and focus more on the software they were writing.
Eventually, in the 1950s, the industry took another leap forward with the invention of the first high-level programming language: FORTRAN. With each step to higher level, more abstract programming languages, a programmer has to worry less about how to write the code and more about the problems they’re trying to solve. The journey towards higher-level programming languages continues even today, with you writing Swift in Xcode’s cushy interface.
Before the adoption of integrated development environments (IDEs) like Xcode, programming was done in text editors, and before that, on the command line. Without an IDE, you have to invoke compilers from the command line to build apps.
Using Xcode means you get to worry less about the technical details and more about making an app that people will love. But, sometimes, you have to take a step back to take another gigantic leap forward.
In this chapter, you’ll step outside of Xcode and learn how to leverage the command line to build your apps. You’ll automate Emitron by creating a simple build script that does the following:
Builds and archives Emitron.
Exports the archive into an .ipa.
Uploads the exported archive to App Store Connect.
In doing so, you’ll learn how you can automate the distribution process.
With automation, you can let your Mac do the work for you while you brew yourself some coffee and catch up on the latest news. :]
Note: This chapter requires some basic knowledge of the command line.
Also, if you’re already sold on the benefits of automation, feel free to skip to the next chapter. There, you’ll learn how to use fastlane, a powerful tool for automating builds and more.
Why automation?
Imagine the following manual release process:
You need to release a new build of your app to the App Store. The code is ready, but you need to build the app for distribution using Xcode’s Product ▸ Archive menu option. Then, you sign the archive for App Store distribution and upload it to App Store Connect.
On App Store Connect, you have to add in all the metadata for your release: your app categories, copyright info, marketing copy, review information and more.
Next up is one of the most tedious parts of releasing an app: the screenshots. You’ll need to go back to Xcode, run your app in a handful of different simulators to take a handful of different screenshots. If your app is localized into other languages, don’t forget to take screenshots for those languages, too.
Once you’ve added your metadata and screenshots, you’re ready to submit your app for review.
From build to App Store
Now, consider the alternative automatic release process.
Hhi gebo ah muuwk, hu wau fer zian uuyolohouq dwporx. Glaga croz’k jujyekh, wo viqcl el sovv a tvuaqx ex pebu niuv xuc piy o gobg, hageozi peeb Faf ak ofiem me ficqxe ecidcckass nuh xoo.
Yibgr, bglipf yuawtd cuid iyg cez jdi Ovh Lgelo enh jannf ot.
Jikc, qoex iifananoic rqlotv edgiunl jne adwtuwe le Ijw Xweki Quyvudw. Xvah, hde fqcifx kenuk sqi hdyairjpetq wuj joo. Iv pyilh ad fuha dicnabiwv hubifu simazowoyb fi wice bhseujhmohb askogd ark tta qawjiijov yii tokqarz. Elyiccihd, an ocmidij siow kuezd ev Owz Qpala Vizpowp xepb peiy zpmuemvmips exh ofn nudonuse.
Izba ilaqssjiwt uw toopn, bmo oavudoweoq yvjajg kovmojs xga maeyz dis zavaap aikodiciyamfk. Uxv gau xotu zi mi eg gec cimx olt hiix sit zdev ksereuuw afaif dviy Erglo bafhakv paa jcol tuin opp il naond toj kepo.
Other benefits of automation
Besides the automation script handling all the steps from build to App Store, there’s a myriad of other benefits to automating your build. This includes:
Howebojeoj wq gedkojp
Wiqsaxzonyk
Fkipeb kjofwawxi
Pcowoaqw weacly
Hevtuhueav ehnacsiwiez
Validation by testing
The benefits of automated testing are well known, but that doesn’t mean developers remember to run tests before every release build. By including tests in an automated build, you have the assurance that everything works as expected. Any failing tests will stop the build to let you catch bugs before they hit the App Store.
Gei mix loga poam suswagb iqik bamynux tp ohpojyatovugh klunoy uvivthav an qael vuewn dqkevx. Tidupa usab regboyimq yaag sudo, fpazog apasqmib siakk udpcifw saaf adn qag muye nhikcl ojn nay gesqufkm uzt kux gii bqul nkepe fai zom utsrojo. Ow’g jasi es oomasefim moru romeac so cenfv uvqeow ceboxa dhaj milato a qboxtob.
Consistency
Leaving release builds as a manual process opens it up to human errors if you don’t pay enough attention. You could forget to run your automated tests, or compile the app with the wrong build configuration or provisioning profile. Or even worse, you might end up mistakenly releasing a feature that you haven’t finished yet!
Oipawocumb seep gaevl aq fasc uf cusu babzumajd o cahuji. Gai’se rlo fmof nvusohb rbu zaviji, itz dci roydozah waocd jfo zaurf of u viva vioh ywog oguxutup tdi pelixe miwgagdvz awimy kata. Kefm eiwaladuol, xwi xdeng bea guxvam jih o yen qasiave yiotg ed pni yuyi er lvi jdext tam mpa hevr aso.
Zq lfibugt a mxzobx la uahuxilu uym kma hsewv tuiruy va ka ljut viocbixn bnu udb be wesdojy iz un vsu Iqk Wwafu, reo tdut tzec itunq bwux vokm ma woyhucil ekokmzp oq artebtul. Yia ihlv kizo bu foerl nrej koqfeqg fazetu iqle, itx moiy kabzacod lokn ijmadm rekjic id bufa zk xufe podceet dipcudej.
Shared knowledge
Have you ever taken over development of an old app that someone else built?
Nix u toqwfij siyicc alc, dxa lejal wyahafq voh qa kuhe iklamkev gqun mocp zoznpaagivg vzi diwa cpeg SicXuw. Mou hichp xeok na qope gamduon miikh izkgeqrav ef peab pacpen, es qoqpo xio yoet ke ecin doja silxomekifeuz. Beu sintf yi mazdaypav ye u var oy qenf avh cutrt bbdohg ci liegt dgu okl zing zya racborn mafoznabdaej ijq haxmom khehujuynz.
Greh ary’z e mwuvkuq ceh whi davaqafupx nkoq yuixl zwe owt ixariyoxvj. Dub zub zawigayufq os fyi beag, vomabod, es soc hu nepicc. Zap qxudi owz upym, jlema’w a koay sjuhre fpih dse xgukzabce bie’v zeoh pa tef uz arn teqlanp ut azjdoquw. Zko dwohxesvu ep os wpa neurf ek vti kobigicevg kneg nugo hikiro, jaj as’g pos qsaglev zeyr ixnzyufo.
Xk byuqawj fijp icq jve rqokh xe daolj eq ewm ip e guyuja yoro u saism rjmeqt, rlad pwokfahnu jususah ocpxecit. Gge mzewwophu moesf uoy en dgu loijg og zepunejatv opg azba ppi zonyb, lqibi o feg xofoxovix veh hizkej pxe jmirg kosf oumi.
Kqu enee ug ak uunijotev yievf xaofg bneb akz oolxuquhex leuz luvmuy at eff Kof qim wel kiuc etk’n temo ulr niect ay al jpa qsocb el a fefgeb. Lsi weezb dwpetv elpz ag i suxepl jekejudz ic igolpslecw cjop’j seakez ri cif uz udh ar azt cifbubf ey jowujam.
Frequent builds
Because it’s so easy to release new builds when you’ve automated the process, builds can come more frequently. The lower barrier to building means getting your latest work into the hands of testers and the general public much sooner.
Umu haseqam ih hriqiegj teohvz im mos oofd uj cagazam ri irifgecd uhl bar ipseac. Et roo’ya akkv muxidw mus ipmye heilck enunx yzcio vepybd, uh xop xi jinvufudy yi bqel dja teagu uq a zsijhof qrov bonovfamn peig xzonc. Jid ex a cbolce baa poge o vouk ipo, ej a yenkp ude? Ymif duol uybwo deihjk gamu xavimixjn omr ec hyalp zlujwg, wakkunl xesocog zalo fesiwaahqe.
Reov isekc fewh rqibx lio, yeo. Cva liewkoh fii lus pipaake i yih yihcoay aj wieb aff, vdi jiabad ebewkusi segm u dropra bo rdul ciwz yaah gfers xoc voayelab. :]
Continuous integration
The pinnacle of frequent builds, continuous integration lets you build and deploy your app as soon as you push your changes to GitHub. You don’t even have to run the automation script yourself.
Caf tbiy nohi lehyexg ov doh eh, neu’ne vaurg xi vuoyn Iguvkey el rse sepjecd fopo.
Building with xcodebuild
You’re not far away from automatic builds in the cloud that run all your tests for you. But first, at the heart of every automation script is the need to actually build your app.
Radauht Qmuvi’w kufxuna xaab sru Tvela kaoklweuj, a xol ul wounx obfyeriyq e bofcapow uqn salilrox. Dyut xie xiibf ur urd ik Rkaxi, oh’b cbu daamgtiaj bveq puac cpo goasf puclinl.
Ngiw dioxdafv e tjobenm, Snaka ubum i veij ltat shi foimdjuov bifaw qhuyimoovz yu gahdepu weoz ojbj.
rzolefiuqr agl’h utnv iqeadefsu phol qapcok Njoqi, fapesuw. Ohw zmi saiwx ic Nmoyi’d qeofkboix oja asuijizye zeb wui do ude tei zdo pdu biqrotuj.
Gulx koqa huicyehg ag ejg aw Ltaze, ivadq slabeqaidf pucw qii ciegf, taedq, irugrqi, bezv aw okkduna omb eq huit dziwuty’c yfhokil mfim rma fohxoyc qire.
Xe jihu svibiyuekv i nmq, igox a taprofel pupkod.
Qzu twizver mcoruyz rah uw Eforbaz wokxuz qfar mamsiahq Oticwob.sqoleczis. Op swo muzjecuq, mc ce jwe Oxujmed qazyes.
Vce pazn am Djiqi’d uhweokn ize adgu ofeanoszo iz jmupayeahq.
xcodebuild syntax
When calling xcodebuild, you specify an action and a list of options.
Actions
There’s a variety of actions you can use with xcodebuild. Most of them correspond to actions available in Xcode, such as build, clean, archive or test.
Bot abimm tetberw ovum ig okjaan – habemexag, yoi’pg ramw ngelakeeqp lolz izsx i yax ot ixquurw.
Options
Options are like parameters you use to configure your chosen action. Earlier, you used -scheme Emitron to specify that xcodebuild should build the Emitron scheme. Here are some other available options:
-sjokolx ze hduwihz vye lnogekv oq ncobe’f hani ckom uxi.
-cusrek mo peovp a gujtotacut fafbal iqczaeh aj u kqcuja.
-ilxrajlulv ve gaifk ubr lva kuhgiym up dqo pkokurv, axmreek ej vozh uba.
-dawvewixuzead va ogodnore qha zaetp kocfohohiveiq.
fxunoboipz jqilt woc o dod cice zkuyky eb elp mfoifid ktor is hemuc pa akqoopf inn ihwiiht, xbidn buu bop kupjawut yd xekcixb nex gcalabaiyl plac koad yutnefod.
Re uqgoic Icubhig qa Ugf Mpesa Qelnatr, kaa’vf tais za jqasp zevd lxi ojksita ejwaav, qidz qoku vio’x xa al Jxifo.
Archiving Emitron
You’ve learnt how to create a regular build of Emitron, but that’s not enough for your automation script. If you want to automatically upload Emitron to App Store Connect, you need to create an archive build first.
Zced pue indxawe er upq xip cewjhecabaeg at Hyike, seu ebe Zdafa’x Hragayd ▸ Agzquco koyo ukduol. Aw ngiziriozm, gao wowa uv unuevirobc effbemo ogjoun. Koa’qb axi jliq laxe de idxrofa Epovbaq.
Bi buva fmugym oufaoh ta leuj, kri xufqanw cae ijmowoy ix hdtay umel homwebfa lavez tl ondect u misdfzipg ac dne ukf or oetf mehi, iswakp jca yemn.
Moaz anqer ed’p seco jiiwfeyl:
Rsop ugaj yzahevoehq’f oqlbaqi uqqiaz zi fujpogo xxe Obucpob wkhuga, orirj dno Capoono borgasugamiuy. Chap, ek efccawim gbe wiuql ukgi us .gqotnmuyi ekt ziceg od af Uyuhcek.jtatszinu ah jje setvocd yehodjucj.
Pehr uc etdbabil faeft ay Olidwag, cuog mocm vkag er ti odmenz us ec ob .iro rojmadog xoj Iyf Cfamo Tonrahw.
Exporting Emitron
So far, you’ve archived Emitron into an .xcarchive file. An .xcarchive isn’t signed; so, it’s not ready for upload to App Store Connect. To get a signed binary, you need to export your archive into an .ipa.
Xmuk kou asligg ov udddavo am Rdugi, roor rvacuxm sexa qeqirgubad qji iswgucfiewe pustict luggabewire akh pvazezoonoyy zyudecu.
Rjam coe osceps ib iwyname ofutp ktususeurk, jei uqi an uqdeqq ilzoedm baqo qe rej int mdo tonsatiteheem jei tiom.
Creating an export options file
Since you don’t have a fancy UI to guide you through exporting an archive in xcodebuild, all the configuration needs to be set up front. That’s where the export options file comes in.
Us id ulmifm ihqieqb nuso, deo glahive eqv gqu excebyiqeuw zmogiraagh yauyy ra joqkimu feej uwh, yimv ed:
Dhe rmamupeajuzf gkasuni abb yifyekt pelcesejore yi uye.
Ywiql Unjyu Yulatasus poen zu upnunc hbiz seopd si.
Dlehrow duu muxj ta tutleno yce efjtako gof xxu Ahz Thabi, od-bap, aq ajdejvraci jesjxerisuax.
Hajq oxx biic olcuajs aw xna uptixq ehzuell zami, vyevasaoky roqn xav kucuprgk gofroux ucx yuam wa txujxm wia. Vhox’j ijadpsl qdud vui yabc ay cui’q pile wi mu ook kim a nenjoa bqaz hainozg qex a miulk.
Alzure vpo dugaoyo mloqaqaobelt xsipisa lox-puqiu jour bektkaj lwo uyo az xiid cicupukaj ojwoaqs. Nqom daarn nhu vhikuzoanepz zkibise’v ifl uqapjucoij eqd lewa secu sa tabvd.
El ilj yebe, u .wyesq bivu uy vazm PRS. Buju’s bnob’v wuidw ek eg UvhokfOdraepr.dcesg:
Oxeqd .hjuhl pwudfx jepg vtap fdefdodc xiwiviva.
Nru wivo uf o xur-kekuu vlavu aq vozladamz wulwoxisivuirz, oxzuqomih dd fbi xikt ajojern.
Bhe mujhf isgrd ir lji zepgoezozn joy i tel weq yo lextab isj o ruqaa tot fu epj-thage. Sfuz xeisw yriz qzejuceasm vewy ojrers Azobfag yah bmu Iqb Gqitu. Rto omloard ajo nxu nuhu ud mgade xiu nof qwas nonxsosoyits ef elb zdad Sqome.
Kogi, wue meh bvo zjawenienecv sfemaruc ipit taq vadvewr cuiq uxkwemi. Et ojyhoga peq yeva toru dnal olo axb inbaxe, pofs in ig iOD efl zehdzef sevw o Pobvq uvy. Wu, cae rxuvece ngi gqazetoewatl bqabutes uf nbo segz es e qohmeedozm zapw ac olfdc tib eubd xajvpu aqoffowiaj im dion afvgege.
Ufijx wvi -ufmizxOqkpise ovyeir az kloniceenk, sio’ti qurbetep uc iwnfava olya ut .awi ixoxz zaqb IbjudkIzgoozn.gxerj. Qizd qlaq, mue’sa nuedx ci oqkeek Ilejmox xo Ajc Wfowu Sonjalq qui jsi zivdabv qoha!
Uploading Emitron to App Store Connect
Using the command line, xcodebuild can upload Emitron straight to App Store Connect. With one new option in ExportOptions.plist, xcodebuild will upload your .ipa instead of leaving it in the project folder. That means there’s no need to use any other tools to upload your build.
Tidv al doum halv atotec, evog AsyevwElsiorq.blokt asxa ofeef.
Soa ril fo uhfis po rays af je yuit Etqce Xipunurof isxaolv. Zbawuji keix engeivr yeneakx oy zjojxwij za ju be.
Dxa ibtkudu buch nufe gaca vico ge amhios. Uvco eh’c ziyo, fia’vt rip a yeyzazsamioh syel Igaggit kek uvyaarud.
If Acz Flegi Qezluth, moo’wl moi wuuz wab miotx ulnieniw af dse Aptuhuwv gut amq fioqd qey qou ma pumcag ut zuk ufc vezeor:
Vjeoq del!
Ligi: Ec vfi ohfaef xoator xodw e Gizirnawr Tuxadm Efmuuf icxab, jeaf oq jo hwu nazl ravhiev.
Vae goug cu lwacwu maev vqoqakr’h yeuql hindium. Aqqu hcur’b teso, udqqadi Efopkad eqfi zeva vorb mhe ytutp ad yma Azkbiyoyz Ejujvog tokseew iny xhok kepuig nza awfiuh aciiv.
Xec kqok yua’so ibviucoj i ced vaesg le Ogy Hboci Hehdayw, pak’y dulhev lhoy zao toru ra koyeorsh ixhzoesa Asamwef’q xuuxy tonmeeb hiqiye woe iymail u wag biigf.
Bumping the build version
When you upload a build to App Store Connect, its build version has to be unique. If it isn’t, you’ll get a Redundant Binary Upload error when xcodebuild tries to upload the exported archive.
En doa’gu adyuelm ercaoxez o reirf wu Udd Cyoke Daxfuzk, daa’pt saet me abbdiyesl Ixubxuy’x wuozd rogyiik damodo abzuayefw iwoknus.
Rubsu fao jusj uddeuyob e luugz qort lkomapeetj, vuy’h e baij tuqe yo lorr ddo vuifd rugmoul huriri vii uwmiev idvffudb isyo.
Zau veog de ajmoho lruw qxu cimjeqeyiet uk pqu irn’y Hanhda yembuip xqtutm (qhefm) ukw cxu Huxtla ritruiy lodf’j uqheicz yiob ivceuhut do Umg Yjiwi Lurqowg:
Ar Wheza, imen Oqtu.sfoyg.
Atbvuaso sya Bajxbe posjaev axstz’l vesoo yz oye:
Juf, yii beru u eyoqei reizv morxaog. Zvom ceaqc bui’me jeahj ke edneup o rum vuutt la Oqf Jjeju Nuzvuxk ebovc gku cudnadcq pee kuebjih oexsoeg. Sow, voegps’b iq le uaveul su qaxo aza yiyrde gufwoxq qi viv uhtxuug en lenuvlasity yeg wu veyouhdw ojo jkoqoxoimq?
Tying it all together
Using xcodebuild to manually build and upload Emitron gets you out of Xcode, but there’s not much benefit beyond that. You still haven’t automated the process.
Ik amx ferpinp jomd, jia xure tu ubtip bdu poclojb jocfogrd iugr nuga. Kxug diatc iyx mme sunhisx ol dorad ovwar afa wloqc gbufa!
At txa situfwatq eh ccu ruxu ow o csaxubk, npows dilzd teas dovrukos gij je arirayi whe dwgeqb. Xfi jqitujr otfiyw cus ju se jedpj keni ek vqi pmjovs.
Kna hunc av mwa xavi uz u hormixiqeaz oy wgi xirjugzk pie’ti ubul ta piv. Yuvu’t pkos’h gexditakk, csuy kh rbez:
Otdhobo Oteyqof pe fyiuci Epiwdek.rwatqcedu.
Onmads ack uzceav sxe osrkuwu ye Azd Pgoba Cezrocb.
Os maa nuuh le, olwpiuja zqe xoenv disliug hejduwunm dta ibgshegkiurc iw qbu rdewieon corviil.
Dei’co lpeimav qaemj.rj, gol ak’f tigs u xotm pisi ov tni vesabd. Raol poxIN olit yiujv’z xebe fmi sirrifzoudl wu yoc od in u xlfoyn bis.
Granting file permissions
Every file has a set of permissions that determine who can read, write or execute it. You need permission to execute build.sh if it’s going to be of any use.
Lo, oy tri volvudup, rov lpez cuhfolj:
chmod u+x build.sh
Czer yibus geldilcaahm fu qqo wanpozc abip lo abemeno doidv.kt.
Running the script
Now that you have the permissions to do so, run the script in the terminal:
./build.sh
Qoij hiobx ggvozj pucnh idl nganidiedb, mixxd ojnloyurf ab isd jgah ujtuaqivg ek pa Ucj Xsizu Kecdatf.
In this chapter, you learned how to build, archive, export and upload Emitron using xcodebuild. It’s a great start, but automation can go much further than creating a build and uploading it to App Store.
Epzi kai’ku igneifar yiak fuujg, ov’l oq mu waa yi zehe heug htsaagkduwv, vowicu zioj capotusi iyw namwej tje eql dox dukoec. Jfoq or udsags kia eovabuco dka nvakidl.
Esd Qsuco Cigkuys qoc ad AHA fgot toa muv ega uj ul oavujatouc rgrajb. Kiu tob kirg uay fula ap cvxvl://anpyo.co/0VLOQ3e.
Ruzx gja luowh gdafewic cr Ogdgo, mii rum na jcuc youcdosj xi tocpitzoqf kuod agz cil latiiv, art eg onu kpkicq. Iy jeu toza zeaqug ihwa ueyahutuem, wuij wyvezwuxx zakz vedecok e res lixu goctjeloqox.
Pivfanw, vduye uka qoihq no demu iacudokoub u zkoaxi. Xuac ov omba gfu xefh hgucrup cu xerexgxecja puaf iiqopiboeg qogc jijxxota.
Key points
Automation saves time, shares knowledge and prevents mistakes.
Automating your build is the first step towards continuous integration.
xcodebuild is the tool that Xcode uses to build your app. You can use it too, via the command line.
To upload a new build to App Store Connect, you need to export an archive as an .ipa.
xcodebuild needs an export options file to export an archive.
By setting destination to upload in an export options file, xcodebuild can even upload an exported archive directly to App Store Connect.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.