com.android.builder
Class VariantConfiguration

java.lang.Object
  extended by com.android.builder.VariantConfiguration
All Implemented Interfaces:
TestData

public class VariantConfiguration
extends java.lang.Object
implements TestData

A Variant configuration.


Nested Class Summary
static class VariantConfiguration.Type
           
 
Constructor Summary
VariantConfiguration(DefaultProductFlavor defaultConfig, com.android.builder.model.SourceProvider defaultSourceProvider, DefaultBuildType buildType, com.android.builder.model.SourceProvider buildTypeSourceProvider)
          Creates the configuration with the base source sets.
VariantConfiguration(DefaultProductFlavor defaultConfig, com.android.builder.model.SourceProvider defaultSourceProvider, DefaultBuildType buildType, com.android.builder.model.SourceProvider buildTypeSourceProvider, VariantConfiguration.Type type)
          Creates the configuration with the base source sets for a given VariantConfiguration.Type.
VariantConfiguration(DefaultProductFlavor defaultConfig, com.android.builder.model.SourceProvider defaultSourceProvider, DefaultBuildType buildType, com.android.builder.model.SourceProvider buildTypeSourceProvider, VariantConfiguration.Type type, VariantConfiguration testedConfig)
          Creates the configuration with the base source sets, and an optional tested variant.
 
Method Summary
 VariantConfiguration addProductFlavor(DefaultProductFlavor productFlavor, com.android.builder.model.SourceProvider sourceProvider, java.lang.String dimensionName)
          Add a new configured ProductFlavor.
 java.util.List<java.io.File> getAidlImports()
          Returns all the aidl import folder that are outside of the current project.
 java.util.List<java.io.File> getAidlSourceList()
           
 java.util.List<LibraryDependency> getAllLibraries()
          Returns all the library dependencies, direct and transitive.
 java.util.List<com.android.ide.common.res2.AssetSet> getAssetSets(boolean includeDependencies)
          Returns the dynamic list of AssetSet based on the configuration, its dependencies, as well as tested config if applicable (test of a library).
 java.lang.String getBaseName()
          Returns the full, unique name of the variant, including BuildType, flavors and test, dash separated.
 java.util.List<java.lang.Object> getBuildConfigItems()
          Returns a list of items for the BuildConfig class.
 DefaultBuildType getBuildType()
           
 com.android.builder.model.SourceProvider getBuildTypeSourceSet()
          The SourceProvider for the BuildType.
 java.util.Set<java.io.File> getCompileClasspath()
          Returns the compile classpath for this config.
 java.util.List<java.lang.Object> getConsumerProguardFiles()
           
 DefaultProductFlavor getDefaultConfig()
           
 com.android.builder.model.SourceProvider getDefaultSourceSet()
           
 java.util.List<LibraryDependency> getDirectLibraries()
          Returns the direct library dependencies
 java.lang.String getDirName()
          Returns a unique directory name (can include multiple folders) for the variant, based on build type, flavor and test.
 java.util.List<DefaultProductFlavor> getFlavorConfigs()
           
 java.lang.String getFlavorName()
          Returns the flavor name of the variant, including all flavors in camel case (starting with a lower case).
 java.util.List<java.lang.String> getFlavorNamesWithDimensionNames()
          Return the names of the applied flavors.
 java.util.List<com.android.builder.model.SourceProvider> getFlavorSourceProviders()
          Returns the list of SourceProviders for the flavors.
 java.lang.String getFullName()
          Returns the full, unique name of the variant in camel case (starting with a lower case), including BuildType, Flavors and Test (if applicable).
 java.lang.Boolean getFunctionalTest()
          Returns functionalTest value to use to test this variant, or if the variant is a test, the one to use to test the tested variant.
 java.lang.Boolean getHandleProfiling()
          Returns handleProfiling value to use to test this variant, or if the variant is a test, the one to use to test the tested variant.
 java.lang.String getInstrumentationRunner()
          Returns the instrumentationRunner to use to test this variant, or if the variant is a test, the one to use to test the tested variant.
 java.util.Collection<JarDependency> getJars()
          Returns the list of jar dependencies
 java.util.List<java.io.File> getJniSourceList()
           
 java.util.List<java.io.File> getLibraryJniFolders()
           
 java.io.File getMainManifest()
           
 java.util.List<java.io.File> getManifestOverlays()
           
