[MUSIC PLAYING] BEN WEISS: One pillar of
modern Android development is distribution. The Android App Bundle is a new
and official publishing format for Android applications. With the Android App Bundle,
we created a publishing format that unlocks,
amongst other things, shipping smaller
apps to your users. Smaller apps are more
likely to be installed, and less likely
to be uninstalled when disk space gets tight. Today, we'll take a closer
look at the technical aspects of how Android App
Bundles can help to decrease your app's size. Getting started doesn't
require any changes to your existing codebase. All you need to do is
create an Android App Bundle using Android Studio
or the command line and then uploading it to Google
Play Store using the Play Console. Once the bundle is
uploaded, the Play Store can optimize the APKs it
delivers to users' devices based on their configuration. This, in turn, reduces
download and installation size. In this video, I
will show you how that's done by taking you
through the process of creating an app bundle, uploading
it to the Play Console, and then showing you tools
that you can use to examine the exact APKs that the Play
Store generates from that app bundle. Let's dive right in. To generate a signed app
bundle using Android Studio, select Build, then
Generate Signed Bundle/APK. On this dialog, make sure
Android App Bundle is selected, then click Next. Here, you have to provide
information on the upload key that you configured
for Play App signing. If you're wondering
what an upload key is or how to enable Play
App signing in general, please check out the previous
video in this series, where this is explained in detail. Let me enter the Key store
password and Key password, then click Next. We're using the build
variant "release," which can be shipped to
users through the Play Store by default. After
clicking Finish, the bundle is generated. When the app bundle is ready,
you can open the Event Log, and then click on Locate to open
the path to the generated app bundle. Choosing Analyze instead
opens the APK Analyzer, which enables you to inspect
the app bundle's content. Before we go ahead and upload
the app bundle using the Play Console, I'm going to show you
how the compilation and signing process works using
the command line. We're essentially going to call
the same commands that Android Studio invokes for you. This can be useful when you
work with a remote machine, are writing a script for a
continuous integration server, or simply have a preference
for using the command line. Android projects ship
with the Gradle wrapper. This wrapper invokes the
declared version of Gradle and downloads it, if necessary. Depending on your
operating system, it's either gradlew
or gradlew.bat. To bundle the application, I'm
invoking the Gradle wrapper and then the bundle command. Since I want to build only
the release variant and not all possible variants,
I'm appending "Release," and then I kick off
the build process. The app bundle now can
be found in the build folder of the common
Android application module. In our case, that is app. From there, we navigate to
/build/outputs/bundle/release. And here, we see the Android
App Bundle that we just built. This is a release bundle
that now needs to be signed. You can do this yourself
in your Gradle script or by invoking the
commands yourself. To sign this app bundle,
we're using jarsigner. We supply the keystore
location using the corresponding parameter
and the keystore location. And then I tell jarsigner
what it should sign-- in this case, app-release.aab. Since a keystore can hold
multiple signing keys, jarsigner wants to know
which key it should use. In order to tell it, I
add the keystore alias as the final parameter
to this command. After hitting Enter, I can
add my super secret passphrase and then hit Enter once again. No matter whether
you choose to use Android Studio or the command
line to build and sign the app, this bundle now can be uploaded
using the Play Console, and that is what we'll do next. In your Applications
Detail screen, click on the preferred
track you want to create your new release on. I'll roll this out
to internal testers before opening it
up to everyone. On the left-hand side, I
select Testing and then Internal testing. Here, I click on
Create new release. To get this going, I'll
upload the app bundle that I've just built and signed. I can either click the Upload
button here, or drag and drop the bundle in the
dedicated area. Once the bundle is
uploaded and processed, we can take a look at
the App Bundle Explorer. In the App Bundle
Explorer, we can see an overview of some
features of the app bundle, such as supported devices,
languages, and permissions. To explore the bundle, I click
on the details arrow here, and then Explore bundle. At this stage, we
can take a look at how the Play Store decides
what should be downloaded to the user's device. In the Downloads tab, we
can see this in detail. Here, I can apply
a lot of filters. They correspond to
the optimizations that Play Store applies
when generating a set of APK for installation on device. The app I uploaded is the
Play Core KTX sample app, which is available on GitHub. You can find the link
to the repository in the video's description. The sample app contains
some rendered icons for different screen densities. So when I set the screen
density to a specific value and download the APK
set for a device, that will provide us with
an APK that mainly contains the rendered images for
that density bucket, alongside some metadata. Let's go ahead and select
devices with 440 to 450 Dots Per Inch, or DPI. Clicking on the Download
icon at the end of the screen gives me the possibility to
make some further selections and download the APKs
for the chosen device. I'll download the default set. Now let's see what Play
had in store for us. The downloaded zip file
contains several APKs, which are tailored to the
specific device in question. Let's take a look. This is the zip file
I just downloaded. Let's go on and unzip it. Here you see all the
APKs that were downloaded for the selected
device, including all potential languages that are
supported by the application. These are the exact APKs that
would be delivered to a user's device with the
chosen configuration, including the signature
from Play App Signing. I did not configure languages
in the Download dialog, which is why there are so
many different language APKs right here. Many users would only install
a subset of these languages, depending on their
configuration. To install them all
locally, you can run adb install multiple
and select all APKs. While each APK in the set
is relevant to guarantee correct execution
of your app, I want to point out that
the base APK always has to be installed on
a user's device in order to provide your app's
core functionality. Next to code and
resources, the base module also contains the
merged Android manifest and shared dependencies
for the entire application. 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. This could be used to
avoid pre-installing parts of your app that only a
subset of users might need. And since we want to enable
users to download and install features in a
programmatic way, we provide an unbundle
API that you can use. It's part of the Play
Core Library, which is covered in the next
video of the "Modern Android Development" series,
where we take a closer look at Play Feature Delivery. To get notified when new
videos get published, subscribe to the Android
Developers channel. If you have questions
on this video's content, please leave a comment. Thank you very
much for watching. Bye. [MUSIC PLAYING]