Create bundle in android

Building your first app bundle

Android App Bundle is the new and official publishing format for Android applications.

This article is available as a video and linked at the end of the post.

With the Android App Bundle we created a 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.

In this post we’ll 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.

Getting started doesn’t require any changes to your existing codebase.

All you’ll need to do is create an Android App Bundle, using the command line or Android Studio.

Building on the command line

On the command line, you’ll run one of the bundle tasks like this:

Then locate the bundle in your application’s build directory. The default location is app/build/outputs/bundle/release .

This bundle needs to be signed. When using jarsigner , this is how you sign the bundle:

Once the variables are replaced with actual values and the keystore password is entered, the bundle will be signed and ready for upload.

Building in Android Studio

In Android Studio, select “Build => Generate Signed Bundle / APK” and follow the dialog.

Whether you use the command line or Android Studio, the process will leave you with a built and signed release bundle that’s ready for upload to the Play Store.

Uploading through the Play Console

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 “App bundles and APKs” section or use the Google Play Developer API.

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.

Exploring your Android App Bundle

To take a look at how the Play Store ships your app to a user’s device, you can click on the “Details” button at the end of the bundle’s row.

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.

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 “Explore Bundle” and then open the “Downloads” tab.

You can either select a specific device or apply one or more of the many filters from the “Add filter” tab.

Download the app bundle and install locally

In the app bundle explorer, at the end of your screen, there is a “Download” button which provides a zip file, containing several APK, which are tailored to the specific device in question.

After you download and unzip the file, the containing APK can be installed on a local emulator or device by using `adb install — multiple *.apk` from the containing directory.

While each apk in this 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 device in order to provide your app’s core functionality. Next to code and resources the base module also contains the merged AndroidManifest and shared dependencies for the entire application.

Читайте также:  Как убрать звук клавиатуры андроид

Each feature module or configuration split provides its own resources and can contain code, but the base module is what ties it all together.

Disabling optimizations

You can disable the optimization in each module’s build.gradle file. All you have to do is edit the language , density or abi property and set enableSplit to false . This will tell the build system that it should not optimize this specific dimension.

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.

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.

And since we enable you to download and install features in a programmatic way, we provide an unbundled API that you can use. It is part of the PlayCore library and is covered as part of the next post and this video in our Modern Android Development Skills series.

Источник

Android App Bundle Part-2 : BundleTool

I tried to explain Android App Bundle in my previous post. Before you read this part 2, I strongly recommend start with part 1 and get the better understanding for Android App bundle. This part will cover how to generate app bundle and generate apks with the bundletool for the testing purpose.

Android App Bundle Part -1

Modular and Dynamic App Delivery : Android App Bundle

Android App Bundle

Android App Bundlemedium.com

Build App Bundle

Let’s play around with bundleTool and see the all possible ways to generate app bundle or apks.

  1. Clone/Download this sample open source application https://github.com/naman14/Timber, you can pick your application or any open source application. Thanks, Naman Dwivedi for this awesome application (github).
  2. Now, update the Android Gradle Plugin version to 3.2.0-alpha14 or above in project build.gradle file to use the Android App Bundle feature, build/sync the project.
  3. You might need to use the new gradle version too if that’s the case then change the gradle version in gradle-wrapper.properties file, build/sync the project.

4. Now time to generate the bundle and analyze it.

As I mentioned in my previous post there two ways to generate the bundle

  1. Using Android Studio, Go to Build > Build Bundle(s) / APK(s) and select Build Bundle(s), you will find the built bundle at : ./app/outputs/bundle/debug/bundle.aab
  2. Using command line, ./gradlew bundleDebug from the root directory of project.

Test/Analyze App Bundle

These are the just ways to generate your application publishing bundle, Once you build your Android App Bundle, you should test/understand how Google Play uses it to generate APKs for the device. There are two ways you should consider testing your app bundle:

  1. Locally using the bundletool command line tool, download this tool from github, It’s open sourced by Google.
  2. Through Google Play by uploading your bundle to the Play Console and using the new internal test track

