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 submit 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 make sure that the eliminated API is marked with @Deprecated a couple of 12 months upfront and that its substitute is out there on the identical time. It will give builders roughly a 12 months emigrate and check their plugins with the brand new API earlier than the previous 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 could 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 variation, 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 basic rule, tasks that use secure variations of AGP will 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, a variety of APIs that have been launched in AGP 4.1 have been marked as incubating and have been topic to vary. Actually, in AGP 4.2 a few of these APIs have modified. The APIs which are 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, identify or taste through the use of withBuildType, withName and withFlavor accordingly. The lambda onVariants and beforeVariants receives is executed after AGP computes variant combos 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 exams inside variants.
  • Two courses utilized by each the previous 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 usually completed 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 usually are not needed 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 rely on APIs marked as incubating.

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

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

Recent Articles

Why create (or not) Panorama App Previews with Portrait Screenshots – Apptamin

Apple has at all times been fairly strict concerning the tips for App Preview videos: there are particular guidelines your video has to comply...

We requested, you instructed us: This is how lengthy your display timeout is ready for

Credit score: Ryan-Thomas Shaw / Android AuthoritySetting your display timeout is a simple method to tame pointless battery usage in your Android cellphone. Set...

Ballot: How usually do you improve your iPhone? – 9to5Mac

A latest survey confirmed that one among three clients plan to stay with their iPhone for at least more than three years. Because the...

Related Stories

Stay on op - Ge the daily news in your inbox