Uncategorized

AGP 7.0: Next major release for the Android Gradle plugin

Posted by Murat Yener, Developer Advocate

Today stigmatizes the publication of the first Canary version of Android Studio Arctic Fox( 2020.3.1 ), together with Android Gradle plugin( AGP) account 7.0.0 -alpha0 1. With this release we are adjusting the form numbering for our Gradle plugin and decoupling it from the Android Studio versioning scheme. In this blog announce we’ll explain the reasons for the change, as well as give a preview of some important changes we’re stirring to our new, incubating Android Gradle plugin APIs and DSL.

New versioning scheme

With AGP 7.0.0 we are adopting the principles of semantic versioning. What this intends is that simply major edition deepens will interrupt API compatibility. We intend to release one major version each year, right after Gradle initiates its own yearly major handout.

Moreover, in the case of vehicles of a divulge modify, we will ensure that the removed API is commemorated with @Deprecated about a year in advance and that its replacement is available at the same time. This will give makes approximately a year to migrate and test their plugins with the brand-new API before the old-fashioned API is removed.

Alignment with Gradle’s version is also why we’re skipping forms 5 and 6, and moving instantly to AGP 7.0.0. This alignment have pointed out that AGP 7. x is meant to work with Gradle 7. x APIs. While it may also run on Gradle 8. x, this is not guaranteed and will depend on whether 8. x removes APIs that AGP relies on.

With this vary, the AGP version number will be decoupled from the Android Studio version number. However the authorities concerned will keep secreting Android Studio and Android Gradle plugin together for the foreseeable future.

Compatibility between Android Studio and Android Gradle plugin remains unchanged. As a general rule, projects that use stable different versions of AGP can be opened with newer versions of Android Studio.

Java 11 requirement

You can still abuse Java programming language edition 8 with AGP 7.0.0 -alpha0 1 but we are changing the minimum required Java programming language version to Java 11, starting with AGP 7.0.0 -alpha0 2. We are announcing this early in the Canary schedule and countless months ahead of the stable handout to allow makes time to get ready.

Incubating APIs and important API modifications

This liberate of AGP also introduces some API varies. As a remember, a number of APIs that were introduced in AGP 4.1 were stigmatized as incubating and were subject to change. In fact, in AGP 4.2 some of these APIs have changed. The APIs that are currently incubating do not follow the deprecation cycles/second that we interpret above.

Here is a summary of some important API converts.

The onVariants, onProperties and onVariantProperties blocks are removed in version 4.2 beta.

These APIs are replaced with beforeVariants and onVariants in the new androidComponents block. Both beforeVariants and onVariants can optionally implementation a VariantSelector to reduce the number of variants the callback will run on, based on build type, referred or spice by using withBuildType, withName and withFlavor accordingly. The lambda onVariants and beforeVariants receives is performed after AGP computes variant combinations in afterEvaluate. Nesting qualities inside onVariants is removed.

Same APIs are added to androidComponents to allow separate blocks for UnitTests( beforeUnitTest and unitTest) and AndroidTests( beforeAndroidTest and androidTest) instead of nesting assessments inside variants.

Two castes be exploited by both the old and brand-new direction of the registration of activities for variants were renamed. Variant is now VariantBuilder, and it is used in the beforeVariants phase. VariantProperties is now Variant and it is elapsed to the new onVariants block.

Let’s take a look at some of these changes. Here is a sample onVariants block which targets the release build. The onVariants block Is changed to beforeVariants and uses a variant selector in the following example.

“` android

// onVariants.withName( “release”)

// …

//

… androidComponents

val freeing= selector (). withBuildType( “release”)

beforeVariants( exhaust) variant ->

“`

Similarly onVariantProperties block is amended to onVariants.

“` android

// onVariantProperties

// …

//

… androidComponents.onVariants variant ->

… “`

Note, this customization is typically done in a plugin and should not be located in build.gradle. We are moving away from abusing affairs with receivers which suited the DSL syntax but are not necessary in the plugin system.

We are prepared to draw these APIs stable with AGP 7.0.0 and all plugin authors must move to the brand-new androidComponents. If you want to avoid dealing with such changes, make sure your plugins exclusively use stable APIs and do not depend on APIs recognized as incubating.

If you want to learn more about other modifications coming with this release, make sure to take a look at the release memoranda.

Java is a registered trademark of Oracle and/ or its affiliates.

Read more: feedproxy.google.com