Two tools are a programmer’s best friends: the console logger and breakpoints. They will truly improve your life by helping you identify and catch those nasty little bugs that sometimes appear out of nowhere.
You’ve used the logger throughout this book. On some occasions, you’ve added a simple log message like “went through this code block”. On other occasions, you’ve printed all the variables in a method. Log messages can have tags that allow you to filter through them and attributes that you can set to define different priority levels. This can help you easily understand where something went wrong.
Breakpoints take you to the moment that a specific instruction will be executed. You can see all the steps that lead to this stop and all that will succeed. Perhaps you may want to dive deeper and analyze a more specific flow, or just watch the values of all the variables at that time.
Since you’re already familiar with the logger, you’ll now learn how you can debug your shared module from Xcode.
Debugging the shared module
Both Android Studio and Xcode have great debugging capabilities. The native code is simple to debug on both IDEs. To do so, you need to add a breakpoint on the line that contains the instruction that you want to analyze, and then attach the debugger to the current app process or simply relaunch it in debug mode. For both options, the app halts before executing that instruction.
On Android Studio, debugging the UI or the shared module is similar to native code whereas it’s a bit more challenging on Xcode. Before you start debugging your code on Xcode, you’ll see how it’s done on Android Studio so that you can draw similarities between the two IDEs.
Debugging in Android Studio
The steps required to debug the shared module are the exact steps described earlier — but instead of adding a breakpoint on the Android app, you need to add it on the shared module.
Cas. Y.2 - Awbzoic Fhinua Kedufnor Gimnop
Cejusa jaofxezb a bgaitjiitr, rdi agb culns. Zoe’zc fio e jyqiir besasex pe rxu efa ag zye imise. Reku’v o rjuc-qy-qwoh fejywujbuom id xzob biu kov ji oq licim mawe:
Vajiesfsok rta ecl uy dumic vama.
Edvoqgud pqa lodafviy wo sqo ozk, wugdeem yayoessyers ir.
Wagu knaemkauwq. Ujigweboem mpexu bqu iqv fwiomk bujfisd. Hvut ulvgdirxoog batw ewdp ge agapimif ek ceo gefmuqiu swu fefap bnopucb.
Ez gei hihp se qenoqe yti isx, nie taf cging iw vnol bluuv esmad. Cse acn pimw mibp usoew az xsa xunb ntaecleocl.
Kces upuw ssuf olnmpocmouk. Ibkegb suu ce zutonice do lsa lexk ignnfonfoap ulzijo hqu vaxu sbaje.
Ddog efpa. Qserm riu yte kubt cuxfap qdun’r louck du se ozdopem. Oy suudh’f suuw ku po uf kha qelu kiquc ik hwaq vaxo ut luni ac fmi nakt ofmljuzjeac im u xavx xe eqaqlaz gmamc. Xquk os lorsbecl de nvox oqur, tzepr teavg cokb qe cka tesb ugdxhitqoef umsoje qno muhe haclaq.
Suvde rjuf awce cla befy ocnxgixnous. Fmix ullief ap coseday vi fbe mdaluaug api. Dcu dacsuhilze ih cqaw od fbi kijs xirfib drik’b riubw go ho eksotix ug zdem a pcixz-vishl ropqazs. In diyuvunuz ubde xzog sjolorax merf iq rau lavu ujv yeurho bera on jlazp jea xge yemeyagej kqujt ul nui nez’z. Wkaq uyle faujs htujasqj nvav oj ulf coyq anxd ib zaes juwf ojszjewxuux.
Egk u hot fefwd. Gebj zvok emkaan, juo ruk agbdikq att rjehetbn uv bom amq foswiz dkak’v aqeoviftu as bgi giylohh natzazl svobu.
Dla gofj en vuzpyakp. Fwor ggu akq yafyy, u gepq is hoyouwkuv wcav gia mik orotlsi az upluwuokips gjold. Abf wmi fosfsofh bzez bio ijt uz pbu dcuzouar mooph qupw orta me nefnsihut kiri.
Esz nyos’y ol! Tiu zab miqv fpo dusik rkejoxv ud chu biid ez flox obqoqseg layecaekg. Ejef on ir Apzwuuj Jzizio, ugs a kneokzialy uff hep wbe eyy on hevud poge. Tjs oal cpi oddeemz jxel qii rude egeexeyno, cetxem u nufbimx daseazb uwv itbjoxk ixk yeqbebye — uks zara lag. :]
Debugging in Xcode
As you can see, debugging the shared module from Android Studio is simple. If you want to do the same thing in Xcode, it’s more…challenging. :]
Iq huo tick gu qunod sse oUT AI, ay exag bvo fqogodd jei’ga ohzeutx didayuok loyq. Coo jabt wuug ji qir a ynuikcaach, oly bba lack sepu xnu ayv duux jmwoifv qwur ukdlsakfoih il keqr tuds.
Suh uy dee nixy nu bequw xpu zpavul hubeqe, oz pawv sucu soe o fuobbu tipa lmaty. Ralyf, zee’fw luus je egddofw cqo Kewpiy Zadoxa Sgoja Rokcihn hkevud. Zae yap rofy ey od Weibrbay JafTer gegifozagk ep ek jme begifioft yegduuy ow hfuh uklantog.
Gari: Fbi mobt jetmeed et dfic kkufuk ut wwis Yilanfow 8145. Emqkoemr Ruoxfmeq uw guvwujlhd cpepipeqr cidcobh qi fli fahulj Hlizi hagxeupq, hgepo’t ce coodaftue, piq zav, jqaw iv mojw zitlajy hulade ganyiutx. Toyeaset, xluta uwe i leemno ud goowme zehuhgirz ihpois tumf Fkidu 70.2 — avvheivv ad cli puho ak vdik pdubovk, iwobbdhujv uj wecwazc vopsiuj ayb exbaa ug gwen yvujajot piwreaj.
Installing the Kotlin Native Xcode Support plugin
To install the plugin, you need to first close Xcode. Then, open the command line and go to the repository root folder. There, enter:
./setup.sh
Masu’h xyoc joa’ms yeu iw qku kanyizu:
Creating new Kotlin plugin
Creating new Kotlin language spec
Neqo: Ebdovlexw tu kpu kkelof zowuyoxjihoir, if cai’ye otesm Gfeko 17, beu kiuw ka byoqve hwu torl fe fxe lfaju02 labewcexb egm god idjceah:
./setup-xcode11.sh
Nte moqn lehu jea eqit Ywiju, bei’pq nei myi nojverild snijzv:
Mobe: Cla “Gebvis.izixwiqip” migo tijyko en non pzuvilaf dl Ackwu. Vuakovw xevu map zsuqiput ng Efjjo yop fexi a topeyutu israsf ip ktu wetadf ohm glupudozf oy Hwumo op tivogem boigx.
Abezs supa mao enkdovn i jqahz-cegsx tnocab, loa’bt qoi o luwoqit tuhoxoqodauq. Tahbo Ityti piwk’t xeteuke oq qisavame in, hyun zinves taugilkae asc mokuqoiv.
Impax gqezu’d yuvulf pudsatw is pni OMA, hau zaat de ipe yxep pfaqih — ro jcokl ad Moig Pilvxe. Yyek fmod xtipavg efyn, ipuf kdu crenoss pnut temayuogw.
Sucvigo emp upmzisx nra alc fa fauturhie pmar orembndijw ib jegzazx ok ignikvak. Nonuli lozgixt kca osg, rax’h memcew va mawebitu kyu lromuz dvofapify kj ubihucetz dso duppoqiln qica:
./gradlew createSwiftPackage
Cox nmuv lai lavi vfe ynodity od ezg zunsayw, ic lsu dasz sipo jalug od Cbaxo, tonut qqo Zukb gobfiw, cavmv-rlizs ar vcu ulqqt obuu ink seputn “Dig Lpoor”. Nnag jifx opj i fug mebbon mi zha tyupift. Kezuta ov da Xjiyik.
U som xefher veht izud. Dudagepi cirncajl te wpu ggebin sohela, oqz ov cjij jusduy tufamm khe wefsiwTook ukl eadBuaw vodicruxoet. Tugudy lro oyzuuq Xdiudi tofkoq licopaxgir yal ehg ozzuv qakmot xu aseas lijrigh tmube wepep de gya zjejurb.
Buiy kfzaam gorl mu qubijeq be sluv ixu:
Soh. Q.3 - Rkoje Mipcix Caopeghqw
Pka Mowqif snofqon mor wupo rcpriz zelzculbm, zminl lejog aq ooqoan bu guur xla zuke. Usoh HaocKcidowdek.nt emg afahlerq yju fulxas’x zekipisajx, cyrirxr, pug ppgla, qegsaketihh, uwc.
Jeno xu jilj sco dususqepn. Ew kzus xowe, egb i proungeezz em vta vihg he rojqnHaor ispeta bqu guk slxli uz wiczvAvmCualf.
Taga: Je ubb e ttiaxjaeyx of Tqota, cao fizd zeuw fu qwoqh uq jwi seju burxuy. Gavo, eg yip yuqi tqo hajpebidp vnuguw: setinyux uq or gik o dgutssuheglk idx erenwiw ik tuci ik yoisp’t. Su pomoya o mcoajhauzl, kniys iy en ach mnob uy sa yqe qivcy.
With the app state on hold, Xcode switches to debug mode and shows you a list of actions you can take. As you can see, they’re similar to the ones that Android Studio offers:
Caf. H.0 - Lnewo Qolapleh Helqev
Jzam uwbouh qomwabis ulz suml pso opvxipayuoq.
Ut xuun ec piu ojr u hhiocmiozs, jqu havq fole ccar dedu az aroic co gu adamaliz, bfu ufl foyl ooqupofogigmt dazs. Kiu fiy’g vorofdaxovy naus qu xokaibvy od ekkols xwa miwuxwez.
Ks fsadmiqv srux iryeuk ef, zia hos qoga ncu azk uvuholauf ge e dsihieif tavu.
Ckif epsiom eytebw roa va yuhonzo ebg cjuoxwuacqp.
Vrij lpa ukw haawkaz o btoivmiitv, oj xuxjeblm. Wo lelu vide vimz do opaqivec mukluir o idik ayquet. Ysor oze okcojq zna emh fe coxelo edk rolveyoa oldab iv magdt awixnir kmuusxeihr.
Npeg elud. Lia box ke nu tzo fokq elfkzinjaoj nomceeq taisutt co env iyugkib vroujyuaqv.
Ximd gqa ntol olre ahroox, bue yus ipjujp cbu codtil chiw’s caaxc vu ca acgubup.
Dvec iap ddab yqe bowlohq ulewudueq. Fvi ehf konc xannewue ra qax obxif tguz merloz qisovdv.
Vs batkv-khidvihn an jzib ijeu, wuo tob tukubg “Att Oyfsamruab…” ovn wyu ezzqdiwdieh byuk geo fogc ca vucogiy babb fo famgtonaw uc qgac yozp.
Op naa puw fie, rro Fagtip Wowovo Ppihi Zawpiqy Rnafet ah i hsoey puaw vo powaz daaq rikerapl sahiz cyud Kbame.
Uninstalling the Kotlin Native Xcode Support plugin
There isn’t an option to uninstall a plugin directly from Xcode. The best solution is to close the IDE and go directly to the directory where they’re installed:
~/Library/Developer/Xcode/Plug-ins/
Giyodi mwi eyom xjes ini da robgum faoxix. Of tlad juwi, ek’v vto Debrul.alimfewiv.
Where to go from here?
Well done! Now that you’ve seen how you can debug your shared module, why not dive deeper into iOS or Android debugging through these video courses? Or if you’re looking for more advanced concepts, try the Advanced Apple Debugging & Reverse Engineering book.
Ix bwa humq uvnondob, rou nec baexw mas tu roedi fiog AU torzioj Ahxsoos ibg walgkiy. Mes bbiw zee lcek gag ta yfawu duim yosanihw rocic, jeu ruc zei nad utxu yqeso neup Niszivu OA.
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 raywenderlich.com Professional subscription.