Only the first option is a feasible option here. Let’s analyze this bundle in detailed and learn more about how it helps us to reduce the app size. We’ll use bundletool command to analyze or generate apks as per our need. I discussed bundletool in my previous post and how it will be helpful.

In this article, I’ve mentioned only bundletool , instead of using the actual command : jar

/Downloads/bundletool-all-0.3.3.jar Actually, I’m using an alias for it which I’ve configured under

You can also setup alias for java -jar

If you don’t want to use the aliases then use the actual command.

Generate all possible APKs archive set

  • Generate an APK set archive using bundletool basic command, you will have timber_app.apks zip file.

Note : Make sure to add language apks configuration manually as there is bug with 3.2.0-alpha14 and 3.2.0-alpha15 versions, none of them generates language configuration apks. Open app/build.gradle and add the following inside the android <> block:

  • Unzip this apks zip archive file into the different directory. Wow !! That’s a lot of apks !! 🤔 😲 😲 You can see the every apk size and get the idea that how it helps to reduce the application size when it gets installed on the device.
Читайте также:  Firestore android что это

If I just consider the en language then there is a reduction of 1 MB in the application size, that’s huge !! 😄 😲, even I’ve not considered density and abi

Note that all apks are prefixed with base-, since our app only contains the one base module, there is not dynamic feature module.

base-master.apk Contains the code and resources for the base module
base-armeabi_v7a.apk, base-arm64_v8a.apk, etc. ABI configuration splits
base-xhdpi.apk, base-mdpi.apk, etc. Screen density configuration splits
base-ko.apk, base-fr.apk, etc. Language configuration splits
standalone-x standalone splits for that configuration

Generate APKs archive set for connected/specific device

As per Google IO’18 official video, bundletool has an ability to generate the apk archive set which contains the apks for the connected device only. In this video, they demonstrated two commands, they generate the my_app.apks apks archive set for just the connected device or as per the specs from provided json.

Sadly, they’re giving me error, I’ve opened the issue under bundletool repo, it may be tool issue or something I’m missing.

Install/Deploy to a connected device

As per my understanding and based on the official documentation it should generate and install the APK from the my_app.apks archive set which we generated in the previous step. Use device-id parameter if you have more than 1 device connected.

Note : I’ve tried both commands are and they’re giving me a problem, I’ve opened the issue under bundletool github repo. My guess is it’s related to signing apk.

Extract APKs for a specific device configuration

To extract apks from generated APKs archive set for a specific device configs, you’ve to provide the device information to the bundletool command. Either you can create manually .json file which contains the device specs or get the device specs from the connected device.

  1. bundletool get-device-spec , this command will give the error for missing required flag output flag. Android developer website doesn’t mention this. Once you’ve the device specs json then use bundletool extract-apks command to generate apks only for pixel2 device.

2. Manually create a device specification JSON as per the below example and just apply the same bundletool extract-apks command with custom json file.

Thats’ it, I explored most of the major operations on the bundletool. Just try this tool with your application and see that how much application size you can reduce before uploading to the Google Play Console

Open Questions/Issues

There are some questions and issues after playing with this tool for few hours.

Is there any way to generate final installable apk from bundle or apks archive set?

I want to compare/analyze the two apks: Universal (tradinational) apk vs APK to specific device (for eg. pixel 2 XL). But I didn’t find any way where I can generate apk for a specific device, I can extract the apks as per device configuration but it gives me all different apks. I am looking for a way to generate only one apk which should be for that particular device (for eg : base+en_US+arm64+xxxhdpi = pixel2 XL)

Although, there is a way to install the apk buildtool install-apks , which I discussed above but it’s giving the error : INSTALL_PARSE_FAILED_NO_CERTIFICATES

Bundle tool » install apks” command isn’t working

Update : Have to set the —ks and —ks-key-alias flags to ensure that the APKs are signed. Only signed APKs can be installed on a device, updated the commands, check the above sections.

