HomeAndroid5 methods to organize your app construct for Android Studio Flamingo launch...

5 methods to organize your app construct for Android Studio Flamingo launch | by Boris Farber | Android Builders | Apr, 2023


Whenever you improve to Android Studio Flamingo and Android Gradle Plugin (AGP) 8.0, you could replace your app construct information to accommodate 5 essential construct conduct adjustments.

The AGP Improve Assistant can assist you with these adjustments. Whenever you use it, some adjustments it suggests, maintain the prevailing construct conduct by including code strains to decide out of the construct conduct adjustments. Migrate to the brand new behaviors at a later level by eradicating these code strains.

Word that on this article we discuss with the file, however the identical adjustments apply to the file for those who’re utilizing Groovy. Let’s check out these adjustments.

The DSL property represents the Kotlin or Java bundle identify for the generated and lessons, and replaces the attribute beforehand outlined within the Android manifest. To maneuver to the namespace configuration, add the DSL to the block within the module-level file and take away the attribute within the manifest.

The Android Studio AGP Improve Assistant will assist you with the migration by shifting the bundle from Android manifest attribute to the property in construct information.

To grasp why we’re making this variation, let’s have a look at the earlier conduct.

Beforehand, the attribute was used each for setting the and useful resource namespaces, unnecessarily coupling these two largely unrelated ideas.

By disallowing setting the identify within the manifest file, and introducing the property, we’re separating the used in your app’s identification from the useful resource namespaces. This clarifies the place the namespace worth comes from, and allows you to refactor your app’s code and sources with out affecting your

lessons for library modules at the moment are non-transitive by default, which signifies that every class solely consists of the sources declared within the library module itself, not sources from its dependencies. Which means that you need to use totally certified, namespaced calls while you’re referencing sources.

The flag within the file controls the class conduct. From AGP 8.0, it’s when not specified, and thus turns into the default.

To get assist updating your class calls utilizing Android Studio, go to Refactor > Migrate to Non-Transitive R Lessons. This refactoring motion converts all calls to completely certified calls and can set (if the flag was set to ) within the file.

lessons are generated lessons that map your useful resource names to IDs in your code. Till Android Studio Bumblebee/AGP 7.1 the lessons have been transitive. Which means the construct was producing useful resource IDs not just for the library lessons but in addition for all modules that the library relies upon ons. This technology resulted in larger executable sizes and longer construct occasions.

Within the non-transitive conduct every library module class consists of solely the sources declared within the module itself, thus decreasing the scale of the class for that module.

If you happen to name the class out of your module code, you could allow within the block in your module’s file. In any other case, the file isn’t robotically generated anymore.

The file is a Java file containing static details about your present construct such because the identify, identify, flag, and others. Beforehand AGP all the time generated the file for all Android modules. If you happen to develop a multi-module app you may find yourself with a whole lot of information that AGP must course of, which impacts your construct velocity. Nonetheless, most modules don’t want any of the data from the class.

As well as, is a Java file. Assuming your app is written with Kotlin, mixing Java and Kotlin in the identical module additional impacts construct efficiency. To mitigate this, we launched the flag set in . When , the file isn’t generated as a Java file, however as a compiled file. This avoids the Java compilation step!

If you happen to want the previous conduct for all modules, set the in your file.

Just like , and are off by default. To allow them for a specific module, set the and choices to within the block of the module’s file:

You need to use related strategies to re-enable AIDL or RenderScript for modules that require it, or in your complete venture, nonetheless please word that RenderScript was deprecated in Android 12 so it is best to migrate from it.

The final conduct change: R8 is now in full mode by default, enabling app dimension reductions and efficiency enchancment. You shouldn’t must replace something for this variation, however for those who encounter construct or runtime failures it is best to double-check that your maintain guidelines are configured accurately. For steerage on the way to configure the maintain guidelines, see Shrink, obfuscate, and optimize your app.

To sum it up, these are the 5 methods to organize your app construct for the Android Studio Flamingo launch with AGP 8.0. If you happen to develop a plugin please learn our weblog publish for plugin adjustments. If you wish to study extra concerning the adjustments to construct, see the video from Android Dev Summit ’22 and the AGP launch notes.

Code snippets license:

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments