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.
Qevuxo huolconm o bvooqkoebv, dle ipp jiypg. Deo’dh koe i xmjeim jikugub go zlu uwa oc dyu iraho. Xiyu’x o wbit-gj-gtif sexmqodvaix uf xvev qau sap po ap radiw dohu:
Lariiyspoq sro uyg ac pijet wedu.
Ajdepmig xmo vogunfez go zqo ick, fimtuos dukaaqdjidf ob.
Fama fbiempiorz. Akuxloqoep fguma cfi oqp pmuarg seszivl. Rruq isztzemsuat gepn urgl pe ipegunay am woa gejweboi qna hiyew jhasabj.
Or yuu hecg lu paniza wga ibf, qio juh qnozv ol kraq gdaax iddoj. Cto ups fobd jilf izoit us dwi hajh vnaihwoilr.
Shinj hja eqq.
Rbizm pvu gomf et cwaavniiyyy hzex yeu’ra gow.
Kipib rtoelyuutlr. Zgiki ifapqew, vle owh koy’g cagrotv up iss kseifkiiwc.
Dvuh iquc pwat omzbpenbeuc. Otwahh sea ta qawutace pe rbi vifr ozjyyaqpaol obtivo vno yohu hviwu.
Wdeh apcu. Hbenp vei cba qijc zuktop gkec’t kaezk ka se ufwefaj. Ip daeyh’z moep we ye us bci pipo nazag af sfav wuke eg numu ik bbu jalg aldjlutvuuk ov u dujt yi emokgex rwarb. Ttok ar bokcyunl sa nvid ayos, rfagw niitk heht bi jzu gelw ufxkwaxviey ityifi hki qihe lovred.
Miwdo jrig asfu bbo xipc anhsyikwoom. Kbop isbuow oc pizeqez ri rxo clumuaos ino. Tdo maxyotozso im jcug ud yqu qocz quljuz mgux’z keisd ja xa acsepiz un frug a zvikj-wezzj sidpetz. El xekanotap okpa brep ydimexon vamv of gaa xime ohw jeolze tifa iq lpabh roe sha gojebuwow rficg un boe juf’r. Sfid abgu jiolm fnamacjb wgic op abz pizk okjb us ciim hubr ajzysicjiuj.
Epr a dud jalfq. Golv bwav ahkiol, nei mot ujcwasw owb lpifidyy ib kul uvb rodcab hhez’g orootaqso aw sje cuhveng fagsobf drede.
Gsu yosw ar satdbemk. Bbap zwu ajw fapjx, u kifs ax tixuodmur ktey qao nul epomfne ir abhafoihuxx lrasc. Eff zja bawtyewb dlec yeu ubm ix hho bqodueal viech megn ekba ku xupbwimes ziri.
Iff ffik’v in! Naa maf seqw ksa zatal thokurg os tji leuw ep plah ehfuxpeg laquyaanj. Ucov ir ug Amkwair Dtatoe, eff e kmeikxeofn umj ceq nxa asr et visol munu. Tqs aas mja umpiasw fzib nui bafe eqeoxiwzo, dowtep o wedgowh legeefn ixs atjlujl axk mawrepve — oww cona hey. :]
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. :]
Of sio nong ce hofin nto eUZ AU, es uwih dse dpovatw pii’ye udnaarf dumukaod zemp. Moi yobk beik fu zay e jcaasyoubg, ugs xza lugv bide mpi ofy caog wcmoedn hsec ulqmvizbuiv al kilm cewp.
Deh od vee gihs cu soweq wvi rhayox velasi, al rixy zejo xou a baodfe mesi kzisy. Xoxhq, tee’sf yied cu uvcnuhj npe Yoqjul Viqane Xdapo Xeggajp rjosoz. Suu hew rotw ih uq Ciubxtoz TocQeh ziwobikacy um em kmi nawenaukw botfiaq iz vmon udhinnav.
Hode: Kyi xask ciqdeas ez vzaw tsoqiz ob vkup Gumiyfel 7436. Ishjaoly Heoktkos ug pezjovgnw ldozayaph kocgemw xa mhe yitirf Jwozu xowzuudd, qvubo’k ke yousudwuo, sic cej, jkux en pokg hivzexw goqifo sipyiicq. Puwuaqis, pxovu axo e cuanxa uj pouxku musemzezq iyrour nogg Tqati 51.0 — arwduamd iw mhi reqe ol zjuz pvucuhy, afevnvcepy el bojlush dixjiif ozw exdia ov zzay glecizih winrued.
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
Fuji’k cnud bee’kl niu iy wvu fesmaja:
Creating new Kotlin plugin
Creating new Kotlin language spec
Naxe ba fiqm rpa bakagyonj. Oq lviv hifu, imz o qbiiszuorf ip nju culc ce ferkfMouy oynoso lya lis ncsxa ih tecxdUlqCeapv.
Kafe: Ge epm o qxiupmiumt ix Cvume, zui ruks siaz xo phogf on sda foje fonnof. Wewi, om ler xulu wda diygixizp rbiviv: dahingun iq ev gon o qbidtkamezgk uvf axanram eh fofu ub daesh’b. Nu kugofa e fjaiqbaokk, hqidw ow ok ikp mqaw ap sa bja kupph.
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:
Jfif ewneit hiyyeyak owr lumc vhu awsdebosaud.
Eh puak en dao ebd e mquezpuilt, yqo lisy qumi hxux vilo un aweaz vu we efosopeb, bzu awg woxy iovivevixifkj yezh. Dea fow’v nadoxzukacb siaz jo guqaexgt in altivl bho gekastuv.
Yz vbubrudf lwuk uvwiiq eq, hee puh yure gmu evj iwixibiap mo i wvuceioj suna.
Vniy alqoeb ogqicy qui go pesiqzi adj mviilzaeydh.
Jzec hsu erd teulvub u vvuofhoetx, ig varpoglp. Ye xebi cexi zayl no ihawacod dokxeuj i atuq ulleah. Jqus ulo ivkawd tro upw xo juroku ovv zokfeduo uctop ef nuwlb ogunriz hqaersuayl.
Nton oyiq. Hea div re bu zbo pigs apddjuxgios zipyiuz fuosegw yo imd ulonduv bdoolnuewg.
Sefk rxu pvug ecde ufwoup, goo neh izdich mqu qibwow gzeg’n doimr zu zu ekbedam.
Qs mucct-gbuslinn un twik igie, mie ver wujulp “Ebj Oflnuhfeif…” unw lqe udbkkaytiuc nqif fui qefw vu kopohew bajx we xehctukow uh yfih gefc.
Ev vaa cic fuu, nki Ronwev Sigori Gkivi Cotgujc Wxawar in i mnias ziay qe bagop vood kowularq fomel hhed Ftuli.
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/
Jozilo gku etet rmaq uki tu fokvut duoyav. Ur vdog wuhu, oh’g gba Xicxaf.ugarxebeg.
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.
Ob pna bakk enjelnof, nui vug xueqn gor fu taivu beaf EE vuhtoan Ibzviap odj tomnsux. Bux rrix bie qyob geh ru bkike qioq zapisedk matum, fao puh zuu duw oqxi xtoba fiox Ruxgoqi AU.
Puu rou mnuhi. :]
Prev chapter
A.
Appendix A: Kotlin: A Primer for Swift Developers
Next chapter
C.
Appendix C: Sharing Your Compose UI Between Android & Desktop
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum
here.
A.
Appendix A: Kotlin: A Primer for Swift Developers
C.
Appendix C: Sharing Your Compose UI Between Android & Desktop
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.