Skip to content

Commit

Permalink
Update recipe to include toTransformMany documentation
Browse files Browse the repository at this point in the history
This updates workerEnabledTransformation recipe which is already using
the toTransformMany API, to include information on the usage of it.

Bug: n/a
Test: this is a test
Change-Id: I13adbae7fd9043cb7889a168a44b0f17b6b52984
  • Loading branch information
micahjo7 committed Mar 18, 2024
1 parent b835bbc commit 6d97736
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 22 deletions.
11 changes: 7 additions & 4 deletions recipes/workerEnabledTransformation/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Worker Enable Transformation recipe
# Worker-enabled transformation recipe

This sample shows how to transform the artifact that has artifact directory type.
It copies the build APK to the specified directory.
This sample uses the `InAndOutDirectoryOperationRequest.toTransformMany()` API on an object of type
[Artifact.Single](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/artifact/Artifact.Single),
[Artifact.ContainsMany](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/artifact/Artifact.ContainsMany),
and [Artifact.Transformable](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/artifact/Artifact.Transformable).
This method is defined in [InAndOutDirectoryOperationRequest](https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/artifact/InAndOutDirectoryOperationRequest).

Custom plugin is defined in [CustomPlugin.kt](build-logic/plugins/src/main/kotlin/CustomPlugin.kt).
It registers task [CopyApksTask.kt](build-logic/plugins/src/main/kotlin/CopyApksTask.kt) that creates asynchronous
Expand All @@ -16,7 +19,7 @@ and accelerating build completion. Android Gradle Plugin made it simpler to use

## To Run
Just type `./gradlew copyDebugApks`
you will be able to find two APKs: before copying its
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.

Expand Down
2 changes: 1 addition & 1 deletion recipes/workerEnabledTransformation/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Copyright 2022 The Android Open Source Project
Copyright 2024 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,12 +16,8 @@

import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.gradle.AppPlugin
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.register
import com.android.build.api.artifact.SingleArtifact

Expand All @@ -46,19 +42,19 @@ class CustomPlugin : Plugin<Project> {
// registering copy<Variant>Apk task and getting provider for it
val copyApksProvider = project.tasks.register("copy${variant.name}Apks", CopyApksTask::class.java)

// Adds the task as APK transformer. This automatically creates
// a dependency of `copyApks` task to the last transformer of
// SingleArtifact.APK. This also creates transformationRequest of type
// [com.android.build.api.artifact.ArtifactTransformationRequest]. It allows to
// submit WorkAction to Gradle's [WorkQueue] to parallelize
// the transformations.
// Adds the task as APK transformer. This automatically creates a dependency of `copyApks` task to the
// last transformer of SingleArtifact.APK. This also creates transformationRequest of type
// [com.android.build.api.artifact.ArtifactTransformationRequest]. It allows to submit WorkAction to
// Gradle's [WorkQueue] to parallelize the transformations.
// Lastly, this uses the toTransformMany() API, used on directory artifacts of type 'Single',
// 'Transformable', and 'ContainsMany'.
val transformationRequest = variant.artifacts.use(copyApksProvider)
.wiredWithDirectories(
CopyApksTask::apkFolder,
CopyApksTask::outFolder)
.toTransformMany(SingleArtifact.APK)

// configures copyApk task by adding transformation request as a property value
// Configures copyApk task by adding transformation request as a property value
copyApksProvider.configure {
it.transformationRequest.set(transformationRequest)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion recipes/workerEnabledTransformation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 6d97736

Please sign in to comment.