AGP 7.0: Subsequent main launch for the Android Gradle plugin


Posted by Murat Yener, Developer Advocate

At present marks the discharge of the primary Canary model of Android Studio Arctic Fox (2020.3.1), along with Android Gradle plugin (AGP) model 7.0.0-alpha01. With this launch we’re adjusting the model numbering for our Gradle plugin and decoupling it from the Android Studio versioning scheme. On this weblog publish we’ll clarify the explanations for the change, in addition to give a preview of some necessary modifications we’re making to our new, incubating Android Gradle plugin APIs and DSL.

New versioning scheme

With AGP 7.0.0 we’re adopting the ideas of semantic versioning. What this implies is that solely main model modifications will break API compatibility. We intend to launch one main model every year, proper after Gradle introduces its personal yearly main launch.

Furthermore, within the case of a breaking change, we’ll be certain that the eliminated API is marked with @Deprecated a couple of 12 months prematurely and that its alternative is obtainable on the similar time. It will give builders roughly a 12 months emigrate and check their plugins with the brand new API earlier than the outdated API is eliminated.

Alignment with Gradle’s version can also be why we’re skipping variations 5 and 6, and shifting on to AGP 7.0.0. This alignment signifies that AGP 7.x is supposed to work with Gradle 7.x APIs. Whereas it might additionally run on Gradle 8.x, this isn’t assured and can rely on whether or not 8.x removes APIs that AGP depends on.

With this transformation, the AGP model quantity will likely be decoupled from the Android Studio model quantity. Nonetheless we’ll hold releasing Android Studio and Android Gradle plugin collectively for the foreseeable future.

Compatibility between Android Studio and Android Gradle plugin stays unchanged. As a common rule, tasks that use secure variations of AGP could be opened with newer variations of Android Studio.

Java 11 requirement

With AGP 7.0.0-alpha01 we’re altering the minimal required Java programming language model to Java 11. We’re asserting this early within the Canary schedule and lots of months forward of the secure launch to permit builders time to prepare.

Incubating APIs and necessary API modifications

This launch of AGP additionally introduces some API modifications. As a reminder, a lot of APIs that have been launched in AGP 4.1 have been marked as incubating and have been topic to alter. The truth is, in AGP 4.2 a few of these APIs have modified. The APIs which can be at present incubating don’t comply with the deprecation cycle that we clarify above.

Here’s a abstract of some necessary API modifications.

  • The onVariants, onProperties and onVariantProperties blocks are eliminated in model 4.2 beta.
  • These APIs are changed with beforeVariants and onVariants within the new androidComponents block. Each beforeVariants and onVariants can optionally use a VariantSelector to cut back the variety of variants the callback will run on, based mostly on construct sort, title or taste through the use of withBuildType, withName and withFlavor accordingly. The lambda onVariants and beforeVariants receives is executed after AGP computes variant mixtures in afterEvaluate. Nesting properties inside onVariants is eliminated.
  • Comparable APIs are added to androidComponents to permit separate blocks for UnitTests (beforeUnitTest and unitTest) and AndroidTests (beforeAndroidTest and androidTest) as an alternative of nesting checks inside variants.
  • Two lessons utilized by each the outdated and new method of registering actions for variants have been renamed. Variant is now VariantBuilder, and it’s used within the beforeVariants part. VariantProperties is now Variant and it’s handed to the brand new onVariants block.

Let’s check out a few of these modifications. Here’s a pattern onVariants block which targets the discharge construct. The onVariants block Is modified to beforeVariants and makes use of a variant selector within the following instance.

```
android {
   …
   //onVariants.withName("launch") {
   //   ...
   //}
   …
}
androidComponents {
   val launch = selector().withBuildType("launch")
   beforeVariants(launch) { variant ->
      ...
   }
}

```

Equally onVariantProperties block is modified to onVariants.

```
android {
   ...
   //onVariantProperties {
   //   ... 
   //}
   …
}

androidComponents.onVariants { variant ->
      ... 
}

```

Be aware, this customization is often performed in a plugin and shouldn’t be positioned in construct.gradle. We’re shifting away from utilizing capabilities with receivers which suited the DSL syntax however are usually not obligatory within the plugin code.

We’re planning to make these APIs secure with AGP 7.0.0 and all plugin authors should migrate to the brand new androidComponents. If you wish to keep away from coping with such modifications, make sure that your plugins solely use secure APIs and don’t rely on APIs marked as incubating.

If you wish to study extra about different modifications coming with this launch, make sure that to check out the release notes.

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

Recent Articles

5 greatest free LastPass options and the best way to switch

Credit score: Joe Hindy / Android AuthorityLastPass places customers in its free tier between a rock and a tough place. Starting March 2021, free...

Redmi Word 10 to have two segment-leading digital camera sensors

For the launch of the Redmi Note 10 series, the corporate is leaving no stone unturned to collect as a lot consideration as potential....

Xiaomi Redmi Observe 10 main leak reveals design, Snadragon 678 chipset

Xiaomi will announce its Redmi Note 10 lineup on March 4 however the cellphone retains leaking everywhere in the palce. After we noticed its...

Related Stories

Stay on op - Ge the daily news in your inbox