Источник

Publish smaller apps with the Android App Bundle

December 27th, 2019

The Android App Bundle (.aab) is a new upload format that includes all of your app’s compiled code and resources, but defers APK generation and signing to Google Play at install time.

Google Play does this through a new app serving model called Dynamic Delivery, this uses your app bundle to generate and serve an optimized APK for each user’s unique device configuration, so they download only the code and resources that are needed to run the application.

This eliminates the need to have to build, sign, and manage multiple APKs based on their ABI, locale, screen size, and more. Additionally, you can use dynamic feature modules to define what feature modules and resources that users first download when they install your application.

Читайте также:  Красивый виджет часов с погодой для андроид

Using Android App Bundles increases the app size limit to 150MB without having to use those pesky APK expansion files. One of the many benefits you get when using Android App Bundles.

Size Savings

As your application size increases, so does the complexity of your application. Your users may run into problems such as:

  • Slower downloads
  • Decreased installation rates
  • Increased uninstall rates
  • Non-supported device APKs

Instead, you can gain the benefits such as:

  • Faster downloads
  • Increased installation rates
  • Decreased uninstall rates
  • Serve users functionality and configurations on demand
  • Simplify your build and release management by removing the need to publish multiple APKs

If you’re curious on how this will impact your Android application today, check out these App Bundle Size Savings.

We wanted to see the benefits this would have on Xamarin, and to our surprise we saw some magnificent results!

Here we have an APK that was 39.4MB using a traditional upload to Google Play. After creating an Android App Bundle instead, we cut our app download size to 23.3MB! That’s a decrease of over 35%!

Getting Started

To build app bundles and support Dynamic Delivery, you can follow these steps:

  1. Download Visual Studio 16.4 or higher on Windows or Visual Studio for Mac 8.4 or higher on Mac.
  2. Prepare your application for Release
  3. Build an Android App Bundle using Visual Studio. If you’re not using an IDE, you can instead build an app bundle from the command line.
  4. Enroll into app signing by Google Play
  5. Publish your app bundle to Google Play.

Build and deploy Android App Bundles

App bundles differ from APKs as they cannot be deployed directly to a device. Rather, it’s a format that is intended to be uploaded with all of your compiled code and resources. After you upload your signed app bundle, Google Play will have everything it needs to build and sign your application’s APKs and serve them to your users using Dynamic Delivery.

If you’re using Visual Studio, you can build your project as a signed app bundle in just a few clicks. If you’re not using the IDE, you can instead build an app bundle from the command line.

To enable support for Android App Bundles, you’ll need to opt-in to the bundle value of the Android Package Format property within your Android options. As you do this, ensure you change your project to a Release configuration as app bundles are intended for release packages only. To do this you can follow these steps:

  1. Right click your project, and select Properties .
  2. Navigate to Android Options .
  3. Change your configuration to Release.
  4. Change the Android Package Format to bundle .

After you’ve completed these steps, you can generate an app bundle by right clicking your project and selecting Archive . This will generate an app bundle for your application.

Test your app bundle

After you’ve created your Android App Bundle, you can test how Google Play will generate the respective APKs when deployed to a device. To test your app bundle, you may try to:

  • Test your Android App Bundle locally using bundletool which generates APKs from your app bundle and deploy them to a connected device.
  • Share your application with a URL. You can share your app as a Google Play Store link with your trusted testers.
  • Set up a custom delivery. You can customize your delivery options based on who you want to test your app.

Learn More

For more detailed information on Android App Bundles, please see Google’s documentation on Android App Bundles.

Summary

With just a few clicks, you can upload your Android App Bundle to Google Play today and give your users the gift this holiday season of a smaller, optimized, dynamic APK for their devices!

Feedback

We encourage your feedback on any issues to be reported via the Report a Problem option found in your favorite IDE via Help > Report a Problem. If you have any questions regarding Android App Bundles, please post them on the Xamarin Forums or Stack Overflow.

Источник

Оцените статью