Skip to content

Latest commit

 

History

History

workerEnabledTransformation

Worker-enabled transformation recipe

This sample uses the InAndOutDirectoryOperationRequest.toTransformMany() API on an object of type Artifact.Single, Artifact.ContainsMany, and Artifact.Transformable. This method is defined in InAndOutDirectoryOperationRequest.

Custom plugin is defined in CustomPlugin.kt. It registers task CopyApksTask.kt that creates asynchronous WorkAction that copies APK file.

WorkAction is part of Gradle Worker API

  • a standard way of developing parallel tasks. It enables the division of a task action into smaller, independent units of work. These units can then be executed simultaneously and independently, maximizing resource utilization and accelerating build completion. Android Gradle Plugin made it simpler to use Gradle workers API with ArtifactTransformationRequest.

To Run

Just type ./gradlew copyDebugApks you will be able to find two APKs: before copying, it is app/build/intermediates/apk/debug/packageDebug/app-debug.apk and app/build/outputs/apk/debug/app-debug.apk after copying.

Renaming APKs

This recipe shows how one can make use of workers to transform the APKs, and uses a straight up copy as an example.

It's not recommended to simply rename the APKs that are generated by the default task because Studio expects specific names.

Having an API to rename things based on date/time would break Studio deployment as Studio would not know where to get these files. Based on this the API exposed by AGP allows you to copy them only.