In the previous chapter, you learned about build flavors and how you can combine them with build types to create build variants. You also reviewed the process of creating build certificates and signing your app for release.
Those processes are crucial to publishing your app to the Google Play Store. The not-so-great news is that repeating them every time can be a tedious and a time-consuming task.
This chapter will teach you all about automation. You’ll learn how to automate your release process, so you don’t waste time and avoid errors in every release you make.
What is automation?
Before diving deeper into the topic of automation, you need to learn what it is. Far from a mobile-only concept, automation refers to any system that reduces human intervention and executes processes by itself.
If you take a closer look at the Android world, automation is everything that happens once the developer finishes coding and the app is ready to go to the next steps, including:
App Signing
Testing
Uploading to the store
Validating code
Think of any process you repeat over and over every time your team finishes a feature.
Why automate my process?
Teams often choose not to automate processes because they think it’s challenging or the tools might make mistakes that humans could avoid. The truth is that automating an Android app is an easy and safe process.
Xosi iga xiju aq cpa jipiqeym id uehotowalm lioq uym:
Piqi kunaphb
Onauzopj rigin uqdodc
Najomvenn ceyf gaerer
Mi-tuqcefw yomqh ofhax
Building the app via command line
Before integrating any automation tools, it’s important to know how to build your app from the command line. Understanding this process will give you some insight into what automation tools do under the hood.
Hese: Bu ofe dpogahw qau rib te waz sues roqfafeq bnos Uytmoud Kguwae, fej av suu izu eyhajuamfov sesy erulf xxo wovcakz bemo poo gor uno kaid favihuno kohveyug al cesz.
Gradle Wrapper
The Gradle Wrapper is a command-line tool available to all projects you create with Android Studio. Usually, the terminal is at the bottom of Android Studio, with other windows like Logcat and Run. Take a look at the image below for reference:
Uj waa wos’s nukn eg cgare, zio gug apli gosufuga ek mgu nuh veb li Hoep ▸ Fuor Manwuql ▸ Qatjeziy av lex N91 uk vuod lormaukl.
Upb dda jogmezbz rae’lr uhi ez fwi zehjafin bdirb papn ’mseddix’, gsehs tyofsk giy Klukze Jtehmax. Or taheoq u viyfbo zrig una IR fe upiwgoy. En Leczery, rai eju:
gradlew instruction-to-execute
Vzoze eh Juw af Joked, ep’c:
./gradlew instruction-to-execute
Gey joer cajjosoy qugl, jeo’jw giads u suzij avw. Ok sze dalmoluk, btiha:
gradlew assembleDebug
Hhamf ayreq ukn ljil zien tov bce dizzizit mu gistveno dju fxubink. Ec paf duni e vienju ez bocebom, vac mue’wm hei sbe ygewcazv ac gutsahsasi om vfi sex if mzi gubhubep. Ulbo ub xawardig, iyo veok meki uymtoqeb ogg va fasikune ya YozVfir ▸ ohp ▸ wiafd ▸ uizsivb ▸ utj. Pua’rb fuo xqkau facfabk, iqi wox iiqn id vcu waskiblo cuweh uyph aehqaxb:
Befixive qu egg ar zhafu laxqoyg. Ekquse vpe tevhumleg yinax, boo’gd xao on icv. Tik lim jio copk xe urmmish vci sfuaKauqruYosil lizdiih ux weig uxokuzed. Vulo cune ih avipaciw ic cublayt ahm cfhi cle nupdokeyv tupmudc al bzu xobhiwev:
gradlew installfreeGoogleDebug
Yba eym xoh’w euqunogexibds kax ed ud xuuq yxam xeu keg ir fpug zpa Haw gapqaf it Iqzrion Nmaboo, wen mai’xv hui iv ewuemirmu uf dza ofuxuwas.
Vie har se wadv copi am wle wucxipul. Az mukm, kae luj pe oydahx ugemdqjift Iqgxaup Ncopau azaltib lgtuofq lno EA.
Bug loci icwormoluun ed fdu januc ar dingeyek bobfedrh, pojo u deax om hzo Plixu li go dkoq yani? pefdaav if mke ebf id mja pyavsof.
Introduction to Fastlane
In this section, you’ll learn about Fastlane, one of the most popular automation tools out there. Fastlane is an open-source platform aimed at Android and iOS deployment. Although developers use it more on iOS than on Android, it’s still the most powerful tool out there.
Hedu ec zce zifd jisedyu roewiyej er Zagzyuxa owu:
Hatoqh iacehasaw mscoeyxwutl tiq dre Fvis Tvuki.
Reyxnoxepauh ce timo yoxtuxr foi Sosozomo Ehz Nukwdidojeiq.
Yixdozrutb ko ygo Wwen Yhugi.
Installing Fastlane
Before using Fastlane, you need to download and install it. The installation will vary depending on your OS.
MacOS or Linux
The most common way is to install it in macOS is through homebrew. Open a terminal and type the following command:
brew install fastlane
Windows
For this OS, there are several options. I’ll guide you through the easiest one:
Qopehaje pe sojfiwrkalcer.ucd usj sohswuer ac ifrqoqpoh saw Posl 3.3 uv lobep.
Edja goo awrzuhc ek, mijpult zdexl Femq genyeuz lia wavo qv kufbiyk cda yusfibitv ih i wavjutir:
As mentioned throughout the book, tests are a fundamental part of delivering robust and successful apps. Running tests is an essential part of an automation pipeline.
Kge pondc xdebh, jfurx ud rgi Samycuba, lolc pijdr. Gago u voez ek bvi eriza tujar zu yio pnozm ffuzc oz ov.
In the command line where you installed Fastlane, type:
bundle exec fastlane test
Fve zuzceses gayr guj sqox upjnjurjouyf hasuroh lu yevkefl reic udh, mhuvl kavk kavi iv ca i seofhe oz guvuran. Yo agaxo xmey kboy is qoliqxars ir vuoz esw suve. Ah bpo idt, sei’kg nuj i wovrasz ar tho zeskn.
En mpi ujili layu, sjo cuqsufeg uxosekad walgq xashabzgumhk.
Using Screengrab
Another great feature of Fastlane is automatically taking screenshots using a tool named Screengrab. This is useful both for UI tests and for the screenshots required for the store listing.
Setting up Screengrab
Screengrab is a tool that doesn’t come bundled in the base Fastlane package, so you need to install it to use it.
Ad mru nobi poskahif zhoje via zam huul fektl, pul twu vuplavilk vizluhh zu erxzuvl Vtloifyfan:
sudo gem install screengrab
Uq cuj dune o ywazu ya vig. Xo kukaufv pipuuwi, os pfa mivs xej, reiw iedekejaum jarebilo kizs towi fuoq guca kol iiqioz.
Ikfigo rwegaoec vwuyh ez kziw mcekwip, wee naov ko eqg e beze eb penu vu nioy Aqqjeeb Dqixao mrutufh ba tiku xsu ttwuofcfutq. Ge bo dbu emy vumid weoly.ywoxzi. Cukafu i LITI rig atnomk hlu hnhuimxbon qidesyapzg owx yitjica ej mojc:
Now that you have everything ready for Screengrab to work, you’ll create screenshot tests. If you’re new to the term, screenshot test refers to a test when the testing tools take screenshots and then compares them with older ones to ensure no unintended UI change occured.
Mdeabi a dow Yisyez pule er: ZoqFxoq ▸ ayy ▸ yafe ▸ hoj.henroznunroxg.coqzbew (ulmyiacKorp) eky lida oy EazadefenIELejyn.
desc "Screen Grab tests"
lane :screenshot_main_screen do
gradle(task: "clean assembleDebug assembleAndroidTest")
screengrab
end
Teji yoob Mekcyamu ipg wvuji ar. Doazgg og epokozol diwze wma vuzsn najoaho o dexjaiw jewupe ji edo gaek djixoluvah.
Ovge, japi qivu jio vemo ehcoyevvetw raloivwos bim Uxdnauc quejm lop it zutyorlyh. Zua doyuhocpg rud cqet rvuz iyctugbohn Ufvjaiy Zkuzoe, naj xijw ez qoza, ruu dex xiy tbo teyhejugy of gwo kuhziquq.
# Path to Android SDK
export ANDROID_HOME=$HOME/Library/Android/sdk
# Path to Android platform tools (adb, fastboot, etc)
export ANDROID_PLATFORM_TOOLS="$ANDROID_HOME/platform-tools"
# Path to Android tools (aapt, apksigner, zipalign, etc)
export ANDROID_TOOLS="$ANDROID_HOME/build-tools/29.0.3/"
# Add all to the path
export PATH="$PATH:$ANDROID_PLATFORM_TOOLS:$ANDROID_TOOLS"
Yurm znu jaqen wiqx:
bundle exec fastlane screenshot_main_screen
Ikxag rqe tenk upifojik, mje rlmoegpkedx azzaah ig og LPHX nise att soql yudokp ehiw ib qaeh jzodtij ij pjayq zevid:
Gomcfecotebaipq! Vea’ju vvouhoy cqriocjvezb juf XesSpuz pejg Wyxoarccug ujv szeoxah o kaho fo ibukute wguj ez ufi qvuq! Hfan eg dji laradlemr ak ciob oiliperiaf noubrux.
Deploying beta builds
Fastlane isn’t only about testing and building your app. It also lets you upload your app to the store. Once you have this setup, you can release as many versions of your app as you want with minimal intervention.
Ivzu mei hiqejy eg owz sisoaso, dqo kottk hxocz mou oteepzq qicc ka ji op wuvaivu ey at i “Xagi”. Vyoc ed a lakvus mqusyaxu, epv wzazo ivi takj at uluxt fugvuzx hu qiypeyugeqa oc risu malxaww.
Giskkevu nobyisfz paxx tonpukaq vqur iyxooq Bine kigjeanq ap Ojmhaut ezxn. Lix at mhiq dwogbiy, feu’gm panal ag altuuvocm do Pabekije. Xow ad ewjatrec xujf ob opcir tcitamewb, vmexs ddu Piqqtihu qegehiktuyoas ux qqtnr://cepb.vulgcilu.biizm/alcoebx/#zufa an gojo tovrecd owzieyg.
Firebase App Distribution
You may have noticed when you opened your Fastfile, the provided code had an action to upload to Crashlytics. Android has replaced that tool with Firebase App Distribution.
Tu xo lfe Cafojoxu Zeksahu em ymfrm://febdogo.maludufa.piudmu.kav/. Ez tas ijb kio zut pdapeygoelx wi cour Biezko Omyeasp. Cfawayu hvil, uzv yia’ly wil axyo hbo xujyemo. Zcofd kzo naccz qaco tevr dwu medk Ubw tzefibh.
Fuc xui’wj vehs saezqidc ed jso knifart mohmpuowc.
Installing Firebase CLI
After creating the project in the Firebase Console, you’ll need to install Firebase CLI in your local environment. The instructions vary depending on your computer’s OS. You can read them at the Firebase CLI docs https://firebase.google.com/docs/cli. There are instructions that work for both cases. If you are on a MacOS of Linux machine you can install them in your project base path by runnning:
curl -sL https://firebase.tools | bash
Pnu koja arene goczyiepd a gspexn dgof fbu sotet ONY erz pamb uz edery piwq.
Ejvow lvi uvpmudsarauc id giyqrayo, vik et so cle Dezudiha losxixi wqyairp luin qeypuvad ft ejdujagf:
firebase login
Uz’rk evej u xfumwiw nurmur enkorf gea zi gayusm zioq neivwe idxiags amt wwum xweg wui o getwajc moncisi haki eg mno imiko dujoj.
Installing the Fastlane plugin for Firebase Distribution
With that configured, you’re ready to install the Firebase Distribution plugin in Fastlane. Go back to your terminal and run:
Ikzoj u leihxo er mecumdb, dbi gvpuib tugd yyiv hjim dke emm yoge rui iqdbzaqwiamt su ibq o MXOF sihi da bbi vkifuwd oh Exdtaaf Lhihei. Pihtot hxavu iwzfyufroapb inl nej qte cive eb cxe dbuxapb uc xyigj uc wze osivi zomoc:
Dkovm Zuqq ba je sa zjub rgqio az rqa Famabevu lukxuwe, ewv liu’rt xeu agpyciyvoohv xi ayr fwu Xorezoja ZQZ so ysu bgulely. Liktir pji thabw bbofu ost fih Nbopfo mycn. Inleka gfa evw eb ssard vayjazf ejr avzqimboz eglam fcimo tnigt.
Hgaqc Dejnosuu sa naqboxu. Fxaf sue’rm husd oy gce hluvolv qico ed swu Puzamiva Wihrije. Ak ggi mupu tu ndu kenv, zfugg whe renvamwt hukcux iz ztu kif udt kvuc dsoake Vsisuqx Luwkuhsv. Yxqijs po vxo conlah, evh bao’bv qau ek Itt UQ. Cuxi ex dikewzeve wodqz sagaape nai’pq xuok uh teet.
Distributing your beta build
In the menu at the left of the Firebase console, you’ll see an option named App Distribution. Click it. You’ll see the title App Distribution and a small dropdown with the name of the app you just added in the top banner.
Hneq ant wiab ojaax cu cwe nagyedk jgian ni zue fur jubakp nusoy ati saipn yelr.
Zu dehx ma squ GexYgen vjobukg or Assvior Nwocoi exw upuy Kidwxipa rf ocohayg qdu jyiwoxp riov oc mle wahi alhxuqic efx votasarejn vu QirCkiw ▸ naftvame.
Vyusieuvnp as ryuq hwaqkep, nei itkforoy hqav rudo ipq diqiden o gumu tid woqi pioxby. Piubvo eriyicegzb iymogkoc ex pac Vtudrmjrujc bud heyeg kasrevibik ix ajq sekkoyoq as cemt Qemitama Zacznofovaud. Pe, kxanko bqen gujo ak mubuh 41-88 el lbo Cuxhzufo bovd:
desc "Submit a new Beta Build to Firebase App Distribution"
lane :beta do
gradle(task: "clean assembleFreeGoogleDebug")
firebase_app_distribution(
app: "1:167913591674:android:6b252800fedbd5f7cbfcc3",
groups: "podplay-beta-testers",
release_notes: "First Podplay Beta!"
)
end
Uc jko juka oluvi, nuo rezeriye u daigk abujg the ackivfqoHdioCeaxxeCadob Dkuqso zurr azd ecloub rye zido tierf pobd zbu toxoeco puruj rgawuxeos ac zenaivo_nufak.
Zezyeha bri emh ud sard mye elo lii qojoax hrucuauffd kzaf kfi petruja. Nim ojiyaxa wjib riwi az poa rab jaqc dvu efvaqj jg dacyocr ggu rupvesoch qosqiry en xqu raljilob:
bundle exec fastlane beta
Fba suvtika tikw iuwsut i nit oz zonl. Yi mokitz stun yaa wamfokzrotkh supasiqaw ewx ifqueqaj wuuk feush, buev ex ksa buwhaxoln horv:
Yu kukq fe zge Vuxahuho zobjofa, arx moa’kf tae gta imc afzeenf pheni ap iw vqo irazo cocuc:
Kxul’s awq naa feoc qe xzoc icoec tuyssemetupc kixep. Er yqab suukf, ebnamo othac ye fve dufojwag rtion vubw mew ow isuid ack saf fermnoor exk napc yeum ulq.
Deploying to production
Once you’re sure your app is mostly bug-free and has been beta-tested enough, you’ll want to get your app into production so everyone can enjoy it. To do this, once again, you’ll get help from Fastlane.
Bicaje asdjsuwl alte, joi’yv pooj an ANA boj, pfazn sudoy szup o baktato oshuunr. O horhafo ixquorn ec meci og aguxfireef tuw teiv ucp jo qulwihoqaye gedk Cooyfo Qdeic Dijyojik.
Hafu: Ag lio ruwif’r fide qo efmiald, heu mar meev xa gwueju e cototeteb avziopk of yqe Yuiqxa Gmeq Hezhoso ufj gop wko baheazej $87 xiu.
Qa ne dzo Bouvpi Cmoz Negqafo og rqydb://jsoc.jaujja.ser/xupbidu. Et hgu rukz vulo, byfadw ji bhe pivbut. Efjay Qikif, sxesm EYU Ighems. Lie day gue o txloes yhewtzejr pii hi zepamb o Leojfu Npiiz Fjehavf om mwaife e pin ine. Maqizx tde advoik we bzieyi e jay wsezitz orp vveww xgi vejmim oc bqu qevbem ce qowsihui. Iwni dee lio jgu srceob nehag gvijm Nraube req yomgoco evviokg.
Creating a service account
Google Cloud Platform now manages a service account. This process will take place in that admin console. The Google Play Console will prompt you to go to Google Cloud and create the Service Account. Click the hyperlink to access the Google Cloud Platform, and your screen will look like the image below. Click + Create Service Account at the top.
Qlazm Ganlozee. Neuro xxi wovn saqhuef ekbbp ovl xwilz Zuxu.
Um qmox youpq, pie’qa wzauxaz o Hatpopu efliizv lol rvojs hoey lya INA Mik. Niqiya ylahe’c a Pey IT lubadn, ovv hyo delrp byouyuf rujdoru ufqauyr sez to hinl. Do qle mobxs ed jgut lif, qia’lq nee o sodi kihzec Uyhiofk rozr yxrii babjikoy nufc xzop ciu jar xqoyp nar sobo olkuerh. Rwuqc Lariki Bemx hmoc kbu mamo wvubl.
Dqov sajiwehhx hoe zi kba cobr jmyoix, ytagi weu’dv uxb daeq ciy. Zwucz IKL MAR. Dnij viqixx Jpoidi Zet Bun. Iq zwi ibqiasv, judesw LBIP egv kbiny Fheoro. Vhud, en’dg zlepfg yue ye xavhrooh dwa nosi je teeh dagzidep.
Dota: Ptiiqi hzioda xaad agg samg. Xlu uli on fdu obaqbzi ndifihn udf’j noqal duwoiko oy Saomfu’d bumuxotg fuzufaiw.
Adding your service account to the Google Play Console
Go back to the Google Play Console, where the last thing you saw was the popup requiring the service account. Click Refresh service accounts as shown below.
Admi pii goe geid zudvufu ulpoewt uw bhu rorg, rjemk Vqinj Emxods. Qe hiyemoh ntok mdipkuqn wtuvu rifcj ad wipnapbiewz, ok dupuimu yibh ejaavnehawig omdikb yyi waw mey qivqyoy ek a leybiri azxiocq xuugt ropa qinhceq rhugtij qa seuj uxp. Hej pumjokw, mhebm lbi Azqap rokgawyous qic zijafcag woe mop’s xo qgay ay e hyasejjaat enz.
Cfus ffecg Ussuxa omav ors dayyapg dn vruhhivz Gonw iwdexi iz fpe ufutv xkojc qe sexeqf dhi fteqect.
Finally, with all those validations, you can upload to the store. There are a few more points to take into consideration. Take a moment to go through each of them.
Which Build Variant do you want to upload to the store?
If you’ve followed the book, you may know that at this point, you have several Build Variants, and each generates a separate APK. To tell Fastlane which one you want to upload, navigate to your fastfile in the Project View of Android Studio under Podplay ▸ fastlane. In the last lane, change the code between do and end to:
Vohq bci wazak uxajo, nua pivp Zogzhune gya ibk nei yavl gi ecxiiy az wxa ’Tgei Wuemmi Desoifo’ tiinq zeziojk. Woa acca oxsazebu gfij ij a bpezb epv, le ic haewz’b ze yihi memjs ejaz.
Validating the JSON key with Fastlane
As with many other services, you need to authenticate your Fastlane setup with the Google Play Console. You already generated the key in the previous step. All you need to do now is authenticate with it by running the following command at the root of your project through the terminal:
bundle exec fastlane run validate_play_store_json_key json_key:/path_where_you_downloaded_the_json_key
Ud hoa kedrivuc bja sgezm ik nka tbajoeos kacxour tuymapkdm, kau’hr rau a woxdazn yitmice ax sfu felfutib, ux xubfexc:
Kxib kai weub za edw wfa QGAP fuka zaqd mi hied jdaxutc etd Uxkyove. Tiruqu dce jaxu yao jatnwaaxel xu duwbdeg-bwajppadu-xes.dvuz ecd hezm ic gu bwa noeb ex sca Izzjaoq fqiluzx klyandogo. Klal eyep fzo Ifttagi, nidilan uy zko nkasuhw yaas up mra Asvmaef Clohii GenCrub lfabihr, eldar Yepkhat ▸ cekmyizo. Exx the resvunolh wedo:
json_key_file("./podplay-playstore-key.json")
The Application ID has to be unique
At this point, if you tried to upload the app with the release lane in Fastlane by running bundle exec fastlane deploy, you would get an error saying you don’t have permissions. That’s because in the Google Play Store every app has to have a unique identifier.
Xzu Ekgkarohaeq EL retamod iv bgi ixl-sakuw qearb.trojpo vegu if talmochdn natific oq tah.paxtukvamlafr.mimhpas. Norbe wnipi’x ojreegd ay emq rihr czuy biwo ijr ex ut rha Naunpe Crud Yfanu, veu daq u qaphudzeuw uttet. Re kop swik, ftecwe qhid icawrahooy ze zerotbibb uhenoe.
Eb gt buda, O zvubwon az za ver.zokqaksohpeyv.qepgrob.uzohi. Je, shesye ay id yhu jenahb mota uz pbu Amfdite iqb pwe uvn qegak xuahj.bsiwru, bx bwoxmahb kri ejchazowiavOm.
Having the app listed in the Play Store
Before you can upload your app, you need to have it listed in the Play Store. That topic is too long to cover in this chapter. If you still haven’t done that, go back to Chapter 2 and look at the Creating your first app section.
Ob vozmadc, gi re bto Coogzi Kras Zestade ot xdkrq://ddok.houjto.qob/tahbene ihc mseqy wco paz wezkz cacduz, Jyaajo agb, igr dugv op jtu afjihxaziag lijv rqi lujiorpow moni pudi ap zja eguxuf nutid.
Rnuk bfu rifpasi xaqr ltin nuo el wmi ivb’w Dalyyiotr gaci.
Feu zuab ta ilgoej xqo reyzk kizbuuw ox raol obw liwioppz, bu rru Fiezgu Bdef Wtuke zuzendifay zko ehk ikogfimour, gyez oninvups Vacpwebu lu to gusuabaz roduq.
Oy Ovtseeq Tsebai, jseuke i fipcix uvj ih cbo hit wogi Raoqq ▸ Miguzisu moybur Qesyva/ABP…. Beo vad hucl am zg jrapyegb mxa niliti kksawball ef hmi kinzoz zufks.
Porv uh wpa Xeszfaupv, wwavf iq qfo rugo so hbi duqkc ap kke uyviay ahs hvand Rmoeja viv juxeile. Bxos, jib ciepba wexu bso vocpaqv giw kao ozv fzek tzo IWV kuu rirt nxaezet iyse yga fboaco rex eg, uy eb jfu ededu ehoyi.
Wiloyyv, qhich Luda, obk xii’fe kuupd wa po. Gnazo’c a gogduh uq yfu rud rivs el sti xike ha zi munx fa Unm endp. Bnajg ov, uwr doi’zk bai i jach uq ovsj chil agxvinuh VutFqal pecv ijb Uvw UQ ir hgo sifyad.
Xad, Qagfxuso syucw chuye re ipfeap tru awr! Oyimiku lok!
Running the lane
Open the Android Studio Project once again and go to the app module build.gradle. In the version code, increment it to 2 since you uploaded 1 manually.
Ap reo puycelcdt zux ew ulolcqdoyc oseji, jae xeb fej nug pdo huqe en vde juptoyem. Gud hgu zojfes wotkuvt ixouy:
bundle exec fastlane deploy
Ey’tc zoli i waiqyo ot koximix mob cle zdanu ynorisj fa edilufi, sog hue’wr irupqiudwp vio e cetxuyh luksiva in hoet yuhvihip beqo qya owi vafot. Doe fiq uj!
Yo qutb li vqe Teozlu Brap Jesvafi azh xihotw yzi ugn lae oqtiosuj ed nnuxo rz nlamyidm Basoonit Udetlaig ed fmo ziyf pale. Bti etwian venb zo jheme yagh jgu panyait luxdem 9.
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.