Class Transform
This API is deprecated and is planned to be removed in Android Gradle plugin 9.0.
There is no single replacement. For more information about how to migrate, see https://developer.android.com/studio/releases/gradle-plugin-roadmap .
For each added transform, a new task is created. The action of adding a transform takes care of handling dependencies between the tasks. This is done based on what the transform processes. The output of the transform becomes consumable by other transforms and these tasks get automatically linked together.
The Transform indicates what it applies to (content, scope) and what it generates (content).
A transform receives input as a collection TransformInput, which is composed of JarInputs and DirectoryInputs. Both provide information about the QualifiedContent.Scopes and
QualifiedContent.ContentTypes associated with their particular content.
The output is handled by TransformOutputProvider which allows creating new
self-contained content, each associated with their own Scopes and Content Types. The content
handled by TransformInput/Output is managed by the transform system, and their location is not
configurable.
It is best practice to write into as many outputs as Jar/Folder Inputs have been received by the transform. Combining all the inputs into a single output prevents downstream transform from processing limited scopes.
While it's possible to differentiate different Content Types by file extension, it's not
possible to do so for Scopes. Therefore if a transform request a Scope but the only available
Output contains more than the requested Scope, the build will fail.
If a transform request a single content type but the only available content includes more than
the requested type, the input file/folder will contain all the files of all the types, but the
transform should only read, process and output the type(s) it requested.
Additionally, a transform can indicate secondary inputs/outputs. These are not handled by upstream or downstream transforms, and are not restricted by type handled by transform. They can be anything.
It's up to each transform to manage where these files are, and to make sure that these files are generated before the transform is called. This is done through additional parameters when register the transform.
These secondary inputs/outputs allow a transform to read but not process any content. This can
be achieved by having getScopes() return an empty list and use getReferencedScopes() to indicate what to read instead.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanapplyToVariant(VariantInfo variant) Deprecated.Whether this transform should be applied to a given variant.abstract Set<QualifiedContent.ContentType>Deprecated.Returns the type(s) of data that is consumed by the Transform.abstract StringgetName()Deprecated.Returns the unique name of the transform.Deprecated.Returns the type(s) of data that is generated by the Transform.Deprecated.Returns a map of non-file input parameters using a unique identifier as the map key.Set<? super QualifiedContent.Scope>Deprecated.Returns the referenced scope(s) for the Transform.abstract Set<? super QualifiedContent.Scope>Deprecated.Returns the scope(s) of the Transform.Deprecated.Returns a list of additional (out of streams) directory(ies) that this Transform creates.Deprecated.replaced bygetSecondaryFiles()Deprecated.Returns a list of additional (out of streams) file(s) that this Transform creates.Deprecated.Returns a list of additional file(s) that this Transform needs to run.booleanDeprecated.Returns if this transform's outputs should be cached.abstract booleanDeprecated.Returns whether the Transform can perform incremental work.voidsetOutputDirectory(org.gradle.api.provider.Property<org.gradle.api.file.Directory> directory) Deprecated.For Transforms that produce an output available though the [BuildArtifactsHolder] provider based interfaces should indicate the output directory of the produced artifactvoidsetOutputFile(org.gradle.api.provider.Property<org.gradle.api.file.RegularFile> file) Deprecated.voidtransform(Context context, Collection<TransformInput> inputs, Collection<TransformInput> referencedInputs, TransformOutputProvider outputProvider, boolean isIncremental) Deprecated.replaced bytransform(TransformInvocation).voidtransform(TransformInvocation transformInvocation) Deprecated.Executes the Transform.
-
Constructor Details
-
Transform
public Transform()Deprecated.
-
-
Method Details
-
getName
Deprecated.Returns the unique name of the transform.This is associated with the type of work that the transform does. It does not have to be unique per variant.
-
applyToVariant
Deprecated.Whether this transform should be applied to a given variant.since 3.4
- Parameters:
variant- information about the current variant.- Returns:
- true if the transform should be applied to a given variant, false otherwise.
-
getInputTypes
Deprecated.Returns the type(s) of data that is consumed by the Transform. This may be more than one type. This must be of typeQualifiedContent.DefaultContentType -
getOutputTypes
Deprecated.Returns the type(s) of data that is generated by the Transform. This may be more than one type.The default implementation returns
getInputTypes().This must be of type
QualifiedContent.DefaultContentType -
getScopes
Deprecated.Returns the scope(s) of the Transform. This indicates which scopes the transform consumes. -
getReferencedScopes
Deprecated.Returns the referenced scope(s) for the Transform. These scopes are not consumed by the Transform. They are provided as inputs, but are still available as inputs for other Transforms to consume.The default implementation returns an empty Set.
-
getSecondaryFileInputs
Deprecated.replaced bygetSecondaryFiles()Returns a list of additional file(s) that this Transform needs to run. Preferably, usegetSecondaryFiles()API which allow eah secondary file to indicate if changes can be handled incrementally or not. This API will treat all additional file change as a non incremental event.Changes to files returned in this list will trigger a new execution of the Transform even if the qualified-content inputs haven't been touched.
Any changes to these files will trigger a non incremental execution.
The default implementation returns an empty collection.
-
getSecondaryFiles
Deprecated.Returns a list of additional file(s) that this Transform needs to run.Changes to files returned in this list will trigger a new execution of the Transform even if the qualified-content inputs haven't been touched.
Each secondary input has the ability to be declared as necessitating a non incremental execution in case of change. This Transform can therefore declare which secondary file changes it supports in incremental mode.
The default implementation returns an empty collection.
-
getSecondaryFileOutputs
Deprecated.Returns a list of additional (out of streams) file(s) that this Transform creates.These File instances can only represent files, not directories. For directories, use
getSecondaryDirectoryOutputs()Changes to files returned in this list will trigger a new execution of the Transform even if the qualified-content inputs haven't been touched.
Changes to these output files force a non incremental execution.
The default implementation returns an empty collection.
-
getSecondaryDirectoryOutputs
Deprecated.Returns a list of additional (out of streams) directory(ies) that this Transform creates.These File instances can only represent directories. For files, use
getSecondaryFileOutputs()Changes to directories returned in this list will trigger a new execution of the Transform even if the qualified-content inputs haven't been touched.
Changes to these output directories force a non incremental execution.
The default implementation returns an empty collection.
-
getParameterInputs
Deprecated.Returns a map of non-file input parameters using a unique identifier as the map key.Changes to values returned in this map will trigger a new execution of the Transform even if the content inputs haven't been touched.
Changes to these values force a non incremental execution.
The default implementation returns an empty Map.
-
isIncremental
public abstract boolean isIncremental()Deprecated.Returns whether the Transform can perform incremental work.If it does, then the TransformInput may contain a list of changed/removed/added files, unless something else triggers a non incremental run.
-
setOutputDirectory
public void setOutputDirectory(@NonNull org.gradle.api.provider.Property<org.gradle.api.file.Directory> directory) Deprecated.For Transforms that produce an output available though the [BuildArtifactsHolder] provider based interfaces should indicate the output directory of the produced artifact- Parameters:
directory-
-
setOutputFile
public void setOutputFile(@NonNull org.gradle.api.provider.Property<org.gradle.api.file.RegularFile> file) Deprecated. -
transform
@Deprecated public void transform(@NonNull Context context, @NonNull Collection<TransformInput> inputs, @NonNull Collection<TransformInput> referencedInputs, @Nullable TransformOutputProvider outputProvider, boolean isIncremental) throws IOException, TransformException, InterruptedException Deprecated.replaced bytransform(TransformInvocation). -
transform
public void transform(@NonNull TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException Deprecated.Executes the Transform.The inputs are packaged as an instance of
TransformInvocation- The inputs collection of
TransformInput. These are the inputs that are consumed by this Transform. A transformed version of these inputs must be written into the output. What is received is controlled throughgetInputTypes(), andgetScopes(). - The referencedInputs collection of
TransformInput. This is for reference only and should be not be transformed. What is received is controlled throughgetReferencedScopes().
getScopes(), and what it wants to see ingetReferencedScopes().Even though a transform's
isIncremental()returns true, this method may be receivefalsein isIncremental. This can be due to- a change in secondary files (
getSecondaryFiles(),getSecondaryFileOutputs(),getSecondaryDirectoryOutputs()) - a change to a non file input (
getParameterInputs()) - an unexpected change to the output files/directories. This should not happen unless tasks are improperly configured and clobber each other's output.
- a file deletion that the transform mechanism could not match to a previous input. This should not happen in most case, except in some cases where dependencies have changed.
JarInput.getStatus()will returnStatus.NOTCHANGEDeven though the file may be added/changed.DirectoryInput.getChangedFiles()will return an empty map even though some files may be added/changed.
- Parameters:
transformInvocation- the invocation object containing the transform inputs.- Throws:
IOException- if an IO error occurs.InterruptedExceptionTransformException- Generic exception encapsulating the cause.
- The inputs collection of
-
isCacheable
public boolean isCacheable()Deprecated.Returns if this transform's outputs should be cached. Please readCacheableTaskJavadoc if you would like to make your transform cacheable.
-