SourceDirectories

public interface SourceDirectories extends Named

Known direct subclasses
SourceDirectories.Flat

Represents all the source folders for a source type in the variant.

SourceDirectories.Layered

Represent a collection of directories that have overlay properties to each other.


Defines all common behaviors to sources access in AGP.

Adding directories is always added to the "Variant" overlay and will therefore carry the highest possible priority among all directories for the source type.

Summary

Nested types

public interface SourceDirectories.Flat extends SourceDirectories

Represents all the source folders for a source type in the variant.

Represent a collection of directories that have overlay properties to each other.

Public methods

abstract void
<TASK extends Task> addGeneratedSourceDirectory(
    @NonNull TaskProvider<@NonNull TASK> taskProvider,
    @NonNull Function1<@NonNull TASK, @NonNull DirectoryProperty> wiredWith
)

Add the output of a custom task to the list of source directories.

abstract void

Add a source directory with sources already present to the variant.

Inherited methods

From org.gradle.api.Named
abstract @NonNull String

Public methods

addGeneratedSourceDirectory

abstract void <TASK extends Task> addGeneratedSourceDirectory(
    @NonNull TaskProvider<@NonNull TASK> taskProvider,
    @NonNull Function1<@NonNull TASK, @NonNull DirectoryProperty> wiredWith
)

Add the output of a custom task to the list of source directories.

The Directory is the output of a Task TASK that has been registered using the Gradle's Task manager.

The Directory is added last to the variant's list of source directories. In case there is merging for the source type, the Directory will have the highest priority.

Parameters
@NonNull TaskProvider<@NonNull TASK> taskProvider

the TaskProvider returned by Gradle's Task manager when registering the Task of type TASK.

@NonNull Function1<@NonNull TASK, @NonNull DirectoryProperty> wiredWith

the method reference returning the TASK task's output to use as a source directory. The generated source directory location is automatically determined by the Android Gradle Plugin

addStaticSourceDirectory

abstract void addStaticSourceDirectory(@NonNull String srcDir)

Add a source directory with sources already present to the variant.

The directory will be added last in the list of source folders for the variant. In case there is merging for the source type, srcDir will be the folder with the highest priority.

Do not use addStaticSourceDirectory to add sources that are generated by a task, instead use addGeneratedSourceDirectory

Parameters
@NonNull String srcDir

the source directory path, that will be resolved using the Directory.dir API relative to the Gradle project directory.