{"id":345,"date":"2021-02-04T11:05:48","date_gmt":"2021-02-04T07:35:48","guid":{"rendered":"http:\/\/emadpourahmadi.ir\/?p=345"},"modified":"2021-02-04T11:15:27","modified_gmt":"2021-02-04T07:45:27","slug":"building-your-first-app-bundle","status":"publish","type":"post","link":"https:\/\/emadpourahmadi.ir\/?p=345","title":{"rendered":"Building your first app bundle"},"content":{"rendered":"\n<p id=\"1e67\">With the Android App Bundle we created a format that unlocks, amongst other things, shipping smaller apps to your users. Smaller apps are&nbsp;<em>more likely to be installed<\/em>&nbsp;and&nbsp;<em>less likely to be uninstalled<\/em>&nbsp;when disk space gets tight.<\/p>\n\n\n\n<p id=\"3572\">In this post we\u2019ll take a closer look at how to build your first app bundle, how you can upload it using the Play Console and dive into some configuration options.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Getting started doesn\u2019t require any changes to your existing codebase.<\/strong><\/p><\/blockquote>\n\n\n\n<p id=\"3f25\">All you\u2019ll need to do is create an Android App Bundle, using the command line or Android Studio.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"4ae5\">Building on the command line<\/h4>\n\n\n\n<p id=\"e3b8\">On the command line, you\u2019ll run one of the&nbsp;<code>bundle<\/code>&nbsp;tasks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>.\/gradlew bundleRelease<\/code><\/code><\/pre>\n\n\n\n<p id=\"5eb2\">Then locate the bundle in your application\u2019s build directory. The default location is&nbsp;<code>app\/build\/outputs\/bundle\/release<\/code>.<\/p>\n\n\n\n<p id=\"4e62\">This bundle needs to be signed. When using&nbsp;<code>jarsigner<\/code>, this is how you sign the bundle:<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>jarsigner -keystore $pathToKeystore app-release.aab $keyAlias\r<\/code><\/pre>\n<\/div><\/div>\n<\/div>\n<\/div>\n\n\n\n<p id=\"42b6\">Once the variables are replaced with actual values and the keystore password is entered, the bundle will be signed and ready for upload.<\/p>\n\n\n\n<p><strong>Building in Android Studio<\/strong><\/p>\n\n\n\n<p id=\"72cb\">In Android Studio, select \u201cBuild =&gt; Generate Signed Bundle \/ APK\u201d and follow the dialog.<\/p>\n\n\n\n<p id=\"4882\">Whether you use the command line or Android Studio, the process will leave you with a built and signed release bundle that\u2019s ready for upload to the Play Store.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"98bd\">Uploading through the Play Console<\/h4>\n\n\n\n<p id=\"c003\">To upload your app bundle to the Play Store, create a new release on a chosen release track. You can drag and drop the bundle into the \u201cApp bundles and APKs\u201d section or use the\u00a0Google Play Developer API.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/1600\/0*gvYVJ4ew6ebOO5KW\" alt=\"Image for post\"\/><figcaption>Highlighted (green) section of Play Console for upload of App Bundles.<\/figcaption><\/figure>\n\n\n\n<p id=\"048e\">Once the Bundle is uploaded, the Play Store can optimize the APKs it delivers to users\u2019 devices based on their configuration. This in turn reduces download and installation size.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"119c\">Exploring your Android App Bundle<\/h1>\n\n\n\n<p id=\"3ccd\">To take a look at how the Play Store ships your app to a user\u2019s device, you can click on the \u201cDetails\u201d button at the end of the bundle\u2019s row.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/1346\/0*CNvrIH4zZE2VOruF\" alt=\"Image for post\"\/><figcaption>Screenshot of the highlighted \u201cDetails\u201d button<\/figcaption><\/figure>\n\n\n\n<p id=\"fabf\">In the details screen you already see a lot of information on your app bundle such as version code, minSdk level, target SDK, required features, permissions, screen layouts, localizations and much more.<\/p>\n\n\n\n<p id=\"6137\">And you also can download signed APKs for your app, to see exactly what the Play Store delivers to a specific device. To navigate there, click on \u201cExplore Bundle\u201d and then open the \u201cDownloads\u201d tab.<\/p>\n\n\n\n<p id=\"e604\">You can either select a specific device or apply one or more of the many filters from the \u201cAdd filter\u201d tab.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/miro.medium.com\/max\/1115\/0*nfvZmnEYHxH14TtH\" alt=\"Image for post\"\/><figcaption>Opened filter tab in the app bundle explorer<\/figcaption><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"813b\">Download the app bundle and install locally<\/h1>\n\n\n\n<p id=\"25f9\">In the app bundle explorer, at the end of your screen, there is a \u201cDownload\u201d button which provides a zip file, containing several APK, which are tailored to the specific device in question.<\/p>\n\n\n\n<p id=\"34ad\">After you download and unzip the file, the containing APK can be installed on a local emulator or device by using `adb install \u2014 multiple *.apk` from the containing directory.<\/p>\n\n\n\n<p id=\"6c9f\">While each apk in this set is relevant to guarantee correct execution of your app, I want to point out that the&nbsp;<strong>base.apk<\/strong>&nbsp;always has to be installed on a device in order to provide your app\u2019s core functionality. Next to code and resources the base module also contains the merged AndroidManifest and shared dependencies for the entire application.<\/p>\n\n\n\n<p id=\"2a91\">Each feature module or configuration split provides its own resources and can contain code, but the base module is what ties it all together.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"2a45\">Disabling optimizations<\/h1>\n\n\n\n<p id=\"251c\">You can disable the optimization in each module\u2019s&nbsp;<code>build.gradle<\/code>&nbsp;file. All you have to do is edit the&nbsp;<code>language<\/code>,&nbsp;<code>density<\/code>&nbsp;or&nbsp;<code>abi<\/code>&nbsp;property and set&nbsp;<code>enableSplit<\/code>&nbsp;to&nbsp;<code>false<\/code>. This will tell the build system that it should not optimize this specific dimension.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Unless you have a good reason to, I recommend not touching this section as setting enableSplit to false can dramatically increase the on-device installation size of your app.<\/strong><\/p><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code><code>bundle <strong>{\n    <\/strong>language <strong>{<\/strong>\n        enableSplit = true\n    <strong>}\n<\/strong>    density <strong>{<\/strong>\n        enableSplit = true\n    <strong>}\n<\/strong>    abi <strong>{<\/strong>\n        enableSplit = true\n    <strong>}\n}<\/strong><\/code><\/code><\/pre>\n\n\n\n<p id=\"2258\">There could be exceptions, such as when your app has its own language selector built in and you want to have all potential languages available for selection at all times. But even then, using the Android App Bundle provides you with ways to load features on demand instead. This could be used to avoid to pre-install parts of your app that only a subset of users might need.<\/p>\n\n\n\n<p id=\"d1a2\">Happy bundling!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android App Bundle is the new and official publishing format for Android applications.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-development"],"_links":{"self":[{"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=345"}],"version-history":[{"count":10,"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":355,"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions\/355"}],"wp:attachment":[{"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emadpourahmadi.ir\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}