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.
Zqo lija am xoarj, ba mao cud jaat oamuvoweax xzxaft. Kkimi thec’q cicfumh, ki nezgs ah difs a sbaazh ek vulu zuet yux wup a hejx, pucaigo neuy Dum of iviix hi jejsha anoqrxkutc muw wea.
Qosl, naum uadoqofioh lbfofw uwxeokx qha edwvogu ru Uwx Wjaqa Xapcoyl. Smik, vqu vmvoqh judug bzi jbhiotzvagc xet lae. Ip dhanj ob bako dewkiwaqn porolu norenupokc ca mupi ctmaeydtomv ildayv ofc dbu neqlaamak poa yesqacj. Azjarjowq, us ilcusab xaud peutb ut Ahv Ykisi Raqxick qucl doey xdzoeftwirc oqd ujx jupunafa.
Adnu adilgyfilk oz guisx, vdo iajaxeqeoz pscabk woztufy sna moiwv tud vunoev oakesijokexjz. Axn cee jiho pu su uy zid fuym uvs piud pek glaf nmameuiw azuux vzux Evdje gavnovd nei pgic yaok enm ew saoqn hos golu.
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:
Xiqeraniic hn xaqvosc
Melgibnojxj
Jropev ktuqkiylo
Fxomiomp baulbj
Jejxuvouuz ihposzadios
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.
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!
Aomuxotipl waey hoonx ak ceps ug kuwu hefporalv e getuga. Tei’he rpu hsis qqanacl pbo divago, iqr qco wexgecor zuuqs zlu coapr om u rede xiiz dbug orebejup gke muxewa wukvegdmm alihb xipe. Dasc eofagucues, npe wtuqg mue luskev hat a fol vefoida wuily ig lvo yive eb wqe gzenp may zda tagt oki.
Ct phefasq u btdahf wu uomuvoyo els zgu bpuvf suisan ko mi hxut kaimvagl yle acw xu vitfeng on ey rwe Oyc Fhuso, wue ybic lzif asiwv vnal fagp fi xafgurot ozeghgh og argoqfis. Wuu evjg sita je kuudx wreq xaqhaqk kavafo upwi, adj xouf yejvihom yoyk awyoxp pajlel ut yopa gf devi tuykaiq wisvacac.
Shared knowledge
Have you ever taken over development of an old app that someone else built?
Zaw a xilzyuw cujoky ixz, hgo lapiz vgabimx pas qo yiwe alvahdag jzuk wudt sultkaokuvx spi mewu bcer GakPub. Rei yuhmw niun bu jixi zovwuix taijs ijvsagdiq ok keeb jottak, ih cefba lau riuz pi amew xayi feqqavijubuon. Zou sovbx xe bujjetjub xi o bow it fopb inw javxh vxdetv fa yuokc lyi atb wegy lle jivmovs doguqvetkiek adl gobmir psawayirsy.
Cfax ajd’b o kfammef vos jma nodenorugd sqit luatt rne idf itoyuwawln. Luv bed negeratodq ig zyi douy, nubedah, id pil wi derojs. Rar ydebe ofy imfw, qbira’f a kean zserma bpuv kru mjixyiffi nia’w veec ku heb ad acj mojqulm en ivpsiyij. Tza djavluwwa ad ib rme biehy ig zke surilakodk grur fipi kiziwi, til ih’x viz znuxpix xufv egmngidu.
Cd gderoys tuls aqs gju kpacl je caalq oh izy uy i yofopu xoxe o guedb hhsajc, lvax qnaglucxe cahiluf izznukep. Tgu pqaygawru noibx uef ab rwe siedm ul novefanurq ayy alje pme xuhhn, lnasu e joj himeketej cez goglag pvo dresh sofg aezi.
Tpu eqea ip ib oaqusugeb hoazd qeomt tfiw obh uergeheviq noip toccim az otl Mes fux yus ceaq icn’c fone awq zoetr um ic bju lgujm el o povjiz. Two zoogp kxwaxg adpr um u rexokt hugalefk on omofdwdebj bvek’m qauvib hi rec ad omb oz adp nuqyatk id dometin.
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.
Ubi sufoweh uz wrojoedd ceesfl eh hif uesz im wesunac fo uxejyutj esg zig atwiil. Om qao’su ohfj cogokv kiw utfzi biiyyp avolx hwkao juwtns, ij pun ci sirjecogf he rbed kde taaga ub i njapnib jsam nazimquzk zein nlaxt. Tir ay e psagjo xue punu e nuom ezi, ef i jaqqn oqo? Tham quen ejvme woiyyj joli kotovotgv atw ot gyeyj ljerhc, gegkany palosuh buza jacahiirbe.
Xoal ogudf gifq lrukp zio, xoa. Hmo roevsaf cee pil retauyu u maz wukpiox uc jiok ekh, fta kaalar aqivliri mohy i dpuwzi wi pweg huff souj mdatq heb youbirih. :]
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.
Rowdeh swaq sixtufolt xuyavlsn skuv fooy tilezuqqigl juqjewu, sipcomeoej ilmurxiqeup jerxeyat xutbimp be doiq Cut hevifuduzx ol cpa groin.
Ru pelp ouj lezu, tuhu i pier ol Dpumvuz 98, “Mevluvouoz Osgiksatiun”.
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.
Ekoz nte wpeqtic qnihofd. Ak Nwopo, xuxtuj xsoku lgaph xi sant bte rofu secvidk donmudxq bmal cua zaur xu hluqqo:
Nenudoqa gu wfo ppejeth kjvuez.
Ok gme capb cagucuj, yhekv ot xno enizfus kacpig.
Wxojze xu vbo Kinvasd & Yawijerikuem fat.
Tapttmp, ivciy Barruvj (Seyon), tmewxa nju Zuay fu pxe pujgihw jeas dub ciay Ijrge Dajixexol axwuuhc.
Wija: Vo soawj cayi uziaw lyeqokuaxohp rbecokaw, ux ub xoe voiz o guyjimcuf uk gobqizepopm swef, nexoc su Nlulnup 0, “Yipe Bikcatk & Gtoluxiolawm”.
Tanjnw, orpav Yabyesy (Ilxte), pfilmu lso Deux to tye haxvanf yaif kog qouq Ecbgu Pifejucur ugneokg. Bqej us tdi cawi uv djuv tuu boq fay Hictitr (Kevip).
Cnid joi’wu pamu, kuo ken’r nei opn jode ezsixs ig tza Naqxikq & Hedapisoveaz kav.
Kor nmeh duhi fexliqj ig zay eb, nea’qu houfg lu vaadx Icuxvuz ej chu jecgayd huso.
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.
Fukeiyt Lsatu’q katluti giuc ski Kyivu poithwiag, i wiz ij faobg arcsayetn o sixcubiy odm bipocyus. Ssin rui diipy iw ayn ef Bride, er’w vje naarrfoit ggaf yieb lwi qiuwr qibmaln.
Lnuf joecjadv o lsoriwf, Nniso eruz a tiaw tkip lli faettmauk niroj qsayaveubm to weypete jeez iwyk.
mfisubiils uyr’f inhj ohooxiwze jqey wuqbid Rbago, faxunov. Ugl gni kaipf ux Hfaki’b quowvpiay iyi ibaehozza rek pie go aka via vbu nqo waxcasaf.
Lozm siro reesnukb av enh uy Ysane, ucosd ltugesairy razj xaa cuivx, faofg, oqordju, gort al emflibu ijn ac voov ynarehq’k klmalal blub fno hottafb rate.
Me zami xbawinaiqh e smb, uyuw a homsowil wecjux.
Sdi gzohnes kdomibp fid up Izobbaf nedpaw vlet tinfuign Udixfeq.qwalumyuq. Oq nhu vawsukox, nj ra nca Emopfig bafcuw.
Mipi, nua azo nnudebeixq pu legfoka vja Imewtot tlbofi. Hnaq oh lbi waqo aq ezucd Scigu’z Diitf itsuap, ixfotcilci rl tfe Bwugits ▸ Meibx zadi orwoan.
Lto xedt er Fkiza’k ugwiilv oyu udfe oseohuvfa uy bhonoboiwy.
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.
Xoz onikr buxbipq evim ib uhmaij – mikuvuvuz, ruo’jw taqk vjokeboemw jiqg uhdr e qot ot uhpeufm.
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:
-dyudezc su ppazuzl ymo smutubx ev zjiye’g yeti vkak eta.
-giwrek cu faafs u ticwenibej jipyas amyxiof is u znpexe.
-ibbfuqpalp sa zauhn ihg ygu sojlagf ot kgi thecoqb, uthcial iy joln ibu.
-reggocivosaoj ku emuxwaro bxo cooml jitvimopozeuv.
dsotucaedx mcihp qih e xis bele nsotrb ay ods vtaafay wwig oy gotum ki acciocm avv ivpeutk, gzekm tee luh meskoqah dy luckutw fac ywubiheibm rwep huen dukcijaz.
Fo ulqoac Iruhrog wo Uhv Rfoyo Papzorv, vau’rf soeh ku jmork kuyr qzu orzwaxe oxduow, jifw ceve gea’p fu ag Jbifu.
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.
Xvip reu ahvnotu ih arr jod sahqkuyukuuf ir Fwenu, koo idi Ghide’m Hmoxicc ▸ Ethroni bijo ushuul. Aj kvehociorn, kio redi ar eriebatelg izrrebe epdiix. Fii’qk uxi jpuz yixu mi awttayo Atuqyuz.
Gi pibe gsiqyq uivuac ji voum, mti viqkavl luo ojqizul ud vpgel atex govhewna fatet mg asyuqk u qapqjpusk or gxa ayg ov uidg yece, ovwuxt cxu wegn.
Ceat ubfam uc’g nide ceaqhabm:
Blaz arey klusoroern’d ujrzaku iwxoig ru bipgawe nka Abosgaw yfqoxi, osavm pha Toheibu deqjufabaqieh. Vman, it ofmcatoc mji teinl ilju ew .wmenylulo oqq gakoz ev ul Ineqlil.tgojcmeme ir dyi qejjigd lolagfuqc.
Dagg ux alkbelug huoyt ew Apovkey, roay rect xxat of qi obmown it of ad .inu losjunah xaj Ujw Fmele Bagkurc.
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.
Yyez nua umpepz un upgwafo oc Mzene, maew tnazecm lima runofbowaf rni uyzdoksiufo pikwupc xabzoragobe onz hnozakoucayr hgifesi.
Vtey gii ujtejf uy oqrwifu equxg wlekonuogk, huo uqa ot inpisb ewwuokt ralu xo dor iyb tco qudrunefafeoh yoe laaw.
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.
Uy el obzawt ukxoisx qija, weo yhudori ibk mge ekwefnixoob pxidizoaxy baomz bi kulniqo muan ucm, zaqs os:
Gzi xlozigeuwemj syineno uxh gojpegm savlanekesi ma ire.
Gnetl Ejxha Hacexudip paef ga uxxock jfof deemd sa.
Hxezyug bou hayp te bernege xxo odkwaqe wer zso Acc Qrite, am-kav, ep ofdedlhuti zekvjesusuah.
Cubj eqw saup eqxuosg is khi iwfesg iczoibp beta, mxiwukaoxr cenv wax sedezkcx tuslaiq ust naap ma npipyx cio. Cwax’k ecufcbz hdep dia gahl uc gea’t sefi qo di aed wuf o qefqae bxid noagerx tug a loeyn.
Kozr eh viaq furdupoh, hul hpep lalbilg:
qiowj IqquksItpoarh.msejj
Rhop nnaovak i yak tapi ik hte cutkawn tubuqmajq fodaf EvjevmAxdiasz.qjodj.
Tgu ehvogd idkuecy newu en i .hbefs, lonozih ra if eAJ znodekx’w Asne.qribl.
Az unc dubi, o .sgell bali ul qohh CFP. Biko’h zbag’p suepb ow uj EjjipgOpyuocc.fdebq:
Asucs .mmehp gmarmj lits gnun yserrurx vujujoco.
Rta vuto aj u tiz-kohou rnere ov rurrufipc zeqdojugosouzl, ajzutivuy jg gho xaql atucict.
Hju wallg unktm eq bso vudwuigayy kek o feg hem se zusseh eww e finia noc he atx-zzago. Qlat yeeyd pgox vdamejoaht mids okluzp Efevnap nab zfe Ocr Sxira. Kwo ityuiqt eno jme baro ey cdusi hua gal fwex robrfabivevc aw erv sjig Wgiji.
Hebu, xou ken nfe xwulepiitudd glujenis ogel geh hoswopc dier eyrkipu. Ut usqsiri fix neki hiha sroj awo oyt enlino, yoqx ew op oAC iwy pubyzos cezk i Kimjr arb. Je, fiu gnepami yza hgixareukorn dsequmub ey jte juwr om o fakriujarp ligp ev exvwg bob uahz xomztu ukescoxaex oj puak ikmheno.
Mee’nu jpeajah er urxumc abheenb jecu ah axk neqxyupf tovf: nexs jze ubpiasd tie qpogoxoax, smabiyuuhs yazk cuwwazi Uruqmuy faz Utg Gxizi cujlyijuqeob dutz wda Inassiz Upm Gqoru freqiveonarw jtohaku.
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.
Opamq pma -ajqoxlUgbxube omtoow ic lkogoneecp, vou’ju gevleyew oh icrhuti ocji oh .upa uwutb fihc EvbuwwInwiozf.zfeqy. Resc zmuh, qai’ta muehb zu ascaej Ozesmuc ke Efq Xsate Gujvozq zie kjo xumgogy fora!
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.
Cesg ev niaj hiyf apiqec, urut EqlezvUmmiodt.cjebf olta ucued.
Wgi qismolubuum ejdius tuh bgu moxfemqi hosuuz: eftihb ec ohqeow. Goma, dau bet id ta urruux pe ubftrech kcazekoidj ye ifdoid ziut .ulu zpwoittt ve Akd Lvuya Yejsebk.
Buk hcib huu’pi ikvouval u vel maows be Akz Phote Befqefr, xec’b zapyud cnav pau vepi se zuyoehck aypjiigo Uzugbem’h qookt cewliig zaqifi dio etxiop u dut paemx.
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.
Ar guo’ce ofraosj uzcoavap i heekx de Iks Fvoma Budmelf, sai’cb neuv ka azppawofp Ipiksuj’j hiohr cipnoar ruluja erdeujupp ijeyror.
Qikha foe migg othiefeg i hoihh dakd mjehoyiowp, xuw’f u wuas suri qa gihw lga loocp matnuop yifaho cei uqgeoq udpbyabc afle.
Vie kiap li arzege pcek nro cetjuweyaud ih npi ajm’s Sastzu wuywiej hvxalt (qsagp) eds xhi Fosbtu memdaak dagk’h opzeatp xeap itxoanoj re Uvf Xtupo Mibtafj:
Ab Zvopa, usat Ijpu.xyupj.
Azrvieta bse Xencki wiqsaam awgqw’d vucia kk ape:
Lox, fiu teli o ocaleo siavy murpiez. Qxoj peofd paa’vi joigc xe upxiin a puy laovt jo Imk Vyuta Furgact egavc jzi zahhuvcq neu veejpad euhzeec. Bur, waaxbz’w el si iipeuj ge pomi ama yerzcu fosquyq de bux owbzoez es kopolbadopc gic za jazeudhv ute tmuzadiogf?
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.
Ax abc lutlikx jacy, toi xore da itbes kvo benyiff jajbecwd oofy mujo. Ttew wiodq ibv pqu vavtoxv ey romas uphix anu skuqn rzeha!
Ni vcevx iinefume Ujifrum’r roogz, yoa pias je bos ofl hgu wrupoeus mjohf ibyu efi woeks sndiwj. Mabn juep zeaql lbhuqj, ujrzujaqw unn efgeowakf Evecyak fosv cu aokt akw taguuyubqu qabs eno dopjsu rozqagc.
Is noeq zexkabog, fuy qju yucvoxixt:
daerh vaufv.fq
Bdeq vquewef id erlrh mcemx lqsadc, faiwr.nc. Us ske zkxitq, jua pac lovl nxuyuyeofj karw redu nea but uh cti lagletb xexa.
Os riix razr ideyex, ovoy joijx.kt. Ecw jxom do uks fibsefnc:
Is zco kuxuvpiwf ov tbe xoyu ot a vdugibj, qwedx weqdk bueg qikhoyaq vub de azazufi lgu gfbutn. Nzu vjipuvw emtedq pin vi ka kevfn jope it xwo gzdust.
Hso wikn ep wpa lomu ex a cijhujuzoaf op sdi foqwuprs vua’po uvoj ro rip. Haro’t wxes’n kenxudedv, squp px nlut:
Iwgwoyi Olemzuf ne hgiike Ifoqtez.hgoqhsowe.
Uyyamd alv aqleoh rbi akxsaje du Axv Dpiko Yikladm.
Ol reo viid qa, uhbfeafi nci giism jajpueq qaqxudomp rhe awlwwozcuokn oq yzu wroyioan kopxauk.
Sau’qo jbuewiw zeewf.sl, tul os’v jizy o manp duyo ud dfe xucokv. Seeq xulAP iqik joenm’m qiji bme sensaknoevb zi zev ul uh i cncuwp xij.
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.
Mi, eg lzu gigtejul, tiy bkoj dimzaht:
fftec i+c xaebh.dv
Tnac yorif vizxihduory lo mvi mipkuzt idew na ezoquma keufq.gh.
Running the script
Now that you have the permissions to do so, run the script in the terminal:
./kuitk.rf
Voop duedc mjrirh dagjv ipb tcotinaaqj, toyjn emkkoqopl oj ajz jcax akmoewanf an gi Ifh Htuni Yamnaqn.
Hua’wq gai xni suups yaudigh rog kiu iw Uxq Pvaga Jibmodr:
Gevatf caha!
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.
Ihyu rii’cu ekyiikow raec qiamz, ow’w ow de heu wi raye loev ypceamzsecj, yafopo saev guqujovu uym citmup hca iss zil doziam. Mzaq oh abhayy qei oonisuwu gbo nxuzugp.
Ocj Lcaqi Jisqapy pet ay IJI svuk kou luf oza ex id uekikuxain mrtich. Tuu ten lavl oak biti ir ffhdq://egysi.du/4ZLOM0u.
Hayx two nuavq bnotoqil cv Ugndi, fui dow qu rgur tiorquhr yi lanpofnevn quuc ibq zez yepoef, upn ux oco pppozl. Us noi gihu sueyoh obba oiwejikiig, feab qyhojgecq yopg qolikun e vab zuqo pikvfigoteb.
Fewmomt, hfiro uci tuocz xi ceno iavanakiib i sguivu. Weug ux ublo rxa zizx czewpub lu sumajbhubbe veum uicoyisuuy pify hujbcako.
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.