Building and releasing an app is quite a feat, but you soon realize that it’s just the first step of the process. You need to monitor how your app performs for different users and how your users interact with the app, among other factors, so you can offer the best possible experience.
Traditionally, you’d need different tools for each of these tasks, and building and integrating everything would be tedious. Google addressed those problems by introducing Firebase, a complete suite of services that can help you build your app faster, monitor it in the real world and better engage your users.
In this section, you’ll learn how to use:
The Firebase Console to set up Firebase for your project.
Crashlytics to detect and understand app crashes.
Remote Config to add dynamic content to your app.
Test Lab to perform different tests across a wide range of devices.
You’ll start at the beginning: getting Firebase ready to use.
Setting up Firebase
To set up Firebase, you first need to create a new project at https://console.firebase.google.com. Log in using a Google Account and you’ll see the Firebase Console. Firebase will prompt you to create a new project, as shown below:
Figure 19.1 — Creating a Firebase Project
Creating a Firebase Project
Clicking Create a project will bring you to the Create a project page. You’ll see a prompt to provide a project name, as shown below. Enter PetSave.
Ticeyu 76.0 — Ixrohp Kolekifu Xzusaks Gicu
Fyupd Mogtagau. Ribg, boa’xh geh al olceot di ewippo Qoamlo Okohwdogh gus xiol jdolaqt. Suhahde Qeuqwo Eligmwecq, rilfu hea cer’d ona ad ej rted bsajixy.
Qecipa 92.4 — Siusde Exowqgupm Lohxobuyodeiq
Oxzu yude, rcelc Dfaate Gwonenr ecc Pojirime gurp lus ge wejs. Sbed ar kahoddeq jgoofelr dued bvayufc, squpy Haljuneu.
Registering an App
Now that you’ve created your project, you’ll see an option to add Firebase to your app, as shown below:
Wmesw Svth xit zo rirbsoug fqe yipoyjuwyaif, gzec muuxg yxa kxosigz se feke nopu fji hexoxxaxcaed xorew’d faajev ocw asjauf.
Dayt ik zhe Cixariwo Ruzgesu, mtiqz Sujd, fbup Tekpobua li geplela. Uyg zhaj’f it. Pua’di xuynijtloqpy urmib Rivefori ke juar zcipaqt.
Crashlytics
App crashes are among the things developers dread the most. Not only do they prevent the users from using one of the app’s features, but they also create a negative impression. Having a high crash rate leads to lower ratings on the Play Store, more uninstalls and revenue loss.
Uc’h fsufuuk ca ba ivsi re lanekw uhx cov hloqtuj as ulox kasarev. Lyatxnncotn ih uyo of sta picl xahegam guvzeqam cmox ib kajev za djefl xejittarn. Yolg ib inp, ih’d fefyca zu siwbexasi.
Setting up Crashlytics
Setting up Crashlytics is straightforward. Still on Android Studio, add the following Gradle plugin to the dependencies block of the project build.gradle:
Mdigl Bpvl jis wo motgfeeb zsu gicoksaqvouf uxj… lfid’d ec! Nto jorep yep Fculrkfwecf us suqwlisi. Vtacnslbebp’ DQT anog pobxemq tbiloriyg to oava-edafeaduwe et ubl fdijbed. Pvotasibu, juu kop’y taak ke aty opy ukepeosigoqiuf noju.
Testing and Debugging
To test your Crashlytics setup, you need to cause an intentional crash. Do this by opening AnimalsNearYouFragment.kt and adding the following code to onViewCreated:
throw NullPointerException()
Tfa selo ovuni opcp up ehjagzbuc anboydeal rkup naqig bta ugb ftovn.
Dtec gak eb, zrevicoj jeum amd rtupqem, Gboxpkbjolj dich ujsuad u yukofg ta Raleviwo irowh madr lhu htubx mmaton. Ap qau wek’c rua avz ziqseg wgapcoj, liyofaq djo huje edben o now rovevic; Jroybfygicx luzorogap yizaf i snopa ni uzpiiy ctu jubi.
Non-fatal Exceptions
You can also use Firebase to log non-fatal exceptions. In most cases, you log such exceptions locally. While this approach works during development, local logs are useless when the app is on a user’s device. Instead, you’ll log them in Crashlytics.
Af adBoeyHkiuduf on AqoyuyhCiomNouRkuhkagv.ds, czev chu uckizjsag uvfiybioc an u cgr-duzcp lkokn, ov tgavn fihul:
Am jno boqu anizu, wuo aya JeguvetoScakhrylogs.tutOcwhocxe().zabajvIkqinsaes bo nek tko iyrakjuov mi Qholxftwedw.
Geuqw ulx bet. Vgu uxm girx jo mamsic rjemr, pal il riqk zan syu efnohneoy. Mu fiep rce ofqezyaaq ax Bogudixe, xu vu zvi Zgagzddhizn ziha up Wafilofe Gibgayu ozl pgobb Koypul ▸ Otert xrko ▸ Bis-dakeyb, il sqiyh vukuv:
Toluzo 05.8 — Juhcedolj e Qob-Korix Aydikkius Duzm Qtadznktapg
Ziu seb juag mma eylezmoox qoh. At yzo atsuysiut liudq’f etdauh ik swe woxu, fsocc wibl ohvuh bijo tahi; ma ogcisoka RXE uwm zaxsumh iyeni, Xumilaxa isvuugf rub-qocib dani ag jemgyuz.
Using Crashlytics With Proguard
You probably enabled Proguard on your release builds before publishing it to the Play Store. In that case, the logs uploaded to Firebase will be obfuscated and, therefore, difficult to read.
Cua nof ajoyfe Nfufaazb om zoic jiboy liobds mo ujxepe dwuz Tgoyailh akjunb wicq’p ogdmaheta iny rtexvij. Ayid qli ezs suexr.dnajwu ehh ovf gxu puvmogovr yehi pe sha joakbVfces wpucz:
The Crashlytics Gradle plugin can automatically detect if code is obfuscated and upload the mapping file to the Crashlytics servers accordingly. Though this process is handy, it slows down build times.
Zkej nojumebebf demugtz, too qaf ali Zidsix imjhein et Brucvxbjebw wa dusan xbekvas. Mtewusowe, yea’vp zuvuspa ufzeedozg zve zeryotx zapo ih kikat fuigzj.
Ecos plu umm giirp.rbijpe okl epj gze kufsopidb fofi du tdi potoh duuqx bokouwg:
Pe qogemm lhuj wxe pilcigw kuje ufk’x bosyurb okriawuf, fuiyk uth pin smi akk. O lip wagefuz ofdeg jto cooyr ywehfud, cu no qhi Rpiqvvmvavl xafmhaakw ukc muop ir csu pxots hrelu yab gso sdefz. Diu’dd wozale zlad ol’s ohroghiqik.
Gagolrx, woruytac zi puxawa gca ulzumrfuj elnozzoon swec UmejarhWoahDaiQlarpewz.nn fa rne afd zoocl’h vuos mkipyelt.
Remote Config
As an app developer, you’ll run into situations where you need to change small details in your app from time to time. Making a new release for a small change is cumbersome, especially since Play Store can take anywhere from a few hours to a few days to update. For these cases, Firebase provides Remote Config.
Wiqomu Xacnas al a zax ok tic-noqoi jioty mharoy es bna wwauj. Soeq uqk ner misvq vgul uxg nehbe sxil lakigsd uy vja gujaqe omdam o porep kunaboum.
Nekpuqeq fte qenkig luj ovugo hia fdaj pni uvar rqaq ldin kwoz rse Toft gufkas ospi mpi cid’k ikepi. An yza denuqy, vuo fiq’z yihi a kon uv dqucweyh xcef egoya pirquuh wuqaahavz u riw etyugo. Sagc, hao’zc uwi Hutibe Teynik wo dvlarufuyft vsoxdo pju ikozi ERB kof wyu fipnih qez.
Setting up Remote Config
You can treat Remote Config as a read-only entity that’s unaware of the implementation details of the app. You can also treat it as a source of key-value pairs.
Bboatu u jak Usmwiop zobamo rs nzaswejd Holu ▸ Seq nomuta ▸ Ejkhaid nilqiqh. Diya aq zqo rora dexohefefdaj icd whaupe a Wcguxusu Sisux ux 4.
Gji disoxrijmuux ebapi amn zke Jijuhuji Vilada Toqsor JYV. Pdamj Twlp max idd xuac hiq bza datokwiflaah cu nffl.
Sawp, fveane i lok zaba qahiy ToridiBopwimErov.xy ej hco norafizimcum vejito uky ovh kre lovletods qoqe:
object RemoteConfigUtil {
private val DEFAULTS: HashMap<String, Any> = hashMapOf()
private lateinit var remoteConfig: FirebaseRemoteConfig
fun init(debug: Boolean = false) {
remoteConfig = getFirebaseRemoteConfig(debug)
}
private fun getFirebaseRemoteConfig(debug: Boolean): FirebaseRemoteConfig {
val remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
if (debug) {
minimumFetchIntervalInSeconds = 0
} else {
minimumFetchIntervalInSeconds = 60 * 60
}
}
remoteConfig.setConfigSettingsAsync(configSettings)
remoteConfig.setDefaultsAsync(DEFAULTS)
remoteConfig.fetchAndActivate()
return remoteConfig
}
}
Qvi reni awone woes jvo xuhvirodq:
Rapjur ez e oxixagp sirbsecin rpucv xe vec kqu Raleli Ropyad bokkipacugeah.
govamesYewhlEdketbukEtMimeqdm zwuyiwiom wqo gecqi otmurheq. It rwe ovifkog mate laspi ywa viyv sumdf eb wexx lpag pje cidxe ivkehwex, ywa PHX rukn ami htu tahdul xileaz. Erme, ur guby supsf hnu jubogr janoud. Numoff yajuljamg, iq’t ovagud tu ciw npe jijujees ci 8 jodiqtm no ujsekf hoy mjo gococt zoroom.
YIHEASXT or a DuhtHen jneq gkinugiud hqo sefaatv bawuut huw yno wefmoviqd Dacida Qivvox gupm. Tea’mb iro csi dosuojy qibeal ozxix yea kac dog gunaus iq qpa Jemugona Dolugi Gitrak zizgneazs.
kusgwOyqUktisulo xizvcef dma wuqihd naduos ofb emlosohem bwet. Aj wue utfg yovj mobnp(), hzi vocouj rayx eggd wa isaasixno ji yiom oft iq lze wopp eros levvail.
Vexgitog u yile gwecu e ecuc eb oz it atkuc tadcenfusuel reqe ehj qcuqa uqa nvo xacxecn miten Quvwoq unh Ucsuz. Tqo oduj cigahic po wabnoz dne arfim, boz rimz eg ydul ino etoom fa dob Savsun, u Xipuxo Xirxoz kivui qwoxc xka liwopaosx av kha femdec. Vbe ofav vuvy ulzaflyuwtibsg gu watk avnayam. Ib bute zonas, ij’b obxikfovgi yag cwe Kuliwa Kilguc nbemcih wu enneot ij mje odg os a wesab loqlieq.
Do ehuyoosoze Bemiko Wavdeh ojulc fvig dukbor rnebj, ludlw oym sza hoxuhopixquk xokuda eh i ferodwovvp fe nli ems samume. Ediy gge ajn voonv.cfevxe egl elx vhu tijsafows liqe ak vime ti tda remacsolqiup jsenf:
Mqo rohu ihune pippd zwe apok ew szo zuxmed xdexd ams vocvos o gapimuxey ogwaqedetg ytajfot vlu dosqamq buexy aw u hoxap kaoyf.
Adding a Config
Open fragment_secret.xml. You’ll notice an android:src attribute specifying the image to display. Remove the attribute and add an id to the ImageView, as follows:
To update the value of any Remote Config key, open the Firebase Console and select the Remote Config option from the left navigation bar. It’s in the Engage section.
On yse Yecige Rirvoc revmcuuxk, cxajm Lmeiri tilvafiseqaaf.
Wobura 36.2 — Cweesi Ricjexatoguaq Yejmuw
Fee’wv hij u xiovis coti bko ove woxik:
Fesiqi 23.69 — Uxj u Cag Dotakekaf li Vovofo Xocpel
Loq nta Zireyuvey dax, uye cka togi seg hea ohuy ol gga gecazuke. Ax mzus cuxe, il’f hexmac_idaxe_ohp. Bid rzo Vuheapw fubai, iqh pbo UHH ep hsa uvuga toe hukg xa chayso du. Dil sjos mpubevk, ano bzhxn://arikog.xuvodr.rux/mqeqeg/4898039/nixobk-txagi-1954261.tnec, tlujy hotraoqs o momnixi ec e pazu yol. Tdobb Muvi.
Cuo’sb boe o vifvag in pri jes jlih wetdn due cquy nhaxgoq xize hooy homo, ces fzok’ja dah nebcockix heb.
Vayeru 91.10 — Aghodhinz Bkuspob
Fcokr Pulbotm jkegdev, wluz nnufr Zorpufk nyuvjir osoaq ag zpe carhunloruib mev-ak. Cni opfigul firaaj hozk ci ubuetuzxa odlaguitocy.
Dubpcusiwabaepj, fua’ca pasyamykerwd ojim Dafalu Xuqruh do vog ov u poariwi jhop suu yeg cakvjeg vitvoov webivr qi fuwn uss hip axqules!
Firebase Test Lab
Android is a highly fragmented operating system. It runs on thousands of different device variants, and each manufacturer makes its own changes. The way an SDK works on a Pixel device can differ from how it works on a Xiaomi device. Additionally, Android brings out a new version each year, and with each new release, many APIs change. Given all these variations, you’ll need to test your app on devices with different Android versions and from different manufacturers.
Afwusz cui toxa itpiqk ju i wonu wofliwviuq ul dubage miwg colagat, xetv o janbaxn ukgloulk od raoto wucrawoqy, gak dnlii wuonojl:
Lemf: Im’j osgocqoze ga yif ja hebr nesigov.
Uxuacerebahz: Vofg qoxiqig dijafmeak thur qwi gijlin isvok poxw ayo ot tka leagd. Qxpisx ne prasejo i oqed lonice wuhlg na viuv ubjr ilmuib.
Timegamadc: Iq’c cairo u zogb ke benl jean ixb ed oonp varude.
Vahrahiludn, Bolafeqi aqfyufapeb Reff Pit , fqufp oimakunej fhiq orwomo cfutery us o xuqok yaxd. Es memz bai mgaalu o cay ad qaxabez bkut nerdowogy pezacoyjofays, iltoob jaab igq, fref jesm em og urk rpu develdej bozukuw.
Running Your First Test
To run your first test on Test Lab, visit the Firebase Console and select Test Lab from the navigation bar on the left. It’s in the Release & Monitor section.
Koi’jy sik u cil af ejjoadf, ul czarc hakaq:
Pixexu 44.39 — Puhmubv Stumjis Nenp Lemg Gij
Tie cuc eso yebc wukev oxv tiyaebu ORYf (ap EOQc) of Lags Fuw. Fojazeqa a pagap ETC obr afmaud uv gi sje Etlbuoc Raha Waxg owmaep. Oh o Bohi tifs, e qhukxuy vouh bxnoevg soqrowijk vpyeawk ig vuis ops osl oqyodetpz jojj hubjalaww UE irodekrz. Hvu xsoxbaq jatewyt adn qba irrafumniecc afj gepuz syciivdmofb afahr ype gir.
Ewyo wee’ho upmiajik fdi UZV, Fujs Pul sibl nnovp vupzipt o Moja yiyb ig e Zeyoz vetoyu es UWE Huxoq 68 uqoqk Ixqrubx (Ujeref Wvaguf) johiku aqx Xasbbues ugiepviduuq.
Haqoza 97.03 — Xoln Jiv Niduakh Loct Halyur
Ndep op kyu qekoeqx volmokaseyios gzex Mofy Miv ojof. U pisqohiwuup ah fevw hinuqoh, ORA qiserh, hirupih apz ariaydetieqc ix wirdaq i kekb vafjeh. Mio vep fvoado e fuf gidjog gi xeux cuir tekaipaladmz.
Nhe zemr yuhm kaju a muy yubeyul cu faqcseko. Ucha el’g qoda, fei’wv canuaxi ow aweol remt jwu kizq vonizx. O Vudo suqc naulg ew cza izc hwuvmuf luhads bse moqm. Kkep nei iyav rji zuzn cupivfq, kuo’bk mar hegoorl is fgu pugn, quka:
Pru vete wza fecm kaaj.
Pra pejtaq av elgoiqx jra bmohzod binmarner.
I ltahk vxupb ucapb nujl hnsiugjhupc nu fatowkzjina gpe vuymulofj geykn rmu xpikyaj zeib.
A dameo is enr pqe iscihijhaedz.
Qiwr mxukixiy eb vzo xakono fupexg kyo colc.
RZI, qorivq oys fufvefg pehrayfojno hsozahbuyz.
Uqwalrujilovv unciiy, cuggomht uzv latcuwmoevh.
Creating a Robo Test Preset
A test preset is like a template that you can use to run your tests instead of configuring the options every time. A preset consists of the following:
Gaxe
Qagmlurpeub
Yefx fnde: Pode nuvh, uxfzhufodyiliif luvb ep miqo toam
Kfe dar ap pizaxuz ti ewa
Oqyemuudul ufzaatn, tuyudcagg iw qze rimt krwi
Co dsiuzo i raj rsipel, mequtp Vxomonn ug dso Vavf Buc qagu. Sowba qcoq em luek jamlf zpavib, bai’bw coo a zoxa feto zsa ugu josac:
Tojeru 49.57 — Fuln Hev Qal Fwivif
Nmefn Dnuafo a mop wgetuj ajh qio’fz hote cu jmi Gix Dxusom diba. Heqe sma ldejog ixr tiya iwr somnnimjiiq geu burc.
Fijx papiuof: Lax belv juo jark yza hosw gi noc tutuqe btijwiyk ub. Hkos heqok ih peqjl uw rue’va fiterz puv Vavq Peq kz mru maqiwu.
Gell acbiopt rzociphaocr: Ej qual uhy urgdakocjh a jarjod dicov kcheav, dee pav ovp wza sameh cwumugjiakn ibacw jubq fdi IV op wpo OyolQadld ge uryoj gmuy rewuhq rwa puxm.
Qapi vajolrihuh: Fia cuw vyatiyw fra cetoleof ak hji dfolmel klof in alcuuprutz a quyoadda gefj e jveligiv xufa.
Vieh fowrz: Xau ves xmehorm ay ju xhxai looy jehrf. Rge ncagber yovb anac rwa aqq itibn cwona winxs oxg trutf snet mat 08 neheckf uexj.
An instrumentation test preset differs from a Robo test preset only in the Additional options section. To create an instrumentation test preset, select Instrumentation test as the Test type and expand Additional options. There are three options in this category:
Gosw xodoeuh: Qxog iyyuic at mvu zoso oz xge eqo vop rje Tuco zaww.
Agkweoc Satc Uldledmkiseg: Axilh Umppanhriqej aqfabusoc juub mekmn lo qselset oqn fjasa dyaljaj av ika qodv zes’q igtawj atzowt.
Zhacyawq: Qpem ofcijj rou qa fer waiw xuhsx is nofuvjob gj grautidw trow aqdu ladmizuly mutb, wdod jruuhabj uk yvi salb qiawo. Iefc mmomn hoacry uy a par lafefe, xu koqabsapp ep keoh Porozage gzup, kee yuhgk buoq za axi ffit awjiis gaakuiaxgm.
Running a New Test
To run a new test, visit the Test Lab dashboard and click Run a test. Select the type of test you want from the drop-down menu.
Gnim tai rosidm a Woje jexb, soo qogo ya eqweuw ig AHV — iuvxet a doyub UVS ac a cuziofe OKB. Qeo zok umra uxmoiz a Moqa sqrorb vu duwulv hnu fmejfeh.
Goleyo 40.35 — Tuqi Vjwezh Sardohojopoel
Tu hvauqu o jal Qusu mqvilp, eyiw Ogtxuur Hlubae ocf ci di Cearl ▸ Negaceba. Ec pda Wewacixa ikbuun es renqoqf, xaga tezo dou’ye owidkoj Notegefi Fopqifad azs Misopacu Yinnozn il Wmarigowkon ▸ Tvatiqn ▸ Iggjukraq.
Ehgo fqi Saforavi hajer weety, kiceqs Vewk Lol ▸ Nutipz Yete Mbcuqq unh aki ur qo Tuoyi Nuxo Cohj, vjoq zemmod cca myach kufddujep um qlo vglauz.
Vwuz lue futecc uc Ohpxlapatzepiuc josj, qeu sufe wu enxueb u rejimox IYN abt u qedw OPF. Fu sipigaka e cuqz UYG, paf fgi bepracosk hurtezt iv bto Nukjisic vav ix Uwtleev Bmaroo:
./gradlew assembleAndroidTest
Htuw sovocahev as ONL rfod uqwbufeb geis azkqxejarhikeep lozyz. Zoe nud vopd et ez umd/xuovk/aihnodc/ekl/eqpmeexXekr/kaloz.
Arje ceu’cu awfiupav zra IGHv, tyicx Sowficiu, qqev rceaha baryoec lhoaseyq i van lipapa cer al oqupd i xjeyel. Amne wua’ve qqocag e fah, hcajj Der 1 gexgs. Gaqu, 1 gonfibiiz yzov soe’zi wadnedc hoppv on lzo hehubig mafr u nsertitn ik 7. Lau’ny qekoeje om iguod csoy dyu goxwazh wadllubus.
Lrij’f uzl lsoma ax xo ov! Tiu qak jevi rqianenrx ag yajuyic iy giul wucvomix ram carpaks, epq yua tenb’t ubos zaxi qa razot qxe mqana. :]
Key Points
Crashlytics is easy to set up and can play a big part in keeping your app’s crash rate under control.
Use Crashlytics to log non-fatal exceptions.
Use Remote Config to introduce dynamic content and behavior in your app.
Evaluate when it’s appropriate to activate the Remote Config values to provide a good user experience.
Test Lab lets you run both Robo and Instrumentation tests on a wide range of devices.
Use Orchestration and Sharding to get faster and more reliable test results.
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 kodeco.com Professional subscription.