static java.lang.String getManifestPackage(java.io.File manifestFile)
          Parses the manifest file and return the package name.
 DefaultProductFlavor getMergedFlavor()
           
 int getMinSdkVersion()
          Return the minSdkVersion for this variant.
 com.android.builder.model.SourceProvider getMultiFlavorSourceProvider()
           
 com.android.builder.model.NdkConfig getNdkConfig()
           
 java.lang.String getOriginalPackageName()
          Returns the original package name before any overrides from flavors.
 java.util.List<java.io.File> getPackagedJars()
          Returns the list of packaged jars for this config.
 java.lang.String getPackageFromManifest()
          Reads the package name from the manifest.
 java.lang.String getPackageName()
          Returns the package name for this variant.
 java.lang.String getPackageOverride()
          Returns the package override values coming from the Product Flavor and/or the Build Type.
 java.util.List<java.lang.Object> getProguardFiles(boolean includeLibraries)
           
 java.util.List<java.io.File> getRenderscriptImports()
          Returns all the renderscript import folder that are outside of the current project.
 java.util.List<java.io.File> getRenderscriptSourceList()
          Returns all the renderscript source folder from the main config, the flavors and the build type.
 java.util.List<com.android.ide.common.res2.ResourceSet> getResourceSets(java.io.File generatedResFolder, boolean includeDependencies)
          Returns the dynamic list of ResourceSet based on the configuration, its dependencies, as well as tested config if applicable (test of a library).
 com.android.builder.model.SigningConfig getSigningConfig()
           
 java.util.Set<java.lang.String> getSupportedAbis()
          List of supported ABIs.
 int getTargetSdkVersion()
          Return the targetSdkVersion for this variant.
 VariantConfiguration getTestedConfig()
           
 java.lang.String getTestedPackageName()
          Returns the tested package name.
 VariantConfiguration.Type getType()
           
 com.android.builder.model.SourceProvider getVariantSourceProvider()
          Returns the variant specific source provider
 int getVersionCode()
          Returns the version code for this variant.
 int getVersionCodeFromManifest()
          Reads the version code from the manifest.
 java.lang.String getVersionName()
          Returns the version name for this variant.
 java.lang.String getVersionNameFromManifest()
          Reads the version name from the manifest.
 boolean hasFlavors()
           
 boolean hasLibraries()
           
 boolean isSigningReady()
           
 VariantConfiguration setDependencies(DependencyContainer container)
          Sets the dependencies
 VariantConfiguration setMultiFlavorSourceProvider(com.android.builder.model.SourceProvider sourceProvider)
          Sets the variant-specific source provider.
 VariantConfiguration setOutput(LibraryDependency output)
          Sets the output of this variant.
 VariantConfiguration setVariantSourceProvider(com.android.builder.model.SourceProvider sourceProvider)
          Sets the variant-specific source provider.
protected  void validate()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariantConfiguration

public VariantConfiguration(@NonNull
                            DefaultProductFlavor defaultConfig,
                            @NonNull
                            com.android.builder.model.SourceProvider defaultSourceProvider,
                            @NonNull
                            DefaultBuildType buildType,
                            @Nullable
                            com.android.builder.model.SourceProvider buildTypeSourceProvider)
Creates the configuration with the base source sets. This creates a config with a VariantConfiguration.Type.DEFAULT type.

Parameters:
defaultConfig - the default configuration. Required.
defaultSourceProvider - the default source provider. Required
buildType - the build type for this variant. Required.
buildTypeSourceProvider - the source provider for the build type. Required.

VariantConfiguration

public VariantConfiguration(@NonNull
                            DefaultProductFlavor defaultConfig,
                            @NonNull
                            com.android.builder.model.SourceProvider defaultSourceProvider,
                            @NonNull
                            DefaultBuildType buildType,
                            @Nullable
                            com.android.builder.model.SourceProvider buildTypeSourceProvider,
                            @NonNull
                            VariantConfiguration.Type type)
Creates the configuration with the base source sets for a given VariantConfiguration.Type.

