Categories
Mobile

Prepare your Android Project for Android Gradle plugin 8.0 API changes

[ad_1]

Posted by Wojtek Kaliciński,
Boris Farber, Android
Developer Relations Engineers, and
Xavier Ducrohet, Android Studio
Tech Lead

To improve build speed and provide stable APIs, the Transform APIs will be
removed in Android Gradle plugin (AGP) version 8.0. Most use cases have
replacement APIs which are available starting from AGP version 7.2. Read on
for more details.

The Android developer community’s top request has been to improve build speed
while making sure Android Gradle plugin (AGP) has a solid, stable, and well
supported API.

To improve build speed starting from AGP 7.2, we have stabilized the
Artifacts API
and updated the
Instrumentation API. For common use cases, these APIs replace the
Transform APIs, which cause longer build times and are gone in AGP 8.0.

This article walks you through transitioning off the Transform APIs, whether
you’re working on a Gradle plugin or an application.

Guidance for Gradle plugins

To improve build times, we split Transform’s functionality into the following
APIs that are optimized for common use cases:

  • The
    Instrumentation
    API lets you transform and analyze compiled app classes using
    ASM callbacks. For example
    use this API to add custom traces to methods or classes for additional or
    custom logging.
  • The
    Artifacts
    API gives access to files or directories, whether temporary or final, that
    are produced by AGP during the build. Use this API to:
    • Add additional generated classes to the app, such as glue
      code for dependency injection.
    • Implement transformations based on whole program analysis, when all
      classes can be transformed together in a single task. This is only
      available starting from AGP 7.4.0-alpha06. The build.gradle.kts file
      in the “modifyProjectClasses” Gradle recipe shows how to do it.

For examples of how to use the replacement APIs see the
Transform API update note, and our
Gradle recipes.

Guidance for apps

Make sure that you update your plugins to be AGP 8.0 compliant before updating
your app to AGP 8.0. If the relevant plugins are not compliant, please create
a bug that includes a link to this post and send it to the plugin authors.

Several commonly used plugins have already migrated to use these new APIs,
including the
Hilt Gradle plugin.

Share your feedback

If your use case is not covered by any of the new APIs, please
file a bug.

We encourage you to get started with making your plugins compatible with the
new AGP APIs. Getting started now means that you have enough time to
familiarize yourself with the APIs, share your feedback and then upgrade your
dependencies and plugins.



[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *