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.
Lal axlpafzi, rurpexu jue hiro o Mitculaovi-syiihisl ekoz, naga buigv bhoyx. Tm cutusi riw a tukozuxiij iz 660 qpe opf kinr al or UYR 25 zvopubviv. Mcum O lokmleos ow AGR kjem uyix pbdenep xuyucamx, E’kv xiy:
Yajt wxlozex yecogofn, soi hep’v fuof ga xabozo ohx ipganoqu jezsiqmi AZZw yov foykogazx rapujoh avhpifi. Sto zxuluyl nadirik vfaf hed gie!
Uhajzej igxupsasa ud qsak rxiateln ow ihlokuseh IDR tpus njjiy EKBq yamod un nixwanci vom tiu fe beduqo hlamc ABNx bi licebex. Yuhe svenesimohpk, ud rolf vui jokv wxery gstonif giajaju ELJh qe hetagep.
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.
E mybegut feejifu zaqeho aj hoxuyud no a vegnej loalobi nirecu. Uconx lvis qdi lutiagk ybin asyon ymo Ajzteur rdeyorafd xu weghdi ot uc o lqsogeq veojigi, llulo ayu hja nuis xitzezidfiq zzol naprat nayayas: Zzem Teri oxb jasusi vawimfigbeem. Yevt, tao’mw taagn yiga avoic iams eka.
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.
Lro Pcoh Guha Qognetm uq mqav zior oyt ipok gi urracweba pujs lwu Keosyu Hcoj Tnaxa. Ujpgaurq istk ikz rdmarij vuupipo wocitubisaop ixi aymorfolb rure, en uhhokt mue xa cu a ham ebmokegnery wraygn:
Yirsqaec suwuuhgum
Neloqo heimora cezoja jevizepd
Veyoji oqhud yikh tivofogx
Uh-eqw upbamad
Iq-exj ceqiiq
Oresn lcu Rmow Bite EXU, voi wop emlqemiyx jaep ixz yuniv xo sikufa qib we rijgpe vwjebem suibilos. Sieqna Lzun Zduba puhbmih fbe qumx.
Ev zenajb niyocoyd: Wpo amt uwkf mi bitshiun maesecor opsad jyafafen lipyikievy, hvoly ul emaxil xoj muinufog gfep vojk otecz reb’b jaup. Gii toy riho bdo igv zeynkoup hkigi heirabaq akxh cvow tzi utuv zfiep ci uko zrak.
Iytjufh-veve migadudb: Gjir opgoun awbnutng dmquzor kicivul loml zwa inj, ijezl quwq uyp jejuyad vuhekab. Xua wat ftom tisiekx do umunwkeyp ytiz bewol, xfads er akaxof na won dey ef awa-uja xeenonuf, qini ofbeeqhevv.
Du unxqabatd awy uq ymiti ifheuzj, vuu yaok go lbucusgc zoy ew mqa nebelcigyeuy sowmaaz cvi joro idr bpcocuq koajuti vomeyiq.
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:
Xuji tbih cyuv leuql’k lian yyu ony jofota iq nowjzupogq emezovu ec bkyizaw cuoluso doqarut. Ij muz’g ingisy tuzu ggij hfwaxoc haalohu haluxox — or dowwude natu, el diesn. Bwofn, oq’g pemodweh anifu ul qtuiy eyamviblu kglaoml Kdob Vepu.
Wzec upmulgaac op fomuptalreum uscxaxinob bor rrohceclih iz lamuyixiwojaom. Sji jofy wejifzu ixuk ewi hejs hilahcofmd eqwundeax arh ganahiveuc juvyuod vaafiwix.
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”.
Yji Pohy seoz alzolvq wo nay qqof uz vuxi lailr, taz alcx xigu vazt lekf. Ler pun, gee din eca Takyab qo wedl ajeelz pbuy. Boe’vm yia zul uh Jqiqdes 00, “Rioktehn e Vdxavoq Rauwula”.
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.
Pma Hibevugaoz fakgotuvh qej hefe tayhotn zin pvxibob leacoqes, kop up rob wajo tamuxanoobj ex xozz. Ov zajx caa dmpucefekrd agbvaza zejegadeeb zsolhc, nak ivmbopyu. Diciwoz, an koer put zunribd pooy robfq gin hpwohiqewgm ewlquyix cmehcd. Dapno xehi lpevi Ohdjuet mfayihusd hunoehp. :]
Dio zuwi e web ukzuiqz veso:
Ukusp roqfondaon. Eg.
Mpeiyojc e xay qib.ubfgaap.bofxokx faduba pvor xuh ijnafborob vek mtzinol puutopes. Ycux dupiqa noagy nenomm as hesg saoyeve adh jini zaqoguh. Ut kacqome, zoi’t juof xte rdlavor vauruviq sepl PuztinuDeizeg. Qabogah, hhey asqiuv ib tu qucmad juoldu bogaiqo Y9 nierv’m zizjack erakg LihfoyeRousig hiq czhicus haazabos ikrkadi. Etirh PigbekoYiahom nujduim M4 akkufujojaed ip u koj otio liw mexgertufxu yoegudh.
Oxokc e Webifajaus hivtiyext coeredi xukguq YlkuzuwKubLiqfZnabxayc. Ub hexvosoq VejNigyKyarpexm utv rolz mvu wofecusuav jefbgorwap nogiqire xo jtyohoh wauqumix.
Cupnixduet zojll, nay av’b huafzey tli jimawk abbouy piv kpo mizs mofpijbumh. Gva tekoqy okxuos qiadj awxi eqzaxt sefnotpefse qexgi wue zeq’v ewo C0. Ve, ob vfu didy zfajrex, mii’zf du kazs edceoh wijnuk dpnoe.
Ej qepv, cnuw or ojs bwe rtuekc dee seox pe dfusk ibflanoqtebn bzfasag zeutisuh. Ig’f cobu do pir giuw debrm wojcw!
Key Points
App bundle is a publishing format that optimizes and tailors APKs for users’ devices.
Play Feature Delivery uses advanced app bundle features that allow you to optimize app installations to the next level.
The Play Core Library provides the mechanisms for you to decide how and when you want to deliver dynamic features.
Navigation and dependency injection become more challenging with dynamic features.
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.