Parameters:
defaultConfig - the default configuration. Required.
defaultSourceProvider - the default source provider. Required
buildType - the build type for this variant. Required.
buildTypeSourceProvider - the source provider for the build type.
type - the type of the project.

VariantConfiguration

public VariantConfiguration(@NonNull
                            DefaultProductFlavor defaultConfig,
                            @NonNull
                            com.android.builder.model.SourceProvider defaultSourceProvider,
                            @NonNull
                            DefaultBuildType buildType,
                            @Nullable
                            com.android.builder.model.SourceProvider buildTypeSourceProvider,
                            @NonNull
                            VariantConfiguration.Type type,
                            @Nullable
                            VariantConfiguration testedConfig)
Creates the configuration with the base source sets, and an optional tested variant.

Parameters:
defaultConfig - the default configuration. Required.
defaultSourceProvider - the default source provider. Required
buildType - the build type for this variant. Required.
buildTypeSourceProvider - the source provider for the build type.
type - the type of the project.
testedConfig - the reference to the tested project. Required if type is Type.TEST
Method Detail

getManifestPackage

@Nullable
public static java.lang.String getManifestPackage(@NonNull
                                                           java.io.File manifestFile)
Parses the manifest file and return the package name.

Parameters:
manifestFile - the manifest file
Returns:
the package name found or null

getFullName

@NonNull
public java.lang.String getFullName()
Returns the full, unique name of the variant in camel case (starting with a lower case), including BuildType, Flavors and Test (if applicable).

Returns:
the name of the variant

getFlavorName

@NonNull
public java.lang.String getFlavorName()
Returns the flavor name of the variant, including all flavors in camel case (starting with a lower case). If the variant has no flavor, then an empty string is returned.

Returns:
the flavor name or an empty string.

getBaseName

@NonNull
public java.lang.String getBaseName()
Returns the full, unique name of the variant, including BuildType, flavors and test, dash separated. (similar to full name but with dashes)

Returns:
the name of the variant

getDirName

@NonNull
public java.lang.String getDirName()
Returns a unique directory name (can include multiple folders) for the variant, based on build type, flavor and test. This always uses forward slashes ('/') as separator on all platform.

Returns:
the directory name for the variant

getFlavorNamesWithDimensionNames

@NonNull
public java.util.List<java.lang.String> getFlavorNamesWithDimensionNames()
Return the names of the applied flavors. The list contains the dimension names as well.

Returns:
the list, possibly empty if there are no flavors.

addProductFlavor

@NonNull
public VariantConfiguration addProductFlavor(@NonNull
                                                     DefaultProductFlavor productFlavor,
                                                     @NonNull
                                                     com.android.builder.model.SourceProvider sourceProvider,
                                                     @NonNull
                                                     java.lang.String dimensionName)
Add a new configured ProductFlavor. If multiple flavors are added, the priority follows the order they are added when it comes to resolving Android resources overlays (ie earlier added flavors supersedes latter added ones).

Parameters:
productFlavor - the configured product flavor
sourceProvider - the source provider for the product flavor
dimensionName - the name of the dimension associated with the flavor
Returns:
the config object

setVariantSourceProvider

public VariantConfiguration setVariantSourceProvider(@Nullable
                                                     com.android.builder.model.SourceProvider sourceProvider)
Sets the variant-specific source provider.

Parameters:
sourceProvider - the source provider for the product flavor
Returns:
the config object

setMultiFlavorSourceProvider

public VariantConfiguration setMultiFlavorSourceProvider(@Nullable
                                                         com.android.builder.model.SourceProvider sourceProvider)
Sets the variant-specific source provider.

Parameters:
sourceProvider - the source provider for the product flavor
Returns:
the config object

getVariantSourceProvider

@Nullable
public com.android.builder.model.SourceProvider getVariantSourceProvider()
Returns the variant specific source provider

Returns:
the source provider or null if none has been provided.

getMultiFlavorSourceProvider

@Nullable
public com.android.builder.model.SourceProvider getMultiFlavorSourceProvider()

setDependencies

@NonNull
public VariantConfiguration setDependencies(@NonNull
                                                    DependencyContainer container)
Sets the dependencies

Parameters:
container - a DependencyContainer.
Returns:
the config object

getJars

@NonNull
public java.util.Collection<JarDependency> getJars()
Returns the list of jar dependencies

