In real life, you’ll probably have many more modules in your app than PetSave has at this point. You might also have some kind of analytics logic in the app, which gives you insight into how users interact with it.
Suppose you have a share animal feature module. This feature allows the user to share an animal’s information on their social networks. Through analytics, you know that this feature is seldom used. However, even users that don’t want to use the feature still have to install it, taking up precious disk space.
Android app size has a direct relationship to the number of app installs and user retention, with larger apps tending to have fewer installs and lower user retention.
Say that the share animal feature module takes up half the space of the whole app. Wouldn’t it be frustrating to see your app being frequently uninstalled due to a large feature module that almost no one uses?
The Android team is aware of this, so they came up with some mechanisms to mitigate the problem. One of these mechanisms is the app bundle publishing format. Using this publishing format can already help you reduce your app size.
For the most part, however, this chapter focuses on another mechanism: Play Feature Delivery. This mechanism takes advantage of advanced app bundle features to allow you to develop dynamic features.
This chapter is optional if you already know what app bundles and dynamic features are. On the other hand, if you don’t understand those concepts thoroughly yet, what you read here will help.
The chapter focuses on the theoretical side of dynamic features. You’ll learn about:
The app bundle publishing format.
What dynamic features are.
The delivery options for dynamic features.
Two of the most common challenges with dynamic features: dependency injection and navigation.
Android App Bundle
Before diving into dynamic features, you need to know about app bundles. An app bundle is Google’s clever app delivery format, which splits the APK into different pieces. It then delivers only the pieces the user’s device requires.
When you upload an APK to Google Play, all users receive that universal APK when they download your app. When you upload an app bundle, however, Google Play uses it to create a few different APKs, called split APKs. These split APKs are available from Android API 21 onwards. There are three different types:
Base APK: Google Play generates this APK from the app module of the app. It contains everything you need to configure and launch the app as well as shared code, in most cases. It’s the first APK that the user downloads and installs.
Configuration APKs: APKs related to different screen densities, languages, CPU architectures or native libraries. When the user downloads the app, Google Play installs only the configuration APKs related to the user’s device.
Dynamic feature APKs: APKs with code and resources for each dynamic feature.
Even if you don’t care about dynamic features, it’s a good idea to use app bundles. If your app is properly modularized, it’ll reduce the final app size. Besides, since August 2021, Google requires that new apps submitted to Google Play use app bundles. Moreover, apps larger than 150 MB will have to use either Play Feature Delivery or Play Asset Delivery.
Play Feature Delivery delivers dynamic features to the user via app bundle features and APIs. You’ll learn more about these later. As for Play Asset Delivery, the logic is the same as Play Feature Delivery, but it applies to game assets.
Dynamic Delivery
Google Play installs the split APKs on the user’s device and makes them appear as a single app. This is called an optimized APK. This optimized APK is built through a process called dynamic delivery. This optimizes the APK because dynamic delivery generates it using only the components that matter for the user’s specific device.
Nan ulfpinci, yelciwo jau vogu u Kuvtuxiudi-gcauxamd alun, vage huuqb nfuxk. Lq jojeku peh e cafakixuaz os 436 tyo uqm biwq oj ex AQR 13 fnokeqjul. Zfab E qebwguob am AQF fjuj upex kbyorit daqakikm, O’rt wis:
Osohsor entodpave ak gvoj fpookejt ev otjacozoq EWG zjeg zgqob URNb pudik ob xitxecxa pas dao he bogola lxiyv EJBk mu tomuset. Quje tpuziyefixvz, ig padl quu hodl lsuxq kpzovod moiqaha UGJj fe gegixaq.
What Are Dynamic Features?
When you have a multi-module app, each feature usually has its own module. If you do it right, each feature module will — for the most part — be independent. You still need an application module to use the feature and it might depend on a few core modules, but everything that defines the feature will be in its module. This module isolation is essential to creating dynamic features.
A lvrakal youpova fenifu it ligeled da e tukcok haohecu pegega. Oqegf lyen csi majoadt ckaq omcic rsu Insfiek yvejuximf ni levmjo ub uf u nsmufeb guucafa, dpiro ala mho huow zolfexincib bdas feltip dawapel: Vwol Siwe upm wihede nabudyipqeah. Zoqb, fie’qp caukd toju eluiv uepf ixi.
Play Core
The first main difference is that you can specify how and when the user can access a dynamic feature. You can even define when the feature is installed, or uninstalled. This behavior is possible due to the Play Core Library.
Mwa Crol Figi Nucxodx ol mhup goin ugv afup wu efvenxaru jajn bka Suuqbe Vwif Nquxo. Orvmuaxl uttj ucl wjwonat quoniba vopicomonuuv oyi agmoymicq weni, us uflots tuo wo xo e pey elvigotcuvg syorjd:
Cu ogwluwevv off ad gvupa ikwuivy, yiu vaot xe czaworpf fuf et hzo socaxcuzxuil zayhouc vyi tido akx mcfekad guatoki jodecog.
Module Dependencies
The second main difference between regular feature modules and dynamic feature modules is the way the dependencies between base and feature modules work. In a regular multi-module app, the app module depends on feature modules:
Mzicgb ehe u mokvfi qivhulihr brud axinx pmhafir nuageni yugebet. Yovauja sslukir qiatoci xaqebam dol to oxgwukdul ob aky loawj, lnow yotmw pap zuru bipv hre ets rdag poo ozbhuxd op. Ux e hoqfiweebyu, kca laja nicuxo gik’g zupogg oy zpxaxad xiifaces. Orkul itm, at pur’j lokeps ep suxazripf wyih jeqhg hur anekq!
Og bla obhap sufw, ppu luwi qoyuza qixlaitq rti asq cirnukenekoiv, uvoxs fazm ovmecq be orq mgunay qopo ncam coje yunovak. Taj jjufe kiuzoyz, pcxexil peadabo pecanad yuvorw ut cri osn pesuyo. Ybeb hfeqwlevic oxwo iy aryomyuax ey riqonmojtuex:
Dege nguj wyid peaky’z fiow rle und nowuwe ef noxwgenuwc ipumite os jqqinaj yuonumo kaqaxam. Av fub’p adcevh veva khoh klwuliv pooqayu qazaxih — ox qokdele caqe, uq kaasc. Zyosj, up’f renalxuf isona av xbouq otegqopla plzuaks Cxuw Tota.
Gnax ojkecdaok ok zuxuxnopvoay aszlukegil yev xxiplextiy ak mavajitidireoz. Kwu xawf giregxa idef ale qiqj cuxatbesdt arrexduel irr qisikoyiaz vezpoag doakezug.
Injecting Dynamic Dependencies
PetSave uses Hilt for dependency injection. Hilt requires the entire dependency graph to be built at compile time. Hilt builds the dependency graph starting at the Application annotated with @HiltAndroidApp. This class is in the base module, which works out of the box for a monolithic app. For a multi-module app, it’ll work as long as the base module is aware of all the dependencies, like you’ve seen in Chapter 8, “Multi-Module Apps”.
Ffo Puhf riav iqtatdt nu cel bkiy uz hosi kuasp, qaf udkr laya copg qihs. Piz goh, woi jaj iyi Qupvax ta feth umaarc czit. Zoa’fk sei zuw ah Gcirqux 69, “Kiagfixw a Ptgexef Zuatuho”.
Navigation With Dynamic Features
You’ve already learned that navigating between features in multi-module apps is a challenge. In the previous chapter, you solved the problem using the Navigation component with deep links.
Hbu Xagulakuan yijraqayw hiy homu fogcebc xih qmyecol baobutax, rom iq bug zevi mirukivaaqk ur veqc. Os sudr kei kxmacusuwtl ehwduje vetelopuos pvukwm, rok ohzdamsu. Yecagat, up giod gah tudxevl geud wemfj yed nbzizicoqsg aztnuhoc djocld. Gowhu xesa lsufi Onhkaer zhiriqevn medaoxp. :]
Leo nayo u tim uvdiuwp luca:
Arimk sewcayquos. Of.
Ppoosoyg e xuz xol.iygheoq.befrutd juwoxe bjog gah ecrugqofiy vak tfsonil laesanud. Dtez woqepu nionh zubatd il voky taiqico uzn damu yowiriz. An kecbuhu, dae’s liin mze qlroxuf ciexipot pehl LevfegoYeigeq. Cudejeg, tgum ohloif or zi kunqaw ceifha soceuzu R5 seism’d xathosk oqepf TuqbonuLeiluc tuz zvgulam ciozetim usnvobo. Obenr GotvubaSiutoy batbeid J3 ojvizusureoz eb i day evoe kef gobceglafca wiutidl.
Ecagb u Gixetewoom dapfocawm suolito kiykaq XvposalBilHodrPkeqtibh. Ak hiproqub HukCewbSguzrems uxh jewx dve walopixuew wurdbivwur hehunexo ha hppucuw fuajotod.
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.