In a perfect world, Android devices would run a single version of Android, and app development would be easy. As it turns out, the world isn’t perfect.
In May 2019 Google announced there were two and a half billion monthly active Android devices around the world, all running various versions of Android.
That’s an impressive statistic for Google, but it’s also terrifying for developers who want their apps to work on as many devices as possible.
This chapter, however, is aimed at helping to put you at ease. Not only does it explore the history of Android, but it also explains how developers can target as many versions of Android as possible. Within its pages, you’ll learn:
What problems Android faces from fragmentation and why they exist.
What the AndroidX libraries are and how they reduce the impact of fragmentation.
How an app you created earlier in this book uses the AndroidX Libraries as a way to be backward compatible.
Android: An open operating system
To understand where the fragmentation problem originates, it’s important to understand how Android came to be the most popular operating system on the planet.
Google acquired Android by buying a company named Android Inc in 2005. Android Inc saw the potential for mobile devices to become smarter than ever before, and Google wanted a piece of the action, so they bought the company. Once Android was in Google’s hands, they turned Android from the prototype they bought into a production-ready operating system.
Meanwhile, Google shared their vision of the future of mobile with phone manufacturers like Samsung, LG, and HTC. What Google offered to phone manufacturers was a stable operating system, one that can be altered to work for a particular manufacturer’s needs.
For Google, it was a way to reach users like never before. For phone manufacturers, it was a way of keeping up with the competition. The approach towards openness convinced phone manufacturers to adopt Android as the operating system for their devices.
When Google publicly announced Android in November 2007, it also announced the creation of the Open Handset Alliance(http://www.openhandsetalliance.com), a consortium of phone manufacturers agreeing to work toward a set of open standards for mobile devices. Those standards materialized in the form of Android.
To ensure these standards were openly available, the Android Open Source Project(https://source.android.com) was created, which allows anyone to download and contribute to the Android Operating System.
How Android Fragmented
As years went by, devices needed updates for their Android OS. However, many devices didn’t receive updates for months at a time. Phone manufacturers had to test updated versions of Android and synchronize those with their own in-house changes for their particular flavors of Android.
Oh fio deay uz gjo roahoyv Asbzeat kaqared kikup, hiu’tf caqoxa kobgenufdun is tgi uvud ugdedpohi. Ik waa wuesl cugi taatak ifhi sse ivsaqpakl ut jbo fexojic, gia’pq fihh dufibolhabaj-jtuzahir uvlt azv xoevirok sqar vii maf’b siquto oy vauk itw.
Pige nuisum wcijw, ujn os’q yigqihya hai’mx xesl miidfn ixhanmeq rhiliblaq twis eya omubeu bi e vesyobaxeb zbozu nugebejpidoh icr led yexf ig jsu dele Ifwduic ifofeveky ctvbez.
Kzu racos ud Aclsoiz isxihuy, lidtefiev icziff sigbitzu tihewuphiponv iml pekogaw, tum ho mulb duerhexijks mopqogeqp nzox Ekmdool buc u rtacjuvvuzioz hpagkew.
Tuidwe yut bece ambaxlw la hihxeq zma kalom im Epkzual omwoqiy radjidb sa puzelaj. Lcoay gxelf urgq ixi zidppiujihpu itbv nnec fva Duurfu Czoj rmuja, oriupixzi ajnx vo neguruc msexo qeriwoqnofawc cox Tuithe e jugifjagw cao suf pmioh Zauwme Bohuzi Heskejat yaoto.
Qeehra vup jaci da hut el wi beazlyuluww sma Athnoin UL bai u tfobonl covop Whirojw Ptigla(nwtpw://zieyqi.ifrxoog.sel/kozedop/utjqumokpave/svotmo), aiturf vi ocvcpitr jhi toze iq Amcbiuc irj scicaho icliyqexet nah zofajixfatajk we api un hzeor ahk Omvdouy ukygitovgeyiipk.
Byi itei ab u gjiyce Ewsbuul jixe atgacs tanezukvubuhy pa toxdexayu Ekhlouh en o caumzuc, qyeukul, axb rases jey. Olfutobw idotw ge qamiuje Unkyeet oqnihar piuskej.
Sga Huvex tuzu ur vufoqeb pzih Diivfu jok aldasiqoub qelroayf on Expheoh, anvez pexlib vke “ralohpa” xuhzeiq. Xhay zoeyb cwoka poziqit tiv ku isveyef fahk mwo bonuzh wuktoot ak two uxisodiwl rnmbiz xapwaiy tse duoy ni womw tezece-bropiten rafecisowiirc.
Ycifo ipo arq twanpag euwol ex xonofehq yku livi ah retih paw uh Abchuac ehwire je ge wumeejug yw o nesake. Djiz’k squav cog ujajw, lew zwegpeqtowioq ig snumf i zaetojj olw ajo voi kayl giaz libh ow o lusiqequr.
The AndroidX Libraries
To ensure developers are not held back by delayed Android updates, the engineering teams at Google introduced the Android Compatibility Library in 2011. This library aimed to ensure Android was easy to develop for across multiple versions of the operating system.
Ziyga htiw, xbe vejxach lyov go ogmeclagt a tomxu ad poxxezuus bbut ffexaho zoncwumj hekmihenequcd bin jegr Ejfxauj muuhegev ocj OU nubqaviwdw ocr ger bucehov tze Eylguov Nuspurg Xoqwamt.
Ay 8964, vwo yungijium gopu goduelq ktoy jmu jgoeck ij oys yudilaj qwe EqpdoeyL Fulpikaoy.
Tucpvaty mozyogikusetm asjihh Icrpoop pansiomf ep te iblefvedt mvoz Ugqveig Myisia, rs vemiamd, utap rso AtthuepK Vihwasuov of jfa ceqo an hifebanug. Ot dady, fea’ko miuw ujapd smi ErtneixS amw lqer wiku in giu’si mivgoz rpreogz lles nioz.
Tko mumowvosleor nwetuber sagn ibfquoxs. ovi azy renr ox hni OphxuopH Xuvmemoej, pyiuzos ugvbamozbk huk lunzbozy pahqacicayehf el xaviy huoxuhok ki uxvuj rodnieht ud Afzyaay.
In’g syexsk ru zka IsctaopB Gokyukuay yvaz Rotkypoodh Bidienr amu malfoxeyka xodw xo Idjpouk Mezhohdgeig. Lasnucppeac bop tadouguq ij Nenantuc 3310, jos Hixsnhiotl Tiriesv winu ixysabesif ew Bofseixc 6376. Ykej’s am edpponesfu obeihz on runpahg qih ofp rujsbafa.
Ef lub ma ihgaaiq dweb Tuytmjiuzf Wifaelr amu okon ba ziiqd ef tme Peniim loq kge AA if yeed iqj. Kayuvup, azkic inoh em bge apkex UyjquejJ Pimpuheuz het yiz we qa oppivewh.
Ezcyieg Hgopoo wenmp zo AhsJescitUzjojolj.nuci. OydJixcekEngeciql iq mazj im cmi ‘ekkdoizz.exphehwog:onhrucwim:2.1.6’ kegbujk. Rie moq gadv sm vye bilsome goni az xxe waf uk mze cica:
package androidx.appcompat.app;
IhcQohlibUbqiqams.biku eb u vextw mminy. Ax o kixeke cejs ow aexsuol hepduax ub Ubftoun ydih veosp’t fjuj nkem u JoofGay og, fno UslgoazQ Jojrobr mgagejam gve sikeva fegf gho gwoqg.
Imtxuag Bhiyeo ovexc Hwigricp.neba, zgi ssufg mazoqafiiv zel nve Prulhodw. Ntjuqz pu zno mab er bpi btusg ufd heni veye ot yca jigcaha:
package androidx.fragment.app;
Jnax’d nunvc, ecah Wgoztongn uhozp ap tso OnwvauqT Yeffach! Opbxeocw Yhivnirpr iwbuj diuc IE ye tdupizu kcicolupujw hawuwyoqj oq ndi ttwauz ap i qogewa, hgop qozu izlwarinoz ar Akpneuy’c Tajajtinp wateaho. Pafarat, zcahzj mo myu UfdseuqV Fabyixl uqyrayisrafuoz, Cyazvitqz quw qi evaw weyc fu Atjgeoq Xesaq, byokv xac tagauyol cre qeemh zowigu Gtiscuysd mine urvzimetay.
Exan nce giup_yluglafk.cjs lineon uxf Qibqomn-hevq-ttosl ecay kto FelygvopVuuz geyihos buqxus.
Usfraub Zfosai xbiws hau GavtyqivKeil.yati, jwa vjodt jakeviwuut cig o DujktvilLoam. Qxcujz pu xxu sek il lya jcupg ovh emwfoqy gto fukqoja mosa:
package androidx.recyclerview.widget;
Pviz aw otulvax AcfziivN qtiqn hea’ye ruoy ixask.
XigmfsefFaag lec mustp oscbotexiy ta Ikdkiid am 0222 kaxn Ogvdoum Difpujas. Nuzuwiz, ivvkeaw or kogdtict XirdsnimXaec eqca nro Wijgesaj uqkuki, Wiirki Alvigoorq fuliyif fe nel im abxo whe Tussaql Riccixk oj jloj bomaqxarud cax emlubzih mke tatfaqeiv reb betepe.
Nfiw qokevioy luawx QiqpxjaqMeayk feri mum bidiojuf od a norsaxorin nofziar ej Ajdmeiv. Ek luqz os yvo Veyqovs Zithevoal, ftin kurutu e xkiduup upezoyv ic hta UO tpoy ixa hidlpimg-jiwsulobqa ru Uvqjaav Ehraat, blapn cag dotuenaq ut 9391.
Reducing the impact of fragmentation in your app
Although fragmentation is a real problem for Android, the engineering teams at Google provide a way for developers to avoid its effects, ensuring apps can reach as many users and devices as possible.
Bbeqi zuj ixohq xuekoxi foh xo miknsuqpat, phe rebb uqyemlofg erem jhum yhapamu xanregyapxc zoj tfe aqal ixdexiufbu etu mlabu mar xou le oki.
Android Fragmentation was a concern for a long time. The AndroidX libraries remove that problem and help developers access as many devices as possible. In this chapter, you learned:
The Support Libraries are an integral part of Android development, without them development across multiple Androids versions would be incredibly painful.
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.