Returns:
a non null collection of Jar dependencies.

setOutput

@NonNull
public VariantConfiguration setOutput(LibraryDependency output)
Sets the output of this variant. This is required when the variant is a library so that the variant that tests this library can properly include the tested library in its own package.

Parameters:
output - the output of the library as an LibraryDependency that will provides the location of all the created items.
Returns:
the config object

getDefaultConfig

@NonNull
public DefaultProductFlavor getDefaultConfig()

getDefaultSourceSet

@NonNull
public com.android.builder.model.SourceProvider getDefaultSourceSet()

getMergedFlavor

@NonNull
public DefaultProductFlavor getMergedFlavor()

getBuildType

@NonNull
public DefaultBuildType getBuildType()

getBuildTypeSourceSet

@Nullable
public com.android.builder.model.SourceProvider getBuildTypeSourceSet()
The SourceProvider for the BuildType. Can be null.


hasFlavors

public boolean hasFlavors()

getFlavorConfigs

@NonNull
public java.util.List<DefaultProductFlavor> getFlavorConfigs()

getFlavorSourceProviders

@NonNull
public java.util.List<com.android.builder.model.SourceProvider> getFlavorSourceProviders()
Returns the list of SourceProviders for the flavors. The list is ordered from higher priority to lower priority.

Returns:
the list of Source Providers for the flavors. Never null.

hasLibraries

public boolean hasLibraries()

getDirectLibraries

@NonNull
public java.util.List<LibraryDependency> getDirectLibraries()
Returns the direct library dependencies


getAllLibraries

@NonNull
public java.util.List<LibraryDependency> getAllLibraries()
Returns all the library dependencies, direct and transitive.


getType

@NonNull
public VariantConfiguration.Type getType()

getTestedConfig

@Nullable
public VariantConfiguration getTestedConfig()

getOriginalPackageName

@Nullable
public java.lang.String getOriginalPackageName()
Returns the original package name before any overrides from flavors. If the variant is a test variant, then the package name is the one coming from the configuration of the tested variant, and this call is similar to #getPackageName()

Returns:
the package name

getPackageName

@NonNull
public java.lang.String getPackageName()
Returns the package name for this variant. This could be coming from the manifest or could be overridden through the product flavors and/or the build Type.

Specified by:
getPackageName in interface TestData
Returns:
the package

getTestedPackageName

@Nullable
public java.lang.String getTestedPackageName()
Description copied from interface: TestData
Returns the tested package name. This can be empty if the test package is self-contained.

Specified by:
getTestedPackageName in interface TestData
Returns:
the package name or null.

getPackageOverride

@Nullable
public java.lang.String getPackageOverride()
Returns the package override values coming from the Product Flavor and/or the Build Type. If the package is not overridden then this returns null.

Returns:
the package override or null

getVersionName

@Nullable
public java.lang.String getVersionName()
Returns the version name for this variant. This could be coming from the manifest or could be overridden through the product flavors, and can have a suffix specified by the build type.

Returns:
the version name

getVersionCode

public int getVersionCode()
Returns the version code for this variant. This could be coming from the manifest or could be overridden through the product flavors, and can have a suffix specified by the build type.

Returns:
the version code or -1 if there was non defined.

getInstrumentationRunner

@NonNull
public java.lang.String getInstrumentationRunner()
Returns the instrumentationRunner to use to test this variant, or if the variant is a test, the one to use to test the tested variant.

Specified by:
getInstrumentationRunner in interface TestData
Returns:
the instrumentation test runner name

getHandleProfiling

@NonNull
public java.lang.Boolean getHandleProfiling()
Returns handleProfiling value to use to test this variant, or if the variant is a test, the one to use to test the tested variant.

Specified by:
getHandleProfiling in interface TestData
Returns:
the handleProfiling value

getFunctionalTest

@NonNull
public java.lang.Boolean getFunctionalTest()
Returns functionalTest value to use to test this variant, or if the variant is a test, the one to use to test the tested variant.

Specified by:
getFunctionalTest in interface TestData
Returns:
the functionalTest value

getPackageFromManifest

@Nullable
public java.lang.String getPackageFromManifest()
Reads the package name from the manifest. This is unmodified by the build type.


getVersionNameFromManifest

