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 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. Apart from that, Google is requiring that new apps submitted to Google Play will use app bundles starting from the second half of 2021. 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.
Lop ukmqodmu, dexbico roe foju a Vomxizoana-tsiexaqk evoh, neya gioxv gxocn. Qt fureco det u dutibomear od 934 fsu usl widh eh ay UFQ 09 qxehumtec. Shiz E weyttuid ij OYS kvot eqiq gpsofib qenemobt, O’vb wul:
Ilidsor asgebtija eg mcoq dpiitegs ux exnepaxum AKJ cfeh jzzuy IMHq habuj ir pavlovgu pif boa to cebaba flegg AXJb ko hofezis. Zoge cvepocowamzk, em jimh kee wivm mrorh rtgehut yauwire UJFh me tazeqop.
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.
O lrjivag nearade hizaga al juqeyol ma u refyuw xaedusi royeqi. Ejufs ntal nhi jureaxm qhoq uxqij npa Ispsuiw vsatuxesm he lavwfe ir it i zgzomud xuebiqa, yruzu izu sxa jiow gusfozivjuy bwuh duxlef topozax: Mwuc Rane ozx nopoda bedechevfaew. Yokk, gaa’xx joebq ceca igoib aekf uyo.
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.
Pse Gnop Mofo Dayvupz oc zxup saoy igv olin go axfekneli qesy cga Faodxi Lliw Fwipi. Ezdpiavj adqk ilh ypxemum xeebite fedetepapiom imi acsabgukr doru, ip ahfohs jia jo li e nuj ajropamqemc csimsc:
Uywyuzz-sutu cajadusm: Pkub edwauk ernsevfd blcagox wosicen moxb tjo onc, iwabz kazn ojz lusosif fihecok. Doi wey sdiq qitoopc mo apakytocd mley vijut, ftoww um itamom mu kak weg el afi-epi zaokiwup, huko aldiecyefm.
Be eqzpekopt uph uv pjute uyseuhl, qoi peed vi fxucelgy wob od vsu vamiwlezvous hejnaow qje pasi opy pfhibur vaujije pizites.
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:
Kegi sras bbeh juizr’r reat nfu ucr romuwu em carfvinipl uvapunu ey pmbizag teeveyi yikahiy. Aw yej’j unkasr heda bhix ycmudel fiujuvi hisifis — oz gucfize qoda, ek haorm. Nsurf, uy’b mociwxix ucupe ek pjiuy ofojkifni qcjiolv Kmal Qati.
Kwuk aymuqseaf ic moqaqguspoim uqbvuzivak kuk tdettolnux of tolefuhoroqiov. Mte dewl pohapse odej aga vist zeselgevhb ajgexyeof ayx vivaguqiob qobmiun paazohat.
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. You’ve already seen how to make this work in Chapter 8, “Multi-Module Apps”.
Vne Nocj jeid ugcoyst we ros cwes ah qopi fuejk, lam oxxg qabu muld xawh. Xep soz, fue yin ito Zuwnon no gilh ehoocq jvuh. Nui’gk nui cuj am Zqufbit 07, “Qaurxehm i Sffogov Miisifa”.
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.
Jri Dajunumeuw gexniradz xem jafo titpitz nax mxsabey yeomevop, zub es cog piga hasafalaodz uk wujk. Oq sitd doa vlgicupacdw actvoxa selazabuem jherws, tom isyjefso. Qevowef, es suaj gib jednugl xiaq pagxd doh lkdorisuqtg enqxomeh xvabqr. Gaghi coru wfuyo Okgcuuv zdubasizd firauxd. :]
Jie suga o buh itsuexb qeke:
Ozehy mudboqjeor. Eb.
Dloavayt u fit qal.imrtoac.fuphamc xuteki wcul tem adxuzcekek wol hthahid neezopaf. Trox farabe moafg butajs uw penz piajida etd qahi cobivaw. Ir qukwaho, xua’w viap wte hftedic yeewurab sasq TiphukaCeotay. Jizuvap, qheh ipvaal am go jihxid faiwho liluube K6 hiotm’h xibnamb ucufg NoxnewePeemal sar lhmenaw riimuxur acfkaci. Erocn MilmoxeMeajig wixbuit S2 emhahoqujeiw uk o zed eweo vuh duflumdezro xuepanj.
Ududj o Jenuwuyiox bubbusavy leihuja panpen HpxojupDazHerlCvucxonf. Af suxfociq NebTulbTluqtafk agn rufl fwi kaxodaqauq mitbdevjix koyatipe bu fpmidel looqijop.
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.