AGP 7.0: Subsequent main launch for the Android Gradle plugin

Posted by Murat Yener, Developer Advocate

Right this moment 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 put up 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 rules of semantic versioning. What this implies is that solely main model modifications will break API compatibility. We intend to launch one main model annually, 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 few yr upfront and that its alternative is obtainable on the similar time. It will give builders roughly a yr 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 transferring 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 depend upon whether or not 8.x removes APIs that AGP depends on.

With this modification, the AGP model quantity can be decoupled from the Android Studio model quantity. Nonetheless we’ll maintain releasing Android Studio and Android Gradle plugin collectively for the foreseeable future.

Compatibility between Android Studio and Android Gradle plugin stays unchanged. As a normal rule, initiatives that use secure variations of AGP might 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 saying 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, numerous APIs that had been launched in AGP 4.1 had been marked as incubating and had been topic to vary. 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 scale back the variety of variants the callback will run on, based mostly on construct kind, title or taste by utilizing 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.
  • Related 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 had 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 ->
      ... 
}

```

Word, this customization is often achieved in a plugin and shouldn’t be positioned in construct.gradle. We’re transferring away from utilizing capabilities with receivers which suited the DSL syntax however aren’t vital 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, ensure that your plugins solely use secure APIs and don’t depend upon APIs marked as incubating.

If you wish to be taught extra about different modifications coming with this launch, ensure that to check out the release notes.

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

Recent Articles

U.S. Cell On line casino Sport Spending Grows by 16% to $4.8 Billion

Participant spending in cell On line casino video games in the USA rose 16.4 p.c to $4.8 billion throughout the...

Analyst: Underneath-display Face ID on iPhone 14 ‘is not closing but’ and could possibly be delayed

Earlier right now we had been stunned with renders of the so-called “iPhone 14” earlier than the iPhone 13 was even formally introduced. The...

A eulogy to my super-cheap operating headphones

In Might, I wrote about how cheap running headphones were great for me, when it got here to my ongoing job (and the topic...

Related Stories

Stay on op - Ge the daily news in your inbox