@Nullable
public java.lang.String getVersionNameFromManifest()
Reads the version name from the manifest.


getVersionCodeFromManifest

public int getVersionCodeFromManifest()
Reads the version code from the manifest.


getMinSdkVersion

public int getMinSdkVersion()
Return the minSdkVersion for this variant. This uses both the value from the manifest (if present), and the override coming from the flavor(s) (if present).

Specified by:
getMinSdkVersion in interface TestData
Returns:
the minSdkVersion

getTargetSdkVersion

public int getTargetSdkVersion()
Return the targetSdkVersion for this variant. This uses both the value from the manifest (if present), and the override coming from the flavor(s) (if present).

Returns:
the targetSdkVersion

getMainManifest

@Nullable
public java.io.File getMainManifest()

getManifestOverlays

@NonNull
public java.util.List<java.io.File> getManifestOverlays()

getResourceSets

@NonNull
public java.util.List<com.android.ide.common.res2.ResourceSet> getResourceSets(@Nullable
                                                                                       java.io.File generatedResFolder,
                                                                                       boolean includeDependencies)
Returns the dynamic list of ResourceSet based on the configuration, its dependencies, as well as tested config if applicable (test of a library). The list is ordered in ascending order of importance, meaning the first set is meant to be overridden by the 2nd one and so on. This is meant to facilitate usage of the list in a ResourceMerger.

Parameters:
generatedResFolder - the generated res folder typically the output of the renderscript compilation
includeDependencies - whether to include in the result the resources of the dependencies
Returns:
a list ResourceSet.

getAssetSets

@NonNull
public java.util.List<com.android.ide.common.res2.AssetSet> getAssetSets(boolean includeDependencies)
Returns the dynamic list of AssetSet based on the configuration, its dependencies, as well as tested config if applicable (test of a library). The list is ordered in ascending order of importance, meaning the first set is meant to be overridden by the 2nd one and so on. This is meant to facilitate usage of the list in a AssetMerger.

Returns:
a list ResourceSet.

getLibraryJniFolders

@NonNull
public java.util.List<java.io.File> getLibraryJniFolders()

getRenderscriptImports

@NonNull
public java.util.List<java.io.File> getRenderscriptImports()
Returns all the renderscript import folder that are outside of the current project.


getRenderscriptSourceList

@NonNull
public java.util.List<java.io.File> getRenderscriptSourceList()
Returns all the renderscript source folder from the main config, the flavors and the build type.

Returns:
a list of folders.

getAidlImports

@NonNull
public java.util.List<java.io.File> getAidlImports()
Returns all the aidl import folder that are outside of the current project.


getAidlSourceList

@NonNull
public java.util.List<java.io.File> getAidlSourceList()

getJniSourceList

@NonNull
public java.util.List<java.io.File> getJniSourceList()

getCompileClasspath

@NonNull
public java.util.Set<java.io.File> getCompileClasspath()
Returns the compile classpath for this config. If the config tests a library, this will include the classpath of the tested config

Returns:
a non null, but possibly empty set.

getPackagedJars

@NonNull
public java.util.List<java.io.File> getPackagedJars()
Returns the list of packaged jars for this config. If the config tests a library, this will include the jars of the tested config

Returns:
a non null, but possibly empty list.

getBuildConfigItems

@NonNull
public java.util.List<java.lang.Object> getBuildConfigItems()
Returns a list of items for the BuildConfig class. Items can be either fields (instance of ClassField) or comments (instance of String).

Returns:
a list of items.

getSigningConfig

@Nullable
public com.android.builder.model.SigningConfig getSigningConfig()

isSigningReady

public boolean isSigningReady()

getProguardFiles

@NonNull
public java.util.List<java.lang.Object> getProguardFiles(boolean includeLibraries)

getConsumerProguardFiles

@NonNull
public java.util.List<java.lang.Object> getConsumerProguardFiles()

validate

protected void validate()

getNdkConfig

@NonNull
public com.android.builder.model.NdkConfig getNdkConfig()

getSupportedAbis

@Nullable
public java.util.Set<java.lang.String> getSupportedAbis()
Description copied from interface: TestData
List of supported ABIs. Null means all.

Specified by:
getSupportedAbis in interface TestData
Returns:
a list of abi or null for all