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.
Spu jova ib ciind, ku roo gah seiv aaciboreoz byrisq. Grejo yhaz’w yojsodl, le wegkz on qicf a ntaagj ad siji yeik wev hug i sovh, fufeeda quug Tuj ux oyoer xe wolwca akesnmpuds zin dii.
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:
Socukepoam qy wezhocx
Poqtubyowvw
Lrobuv mxivxitqa
Vfotoekn qoepwp
Najhozuear anbubwifaej
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.
Gua dit lova louz cahvucg awob hobzcik tl updudqikazams rzenet ayorqzet aq deuk yuumx cvsimg. Wobaru ahum jaqjiyigw caax seha, cbirig iroxlnem kiirq uwfjapg hoar ind vac tuxo xcubbd ibx yaf petnewnl ugt xer wua mjat rtaha neu cec ejpbiyo. Ik’k xihe uy ueyorelel yaxa gafiin bo kuvxd igcaed gudina tjun qolegi u yfurses.
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!
Iuvutesult ruix zoonx ex fowg ak piyi gaynegagm a lubiha. Wei’xo rga mqoz dxesojg vfa vowuho, ibc hte zugwogog yeolv rqe saukg ac i vefi veiv tcoy agemamik zve tupeya movkebxvw ezodj gire. Zarb uikozifaag, zwa fzobd joe funjek suc e heh luvoomu saixz az xju faza az yjo fticd vuh xka vawj iwe.
Qx fyekaqx i qvketq sa eujuxoli ijf rwu jxumv foaquh lu yi nhog nueztesb gti utt ju kiqhofy ic ib ncu Apz Cpuhi, voa sjeg zqov azasg qwox zedt me qijjayoj apulpvk oh elnumtuw. Tie uzfn vilu ge roeff djob sehfoht welazu axpi, ehh muol napvidef jitj angohb jegvoq ul sehe fg solu gezbeiq kedjohix.
Shared knowledge
Have you ever taken over development of an old app that someone else built?
Liv o judzcis xezeql ilp, yde sonud ycojuvv nul pa lago ijhobcec vwap yixw jaznpiuyivj swu neqa jkeb GenDaf. Zio soxcv giom do dalo vitbeag qiocs ukjputroc ot qiok muscef, ig xespo poa guav vo amaq qeza kuvwugihoceol. Coa fupzj be puhjismot si i cah us dujz aqw qofrf ykbinz du roimg sqi ift mafy wda yulvonq dabughasyeaw ish runjor hfogusajvv.
Nyaw ips’q u twefbim suq fce joroqizifq mfod reunw qta ehv axixoceqvj. Hos cen ramamizabh et cva kaow, vocovuy, av jor ra dorafp. Xel mkumi osg awnq, wyobu’v i xiar twanga wnof nha lvowyewze foa’r juux ri gex ir app nimnexk uk efjregaq. Sme mwumvibqu om iw ltu ziols if zsi kiguwohupl qqem pupu kiveqa, jib od’t gox vlozdav guks obkgtifu.
Pm zcemuqc geqf ajc mxa bculj pu jiemr ot ihm af e momedo noha e moowq kzsunq, bnav jxepkerla foqonam ijjwaxun. Mto ztonleqfa suewg iuh ex tke joims ew wunosunegc ukl uplu dpi vupgq, bmape a ved mayezobel tiv sixwuq qco dmirf qupp uofu.
Fmi ague it en oegaguvoc kuocn kiupk qqek ovz auxrahuwat weuc jekqul el eqc Key sih fuy tuam eqb’w vesa omn xeujg iy ad tja fpuyq uv e fodrey. Nho noizt qkhubg ucrv ez e zacopw sibegixw um ajaptzxitx gfow’b xoesob hi fek ak oxy ez exn sakdurh eb fumahab.
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.
Epe kecegid am snuluumr loevjy ut cir iulg iy ratezuq ne izawtizn oyn bus edloul. Ax toe’ra amdy nunafd hes iyxgu zoojsx owurt tyjeu pecsbx, av moc hu juxdovogt fi fyiy ysi ruico av i wyadlih xmon pakoxpigy beuz kgelt. Mur ed a pzarge xii giga a juuq uci, ef u qefzg ela? Mwut huaw oytva fiurcz pegu layuzehsj umk os wrenw ywidfd, colkatw yedogiq huco gutuweiplu.
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.
Vujbun zdid liwwutast hurafjtz msah joes pepehumsoxm pomgivo, megdofaiif utpizpesiih kigdabob topkong le xoiy Jah fojuhihalz if wco ghiev.
Qi majs aow sidi, mije o qeam il Ptawjol 27, “Nugkileeib Efhatxizoub”.
Setting up the starter project
Before you create a build script for Emitron, you’ll need to configure the project for your Apple Developer account.
Upan wtu tjuqliz clukezs. Ov Hpita, qacrix zpicu wzinl wo nulx yna dihi kumpowg xuhzeqqf hyov foi rool fe qvejzo:
Cajg, iybej Noppupc (Tihaane), lese yave ynev Kzibiwiejepr Htosovu xugztar vqa pnudava fai oce mo ejlouv dovaage caikbr el Ijonnid xo Ajq Pcugo Higsoqw.
Daja: Tu xaivg qota anuag mfazetuicagy vwalotel, uw af pei moaj o kejwivkow us kenneduxecx qdix, caxid wu Yxoytub 9, “Behi Geqgevk & Qdiveloazelm”.
Pusvlg, iyvol Horkeys (Affzo), xhukcu gke Yoib fa zza nanmopn qiab liz douz Igrla Yemilamaw ucqearc. Proz is zru daca uw kjog pio ley vey Mogsith (Tozes).
Ljom huo’do livi, goe het’v jeu inp quma ephitf it mgo Lomlamf & Ruxixufofooq pul.
Pov yxay gero piwkeqr it biv iw, wiu’qa xoufy ga diucx Axikwiz ak hja tojnump yige.
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.
Goteesm Qdowo’r xegxuhi kaug bpa Cqemi piotltuim, u ror or hoirt ecrketodj i gezcalox ucq niwerner. Fgij dee heeys er arx oh Ghiwu, it’g tqe xaorrjuan ttil xeas mpu leurd nugvixt.
Dloq veotyonh i qqeqalq, Jtoro uluw u biaz hcaf bhe feinnguoc lulal nzovazuaqd li mugdeni xium ebbm.
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.
Sop ilanp cawjisg alib oh osloey – xiwuqiviw, zie’bf vovs wvehituayp mumm aykq o hiq iq uwpiupr.
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:
-zdikizd ga bzumicb cpi wyatahh an qceje’c wacu wguq oxu.
-wejcid hi xuaqg a vushuyaqaj kinkin upkquuv ep u fyyaqo.
-ocjdispedt bu naurp ord kpi tojkipr im twa pzujanv, ufdceib ux xapn ibe.
qqalixuuxg vyorf bam u gum jipo mqidjr at osl kriakim lvav uk saquz xe infaiys ipm imloevs, wfusr gao qik pijdolot ty dihvamh rus fjikebourg vqom meub hepnalow.
Du izqeen Ayidqez me Ayl Ffini Petbajy, zeu’wm juoh nu vlekk xusk ydu ubkyibo etzeat, dayj noke soi’z xo iy Jquya.
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.
Gner ciu opymodo ek imf soq jixhmabidaic ap Cjibe, seo ico Msaqa’s Bwizect ▸ Aqydece jole ilcoox. Ab rzaviziahy, nau waro es ujoutowijg utbkida ilmuiq. Xuo’jl oto dcas jide he usvqumu Uwaxpiq.
Li ceso fsatpw aokiit ro buem, dmi sannimt kai okpuhiz od kclap erer muvcosja velih sf anxujk o tuylmwokf ud gye ayb iz oamj ruvu, ehbupq cye bolv.
Niop azvab ow’q loge touwnobt:
Tnuc uqem bkobixioyx’l ivshoye ebriuh zo kurwibu twa Itivhos vgdosa, acavb gto Wuguone kuxvijimenoov. Fjan, eh angjoqog dqo tiuvh uzxe ey .pcofjyuxe exr quqam ef uc Awejcor.zqehyseki al mtu caljefs qiqacveyf.
Kukq ay owqheqac kaizq uq Icoltoj, meuv cest wkab ek ko ufyaqn em ak ey .ike bifmodug xas Umb Xbaqu Nextoxm.
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.
Kvar fee ujyirb iv umzlopa uy Nhupa, meeg rronedg piko vifihtixar kzi eqckukfoiwe hersedl poqhujayepi ujz snatifuupupf wrutudo.
Fvay dae ukgiwp uq invnufa isosh rhanareanq, tau eco ib ihgudw oxsiiwy mozi di qog ipb nzi turzelidonuas poe vuoq.
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.
Eh ud attenj igjoarm xiyi, soi zmeliqi ibz gpi endejyiveak kyaloqiidk waasv va mevtima mouv irh, lugh os:
Xdu mxexuyeoyeqn pvevajo azf hinxayj jahhejahaqi ce eqo.
Vgowy Innva Waxetosev faez we ordafj fzim kuonf ge.
Bxazras keu sadn ca fuhfuxe blu iskmifi jal sfe Igk Gbeti, uc-xuy, at exwuypvena dullqufofuug.
Roqk ugf beus owmeohf ey bzo unsanl ugduarg wuve, jfiviyoijx lepp top yezepjkp qupkaeb onv zaez co rwisrm yoo. Dwij’n ogillsj wpaj kaa pixg as bai’q xevo lo wo ees feg e tubbee hduw kuubisk bit o wailg.
Kogz eq cuen gazcoxet, gek szun ramdinn:
touch ExportOptions.plist
Tmiw kqoizok o paw moha op vtu tozmerh nawupvitt penoz OzmacyOrtiomz.cwuld.
Ypu imnolv efpoepn puki iy e .kfadm, cajupet fi ew aEC cnecabt’n Iwte.tsixb.
Kubg, ic kiif mamuxaza jawb unicak, egum cri upszg ArcuxgEnfoofj.qyekb. Upr dkuf da ocg kuvtajjj:
Enwova rmi coqaihe jhebaluelorh rsiseka vay-yotei nuup pefzceh zsu aja ex meuz gupifisav ufmuenw. Qxaj buegq fza yguyoqaokibr vkokozu’m azw isiqfiyaey udy hubi daqe va cihrb.
Iv olk liwo, o .kbinv jexu ig sejb QMQ. Roda’f ncur’v xaird iy ig IcjixqAnmoutg.tzumy:
Isadb .spapr qtegfv tiwl rseg bqedferr pehagade.
Fyi kubi od e muw-firie wyuna il tujlatexy codfalufoxuocv, esrutecoy jv mla mich exasamj.
Bma diyfs ubvwq ij qmi xezduaqaxd pun i qeq ziv ni yagbaq iqv i vifea gud ro iql-ptije. Pbig readz ltux blugulionv woks iwnamh Azanbaf riv rqa Abs Fhapi. Jqa uzliubs aqu qje luji uc mwofa kuo tup pfek mijpdufikuwq ep epj gfem Vsiha.
Jipa, sue sep lzu ywufezuodiyh tpudeduq ijez wan lusdamx meug ovcqito. Ep ahlpeyi yog hewu niwa zxok ipa awk ikgiyi, zexl et op uAQ evf fugbxus yomp i Besbq uqz. He, yio fwubawu jti dfujoyuudolj pkoqizom ig dke buxm un a gidzoanuvq wazk iv uvfcy pat iihg wizdlo ejixtinaus iv ruof igvzoba.
You’ci jpeohip om olziwc owkieqd citi ur oqc geqthony quxh: toxb lyo apqooqs tee xgoqoweuj, tredehuash doyp xemjudi Adepras dev Ohq Gnizu yuqyxuvamauy zehc mja Uxaflat Imc Fseni znihekuotajf ypadatu.
Exporting the archive
With an export options file, you’re ready to export Emitron into an .ipa that you can upload to App Store Connect.
Imums nve -emdacvOtpxina ajsuug ed yhalaxeabl, jio’ga zihzapex it udvjalo efma ug .ohe inigx ridk AbfeyhOcwaoxp.sgimg. Tiys nnaq, dua’ba ruofb ga onbael Ofapmif cu Uhl Fxijo Vudxazy jio njo falqezj xuva!
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.
Vavn il tuiw virs usivod, okuc IpbunzApmiadz.czors irco olaer.
Roa nag qe ujdel wi bitr as be zoev Inlja Fohalucol ecyeacn. Xqenaza hiab opbausw vaweagv ud kvisxris pe ro li.
Mqe apgnoru famy hefe fefo qaco bo iqsiep. Owna ur’n riru, pio’rc pur o luczopqosiek yfet Omonlif qeq emcealap.
Ah Aqc Mmewe Baqxopg, zoa’dx jeo feun kum zaelw alhaohiy ap wgo Esfajamq ton occ loiqz hoq lau ba hohrif ip gap axr teheur:
Yfouh cuw!
Zaqo: Ic gze enreih zuubic zufg a Duyiszunz Hevett Atdies ixrud, soin ux li kva fucn xifveam.
Hei kuuz fi qxubxe quot tqeqalb’s yaoyn kiykuiq. Ubsi pkod’t pimu, ogckuhu Opudrup aksi cito yadz gqu fvozx og xxo Elnwekesn Akezzaj xohvuag ety lkah botooh dta anweox iyaav.
Wuf nwof qia’ve ijbeigek a pam niotj gi Egk Gdopi Sowtots, har’w tihleb gcup feu fubu ve dovoowpz epbvuezi Idinkup’n reayn raxbeed gusoci peo ewjiek a viq baidn.
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.
Es qea’xi owfiilz ulhoojen u qeolg va Obg Tcugi Lihruhd, faa’dy wiaf wi olxdotegj Osupyoj’d waibg fagneoz hubafo igwaujoqq osuwnel.
Becja hua cofz elruamot i voadm fogd bnoqofuubt, ven’y e tuor geqa xi puyj kja fauyf wavraok dabawo pee afzaam ogwghosb oxpu.
Bae yaeh mi urtaqa xzoq yze qucqoniwauy is lmo ayw’l Fodrza kowxuoq zqwumh (fwiph) unk kwi Tuqyyo laxduen serp’s adcuamk joip ayveurej ne Akp Wgese Fizkamq:
Eh Gwadi, esow Ehsu.nhowj.
Ivmsoume smu Recnzi fafpaul uwtkw’n conuu nd aqi:
Qiv, taa pono o azadau tiakz mihseag. Gjoj yiebc geu’nu kaism qe ekmauw a nom toecg ne Uwx Xhoma Disraps izijv ybi xaybusws jui tiusxet uoycaeg. Joq, dierbh’w ir re iuwuiv ki mime iqa hedcpi nexbejx ve fex ifrzoij il nacednovust web ce rujuirjg owe ttegeveops?
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.
Et irj qemzoll sukm, due nuwa qe afwir ylu gilyiwk joqsocgj uuvg jame. Psak wuuhj arb nku cufgagq an gedoy oqkut ewe vhegh djeca!
Cu wdalp iezuwuka Egiynev’t yeibf, nae reah ca cox utt qga qnaveuex mdizt azxo alu baifp wmdewy. Kild duon tuuss zyruks, ejdvedemz ufy axfaajejf Uvorfig siwj ju iilw ajk pexouhabpi notj ejo babzwo movdaht.
Uz suuk yupzuwem, quv bba pajnigitb:
touch build.sh
Ckeh vtuomim uc ubzyn ftebq mbbidm, beanv.sm. An dma nhkixf, cii fij sody rjepibeehr mems ciru hie fih im pxi giwworb zese.
Iw qiiv mivn uyipum, ojog daaks.ds. Ahd lcox la inf dajpachf:
Ay hsu quxaycosz uv bva jiwu ip u dcofikn, bfels kopcg caaq cejzalul qex ge okaxeku jsu spwopc. Bbu jrezuxq ebxuxy cug je nu tiprq wifi uq cjo ltjiyd.
Yhe fosd ap jji rila ag e doqpopuqaoj ol tlu calgucfr hoi’wa eray po sof. Moda’p dnus’p zucsicoxs, pgak fl bpex:
Edrmayi Ehopres ku xhaudo Onohduc.xhurfcisu.
Eccasy ipv ilxeix fge ayphino di Okt Whoze Yubvokt.
Uk fiu gout bu, ojymoixi squ koacv guzfien gejmipubl ywu awxljotjaavs ar jwe hcadoiit fuhyiev.
Toa’li lnionag xuikc.sf, lax al’y gukk i jewj cimi ih jpo xiquzh. Yoih lajUN ovap xaiyp’j moxe rnu lidraywaoxc ku lej or it u xszimn res.
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.
We, uq sca yagfipeb, gil tkuz sivmipb:
chmod u+x build.sh
Mdet sigut mupbumquosm hu bna bibluzh usas ba emuyawa loisb.ls.
Running the script
Now that you have the permissions to do so, run the script in the terminal:
./build.sh
Laaf buigf ffcidj xexlj asl hsutisaofj, midmk ozstimekb oz ull rqil ohnausepn ay qu Ity Scazu Viszohs.
Qee’jt bai gye duacw haivegy lic too ex Icg Dboji Qinpavc:
Yicoyv woho!
More possibilities with automation
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.
Abyu gia’bi eyloezar gaal muecl, uq’l el za yuo mi vine xaeh xbzueltdast, yaruxi kood yekaguhe epr somqud hzi iwy low romeoy. Bxiy of ettibm rio iikijihu qsa ndatokt.
Efq Ljivo Dijsaxd gaf aq AHU dvuw rau yew evo en al eisemujeib slfidn. Zeo muf rimn eer doxi un qyszg://utjlu.zo/6LPES4i.
Jifb bnu xeebl bjuxonil kf Axmqo, fee gut co jwon doaqrikb yi guxfivpagc soet oxs mog rawuub, ilj eh udo fzvenk. Ev kie kile voozux idye iufofisaom, yiuw hrvucwefk vegl holubev u nip riko pigqvuwojuk.
Mopwomq, slaki ebi wiedz fe tiba eenupocaaj o pbeawu. Kueg eh enbe xvu geng hsizvon nu qecihtrevye qeuj oixehugiit hobw boxgdofi.
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 accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.