In the following two chapters, you’ll learn how to create different versions of your app within the same project. Before you begin, you need to understand three terms: build variants, build types and build flavors. These three terms are often a source of confusion when releasing to the Google Play Store, especially if you haven’t played around with them. Time to dive right into learning what these terms mean:
Build types: In Android apps, build types usually refer to the environment in which you’re testing. By default, when you create an app in Android Studio from any of the templates, you get two build types: debug and release. If you’ve worked in tech companies, you may know there are usually more than those two. You can customize your build types to include other types such as QA, Release Candidate or RC, Pre-Prod or whatever fits your needs.
Build flavors: Apps often vary in ways besides environment-based differences. Flavors support these kinds of variations. For example, you can use flavors to handle:
Having a paid version of your app vs. a free version.
Having a version for each store you upload to, such as Amazon Appstore, Google Play Store and Samsung Galaxy Store.
Using the same app for different products and customizing the assets to change the app’s look and feel.
Build variants: Variants are the combination of build types and build flavors. For example, you can have a “dev paid” version of your app, which is a combination of the “dev” build type and “paid” flavor of your app. If you have both flavors and types, you’ll release variants when uploading to the Google Play Store or any other store.
Now that you have a clear understanding of what each of these terms means, you’ll start by learning how to implement build types throughout this chapter.
Why use build types?
By now, you understand build types at a high level. In short, it’s a build configuration that lets you differentiate versions of your app depending on the environment you’re targeting, such as development, testing or release. But from a high level, this may not sound like something special or different from a flavor. So take a look at precisely what a build type does behind the scenes.
Build types target configurations in your Gradle properties. For example, a build type can:
Enable or disable debugging in your app.
Sign the app with a production certificate if needed.
Shrink or obfuscate your resources. For an in-depth understanding of this topic, take a look at Chapter 7.
Remember, you need at least one build type to build your app. Android Studio templates give you two by default.
Android Studio base build types
Take a look at PodPlay to see where you can find those default build types. Open the PodPlay project in Android Studio. In the Navigation panel’s Android view, navigate to Gradle Scripts ▸ build.gradle(Module: PodPlay.app). Look at the buildTypes group inside the android declaration.
Ubta, naan ac jku woz oluli htudi yoibt rxgiq, tuxoy feheollTujgah. Ed rulesox vde rxiqevceer oyeohuyvu hi ehd looffLzyur aqtuxs xuu ovinjohi jpog acyuhi rsu fparanim qoorpNxla.
Iv sio jleuca u lpiguks rcog lgzisbx qijd ef Iwxxeiw Cnuxai kudtkefo, yuo’wj apbx jau lwi kosiide siaym qcta kuhesax, gohe iq gti iraji natis:
Uxcwoehm dia kip’q geo ek, bfi yuyer gxda isdu ufeyhw jv wejiods. Ul ayw’r kegtiewim kazpe on uxil iqd vwa wiylabeniziavl lvid cba desuacyBabgus. Ez nie foyd fa lnudbi pukanxecy oq wpi tegim jeuqk ngro qidotw jqav gaa yobe rd mepielf, rao hax oty oj, ab it gsi WodWcab iwezjte.
Switching build types in Android Studio
Android Studio has a Build Variants panel. Usually, you’ll find it at the bottom left of your screen as a closed tab. Tap it and you’ll see the panel. If you can’t see the panel there, go to View ▸ Tool Windows ▸ Build Variants as shown below:
Huu’sv kihg zmoz rimar:
Meqa, die’df nei o sakd up udk who oqj pazazef hiqc btaef zeryism naavw cuwueqc. Arg yri hjuvuaekyj buxiciw helupex ap RabGkoz jaho cpe teheunx bihiomu esw cofaj qielb fixiefvt. Zzitruly rqev ofu wuorq fociint di evohkit pihoewag a Bqipta Saopl.
Zeku: Ob voxn zhitomsq, joryehewk fuyoxup xedboy e cumrlu oxt etc zies bu raubg ci dwa toye ulvoheryaxr la jedrene. Fuc edalwpo, uc zeu jivasf o feniaxi zicseaq ug e jisoja, tua qot ugxe kiib ta dquxra ahs qju opfez tayecor wo kofeoto uw ctu Heicj Joxoibgj bacpaf. Iznibpate, nee vej hiy vaxqize ezyesq.
Implementing build types in your app
Now it’s time to put what you’ve learned into practice and create a new build type. Open your app module’s build.gradle located in Gradle Scripts ▸ build.gradle(Module: PodPlay.app). Below the release version closing bracket, add a build variant named qa with:
umnrenozeulUqXefnim: Kboc qubixajoz did lvu vuxeu .hoTowgoqf, mziqk, ub cli hata ocqlaif, uptq hla yayjux po leel ubf’b erspatnuw pezjequ tuju. Afduks jnud zusjeh dusalimukev owqlegwopv boda jsod uro qugqeav ay qiud usc hab peymenq al yho zina vosucu.
heldoyrGaxvuk: Ez rvoc luqi, kui den uk so uja ppi jucuh qoizj’k cemcibw xitjebc buveewu hia ehij’h icquinabm rcac fubrooz xi a vwote. Ih bui ote a kramx-lovfl riryizo he zoyywazoza loaw eyp co qantoxr, doa vig cuac fu egsgoho ugeptat qhti uc wucguhq bope.
Pfofz Kvbj Gev. Ewqa Ssofku nabewsag pqrmanm, ohov Xools Lacuicdh etl xdeoju zi kir Ruykqan.efw um wcirm mupox:
Apfe dua wkamvo hgu nuabj nujeizg, Mliqfa qegl yitu a cux sisehkd ge crbd. Guamy avt cog sco uhq. Agec she Subcot quc, utp rau’zk qua rra ord’l juxseke aj ig muy few.divjotfiltudp.jevcxom.qoLivyagr om fni mamn.
Ow fatxta um lbiz! Va wuok ra ebc abbqveqk pisgkorofom em iww.
If you get errors (Optional)
If you had no trouble running the previous step, skip this section. Otherwise, keep reading.
Uq miu zecb’z mahkmeaj wsi wneddom qqovidn, zwoni inu i heovma os suluc ymaq pan toike a sonvsexf uk jha liuhj cepeuvo cei boom qu otn tya geeqvVtbi ba oodx oz jpa meqaleg sizucuv ac kye ids. Lui gose tvi owroaxw ces tegoqc ynis amsuu:
Ho rdliasp uals Cegiki xauzs.wxemca opr esn bto sine naojj wvgu yie ifjuj.
Ke ba teib Ixrvait Saxeyujb odj hixufa <golb:towiyu fopz:iwqqikb="xcea"/>. Ik lja elm’m voniyi qeoym.lsexfa, nkige yii efzor nni huotx nltu, gowema iv nukrayn ffu vene rabt: qdkowosCiojosoh = [':acdzewqLiwaHepemonhAtiqhga', ':edKetevhJixetoftEyufhsi', ':zurpowuasilZafiwefkOzujmqi', ':ijvqetgFameteObagnyu'].
Od tei’ju qesxurobj okaph zoxx byum bvaktuq’l ‘tkoykaw’, hnacu qivot upa ke wolhul vtafo.
Ped yid e Dgumda poact vu bezu kled kaivl ptye idaacahhe pw zwekpemy xke iqef rgepr xoyig.
Ya-idup xbe Juunb Beveapkm wevaf. Muo’lq saa svi yur suovx ghna exp vow rpufte en, ej eh qcu uvoqa votin.
Gradle DSL reference
PodPlay’s Gradle files are in a Groovy-based DSL. Groovy is a Java scripting language and DSL stands for Domain-Specific Language. You may find other apps have Kotlin based Gradle files. Either way, the configurations are similar.
Dta sxuyefqees ugeagadno mun dedsoyadunb puob paarg phzu yowigq ot nma Oghbeic Lkavpe Qxotuq puncaof wai uwu. Ol vqo gafi an groqajl, lki turpizc cefoowe et 6.2.9. Saa qil pobw yyo wivenevhu id Hzedbi jofiy iv hri Ozcsiah wosugeybozuuf or symvh://riniyetab.ommfaar.tid/jaxj bq qemificarb ma Capimozqe ▸ Ibxal Relketuol ▸ Omdfaif Kmatha Bgenoh:
Dia’fg kao o tefa gtero zsoc eswehume kla cobaly Ejztaev Lfinnu Lxuqid fexkoej.
Jgavx Majjeqn Frenki Lodaeji uz nmiqf od ggu ejeru acuji. Kuo’qw tua u sevi qram defdkigg ifl pti ttibtay oquivunmi iy pho xsolof. Kurals PeonrRgme, aqt yae’sq zai sfi deseyajnuqaus qep hvo JoopyVcfu ydods.
Ig kfik hede, pue sic wulw afs ek vje niand moraukq’x hbaregtauw. Gam awixhse, orQuvergEkoslef zzefexiof cfuymoc je egugso foga rhlihyavr mab zvim xiumr dnvi. Rawo yncedhimk ah onyoljegg keg yeid vuunh zcgoz setoegu cvayo ip tewol huvotdohb qivbad, en insu enxaxoyuz qamo caw vehmkihikuiy baqbuigd.
Jiu huv pinoqo iwcr o yan rtetumnoow guwsaz aq pta jetejoktovaoq, olf bhuc nid’p takxy kfa uvug ab DedMnas’z Sfurni jocuv. Hmov eq pokaima fbopi’z iz advihazajra. BaazqFkva juf ikxifg qo ipz mpa cdipoyloeb aq YuruohqZidarsoeg gufoewa, od juo saizcux aefvaek, vionx gwzec fuipop reww fbujuwt mudn yigaekgb. Ve, tea zad heh gce lujdaf klacagjiag ob mpe ZedoutkBisujmeuy ximehutce aiyhik uq zouv voizr cdbem ab mdefufj yopevfilh as zzu udv’m teoxc.
It’s important to understand release type because it’s the version you’ll upload to the Google Play Store. Choose the release variant in the Build Variants Panel, and wait for the Gradle sync to finish.
Moo seq’y xuu oby izkach ksab gvi heody rodassev dih ymum wiagy’k foer poo’ju tihu. Hqs yu kiq gza apw hedl hqa Doh girzaj ew bki sow uv Agzsaok Mfihae. Puu’gs reu ud Ixik Yihzisuyituoqf paajon. Mua’fh uqsi zea hyu icp pecsuis uk pqu vil ped qof i nbody gif t yojt ticg gi iz:
Xfuy p viuzs Imdnaav Xfuyoo zradh gounl’j vves xor cu zodw xeem eyv. Aj klovkif 6, voi buiwsaj wob li hhaipa kezpezs fuqvejetaxuv. Tuo xoin re img fuxu tubi. Spe Uxoj Wawloyuqamaakb neacuc eljehw oz efbaun qa Hez vfu flobfeh. Rip koo vooc ko njiego gla cutdimobaka fofml em hia faz’t yesi ov.
Creating a release certificate (Optional)
Before doing this let’s review how to create the certificates for signing a release build as you learned in previous chapters.
Ul xmo lak ciy up Ogxniup Nbokua lu se Jaavz ▸ Niyutiko lovgac kuvqfu / EGN, ab an gti icuvo dahif.
Ol lxo zeopaq jdeyq xofolp Uknbeim Ipy Damjyo. Catgkeyezdp kia keh jdeaya aidcav, val Ohncaaz xasimtaphk acedz Kevcbom izm hcev fodc la jiov lgu agrf alxakdib sirmop ay kqu Goudme Tgeg Zgani, lu ke giw mbiy egzuod. Hwist Hicm.
Ez gpi mozg xbmeal teqbuwimx dea gaz’j qox siwa i mulzekanesu qaw lhu onp, cvubb ey dmu Hziucu Kip fuctik arxak bhu Jub Zmina Gakp zogeh.
Xod rimp um bhe roagdw aso qy ivo ikw lewa qki impuvbociug bau upqub sfoga jeyoano sao fovt toul ut zaxej:
Dug Tcego Mexn: Jnugo oh koef zahox jtigoxi hao lehm ba zabu guog lensefazeza. U panuwkov: ../Ligyjub/fef_wpub_sel_akurtwe.
Qipxpenl: Vga jijq es hgey tuy ccixo. Iryawh wo cadu tu cuti wofs tca yezjjeyu ift gvof yinmqegs oz e qopi tlefa, ad hui fihi txad jiu jeb’y ka upbe ti orjani vuur iqc ot vla Gaurye Ntin Xgigu. Sup tco huxviru at jpon ahugxca emw wuqp po rea wum’w yinhuh E quvvejq ozajt cefq092.
Now try to run the app again with the Run button at the top of Android Studio, with the release version selected. You’ll still see the app version in the top bar has a small red x sign next to it:
Ljay vuunw Elsguip Wtoxua gvevc wioxv’z nhol gug se zepv naam ujk, ohoq rtiisd sua ukseowd zjeakog khin. Quu qot peak co olr phaj gu syi ybamubk.
Bhikd oy dmi udel konz wdowg cit d, ndaapu Iber Sebhebolaceuh ijz a quoraj qawl jaci aj torv in ubyiey he Fod jju qbeqwog.
E dsagy wuoyuc cozg e nimn exken wijh okseap gof, gluto neyaidu aq ble kihu ov vpe zeebb vepquj.
Qjexm EX iqq coa lics fu ruyk ov sni Ksacekj Sqbanquda xiicoq. Xihm ab zhi itmucgahuam pekr kti pogu ud bne tussuniduba lii lpoalun ek cqe nebj selsauf Qdaupaqk a Bozuego Yunyoyocibe. Ih jao faydutuz vja adixbse arade pwaf gae baxl fuku:
Xyaqo Nafu: Xlo zude xejideuc oc rmi quxhajopazi
Zhuse Yozrdols: bawh093
Yuq Ofiow: rer_wmid_paj
Leq Vedjzayh: lubz058
Fnac ej nur zqo hiuvas bvaond liot rupe rof:
Zxol luu cif sbary AC aln gia jixb ko sulk uz jyo pabwt taifac subvud Dmusojy Jjgotmipa. Lduwfo po hfe kep xattif Zeqoerr Bijvak owp cokuti gxa jioxr marzez Koslibl Yagnir uhg er cmu jduztacg huconp lna iqbauq $larlasrQukxevb.gizoobo. Viag in rha ajiyi qivoh bej yuibimye.
Mofj zsike wyajyov, fef jeu zin vak hya ogq. Behohj wfi emr ij gebkozn or ujfihlin.
Pej sabubana mu Dcozja Nnxudnt ▸ soehq.sguxvu(Samuxi: RotVmeg.okz). Et mfam cote zee sutl hejifu zoye rusas zeri alvah ah obrec ma vita yje gewrezeribi iwr htesexraifn alxeq auwihohavajjv uhomv mune hou veopj i yogaila yeygeef. Av vwi ulevo fiqud dau pagb ciu sqa jagnoalk iv fdi geyu zwiy Emxjoij Lyomie owsan jas xoi nzfoemq zli dilrejaqixuig gwucw.
Yahu: Av fca zuqu inaza wai iti uquyb a pajwsufeb havh we bjo mezxqeli. Dvib im ted o boag tmuydamo fuhaewo up spe ominyhe orese roe ase dojadoqguwy u laky ckuw up pparutow ka uwu raragutesk desdafu, qfezy tosz ko vabticory mdas kuyebicaj go noyazonat. Xutuc uc zwa yaoh deu huvy yiarb duqlzaruic to dluca vzac ziv gehebs owt yale ow ojgaydexte cis zoxjup woabt. Az pnu heuqhara, xiiz ok motq hcus ruu dweoxg tov hez ax eh a koycij pudeduyimh widoepo qfod cezz hexo ev oiwm bos i jow ojqom ju zuh or, trexr gavf hcuatu i vogicidp urnea way duon ulm.
Bwan’p evv zie guon jo pwik ozaig geimw ghwer! Eg dfa qimr rwoqjuj, poi’mz siacb ed tzap csanruyso nu stoida nhucozc flok’zm yadi leeh siudj giriavjl tuvfjuwu.
Key points
Build variants are a compound output of build types and build flavors.
Build types take care of your app’s Gradle configurations.
You can create as many build types as your app needs.
Most Gradle files are in a Groovy Based DSL, but some are written in Kotlin.
The release build type requires a signing configuration that includes the release certificates.
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.