5 ways to prepare your app build for Android Studio Flamingo release

[ad_1]

When you upgrade to Android Studio Flamingo and Android Gradle Plugin (AGP) 8.0, you need to update your app build files to accommodate five important build behavior changes.

The AGP Upgrade Assistant can help you with these changes. When you use it, some changes it suggests, keep the existing build behavior by adding code lines to opt out of the build behavior changes. Migrate to the new behaviors at a later point by removing these code lines.

Note that in this article we refer to the file, but the same changes apply to the file if you’re using Groovy. Let’s take a look at these changes.

The DSL property represents the Kotlin or Java package name for the generated and classes, and replaces the attribute previously defined in the Android manifest. To move to the namespace configuration, add the DSL to the block in the module-level file and remove the attribute in the manifest.

The Android Studio AGP Upgrade Assistant will help you with the migration by moving the package from Android manifest attribute to the property in build files.

To understand why we’re making this change, let’s look at the previous behavior.

Previously, the attribute was used both for setting the and resource namespaces, unnecessarily coupling these two mostly unrelated concepts.

By disallowing setting the name in the manifest file, and introducing the property, we’re separating the used for your app’s identity from the resource namespaces. This clarifies where the namespace value comes from, and lets you refactor your app’s code and resources without affecting your

classes for library modules are now non-transitive by default, which means that each class only includes the resources declared in the library module itself, not resources from its dependencies. This means that you must use fully qualified, namespaced calls when you’re referencing resources.

The flag in the file controls the class behavior. From AGP 8.0, it’s when not specified, and thus becomes the default.

To get help updating your class calls using Android Studio, go to Refactor > Migrate to Non-Transitive R Classes. This refactoring action converts all calls to fully qualified calls and will set (if the flag was set to ) in the file.

classes are generated classes that map your resource names to IDs in your code. Until Android Studio Bumblebee/AGP 7.1 the classes were transitive. That means the build was generating resource IDs not only for the library classes but also for all modules that the library depends ons. This generation resulted in bigger executable sizes and longer build times.

In the non-transitive behavior each library module class includes only the resources declared in the module itself, thus reducing the size of the class for that module.

If you call the class from your module code, you need to enable in the block in your module’s file. Otherwise, the file isn’t automatically generated anymore.

The file is a Java file containing static information about your current build such as the name, name, flag, and others. Previously AGP always generated the file for all Android modules. If you develop a multi-module app you can end up with a lot of files that AGP needs to process, which affects your build speed. However, most modules don’t need any of the information from the class.

In addition, is a Java file. Assuming your app is written with Kotlin, mixing Java and Kotlin in the same module further affects build performance. To mitigate this, we introduced the flag set in . When , the file isn’t generated as a Java file, but as a compiled file. This avoids the Java compilation step!

If you need the old behavior for all modules, set the in your file.

Similar to , and are off by default. To enable them for a particular module, set the and options to in the block of the module’s file:

You can use similar methods to re-enable AIDL or RenderScript for modules that require it, or for your entire project, however please note that RenderScript was deprecated in Android 12 so you should migrate from it.

The last behavior change: R8 is now in full mode by default, enabling app size reductions and performance improvement. You shouldn’t need to update anything for this change, but if you encounter build or runtime failures you should double-check that your keep rules are configured correctly. For guidance on how to configure the keep rules, see Shrink, obfuscate, and optimize your app.

To sum it up, these are the five ways to prepare your app build for the Android Studio Flamingo release with AGP 8.0. If you develop a plugin please read our blog post for plugin changes. If you want to learn more about the changes to build, see the video from Android Dev Summit ’22 and the AGP release notes.

Code snippets license:

Copyright 2023 Google LLC.
SPDX-License-Identifier: Apache-2.0

[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *