Method to register a callback to be called with VariantBuilderT instances that
satisfies the selector. The callback will be called as soon as the VariantBuilderT
instance has been created but before any com.android.build.api.artifact.Artifact has been
determined, therefore the build flow can still be changed when the callback is invoked.
At this stage, access to the DSL objects is disallowed, use finalizeDsl method to
programmatically access the DSL objects before the VariantBuilderT object is built.
Example without selection:
androidComponents{beforeVariants{println("Called with variant : ${'$'}name")}}
Example with selection:
androidComponents{valdebug=selector().withBuildType("debug")beforeVariants(debug){println("Called with variant : ${'$'}name")}}
At this stage, access to the DSL objects is disallowed and access to the VariantBuilderT
instance is limited to read-only access.
Because the list of artifacts (including private ones) is final, one cannot change the build
flow anymore as org.gradle.api.Tasks are now expecting those artifacts as inputs. However
users can modify such artifacts by replacing or transforming them, see com.android.build.api.artifact.Artifacts
for details.
Code executing in the callback also has access to the VariantT information which is used
to configure org.gradle.api.Task inputs (for example, the buildConfigFields). Such
information represented as org.gradle.api.provider.Property can still be modified ensuring
that all org.gradle.api.Tasks created by the Android Gradle Plugin use the updated value.
Please see Gradle documentation first at :
https://docs.gradle.org/current/userguide/custom_plugins.html#sec:getting_input_from_the_build
A lambda must be provided to create and configure the variant scoped object
that will be stored with the Android Gradle Plugin com.android.build.api.variant.Variant
instance.
API to customize the DSL Objects programmatically after they have been evaluated from the
build files and before used in the build process next steps like variant or tasks creation.
Provides access to underlying Android SDK and build-tools components like adb.
Was this helpful?
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2022-04-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-04-07 UTC."],[],[]]