This is the main builder class. It is given all the data to process the build (such as DefaultProductFlavors, DefaultBuildType and dependencies) and use them when doing specific build steps. To use: create a builder with AndroidBuilder(String, String, ILogger, boolean) then build steps can be done with mergeManifests(java.io.File, java.util.List, java.util.List, String, int, String, String, String, Integer, String, com.android.manifmerger.ManifestMerger2.MergeType, java.util.Map) processTestManifest(String, String, String, String, String, Boolean, Boolean, java.io.File, java.util.List, java.io.File, java.io.File) processResources(java.io.File, java.io.File, java.io.File, java.util.List, String, String, String, String, String, com.android.builder.core.VariantConfiguration.Type, boolean, com.android.builder.model.AaptOptions, java.util.Collection, boolean, java.util.Collection) compileAllAidlFiles(java.util.List, java.io.File, java.io.File, java.util.List, com.android.builder.compiling.DependencyFileProcessor) convertByteCode(Iterable, Iterable, java.io.File, boolean, java.io.File, DexOptions, java.util.List, java.io.File, boolean) packageApk(String, java.io.File, java.util.Collection, java.util.Collection, String, java.util.Collection, java.util.Set, boolean, com.android.builder.model.SigningConfig, com.android.builder.model.PackagingOptions, String) Java compilation is not handled but the builder provides the bootclasspath with getBootClasspath().
Constructor and description |
---|
AndroidBuilder
(String projectId, String createdBy, com.android.utils.ILogger logger, boolean verboseExec) Creates an AndroidBuilder. |
Type | Name and description |
---|---|
void |
compileAidlFile(File sourceFolder, File aidlFile, File sourceOutputDir, File parcelableOutputDir, List<File> importFolders, DependencyFileProcessor dependencyFileProcessor) Compiles the given aidl file. |
void |
compileAllAidlFiles(List<File> sourceFolders, File sourceOutputDir, File parcelableOutputDir, List<File> importFolders, DependencyFileProcessor dependencyFileProcessor) Compiles all the aidl files found in the given source folders. |
void |
compileAllRenderscriptFiles(List<File> sourceFolders, List<File> importFolders, File sourceOutputDir, File resOutputDir, File objOutputDir, File libOutputDir, int targetApi, boolean debugBuild, int optimLevel, boolean ndkMode, boolean supportMode, Set<String> abiFilters) Compiles all the renderscript files found in the given source folders. |
void |
convertByteCode(Collection<File> inputs, Collection<File> preDexedLibraries, File outDexFolder, boolean multidex, boolean multidexLegacy, File mainDexList, DexOptions dexOptions, List<String> additionalParameters, File tmpFolder, boolean incremental, boolean optimize) Converts the bytecode to Dalvik format |
void |
convertLibraryToJack(File inputFile, File outFile, DexOptions dexOptions) Converts the bytecode of a library to the jack format |
static List<File> |
convertLibraryToJack(File inputFile, File outFile, DexOptions dexOptions, com.android.sdklib.BuildToolInfo buildToolInfo, boolean verbose, com.android.ide.common.internal.CommandLineRunner commandLineRunner) |
static com.android.builder.model.ClassField |
createClassField(String type, String name, String value) |
void |
generateApkData(File apkFile, File outResFolder, String mainPkgName, String resName) |
void |
generateApkDataEntryInManifest(int minSdkVersion, int targetSdkVersion, File manifestFile) |
com.android.ide.common.internal.PngCruncher |
getAaptCruncher() Returns an com.android.ide.common.internal.PngCruncher using aapt underneath |
List<File> |
getBootClasspath() Helper method to get the boot classpath to be used during compilation. |
List<String> |
getBootClasspathAsStrings() Helper method to get the boot classpath to be used during compilation. |
com.android.ide.common.internal.CommandLineRunner |
getCommandLineRunner() |
Set<File> |
getCompileClasspath(VariantConfiguration<?, ?, ?> variantConfiguration) Returns the compile classpath for this config. |
File |
getDxJar() |
List<File> |
getLeafFolders(String extension, List<File>... importFolders) Computes and returns the leaf folders based on a given file extension. |
com.android.utils.ILogger |
getLogger() |
Set<File> |
getPackagedJars(VariantConfiguration<?, ?, ?> variantConfiguration) Returns the list of packaged jars for this config. |
File |
getRenderScriptSupportJar() Returns the jar file for the renderscript mode. |
SdkInfo |
getSdkInfo() Returns the SdkInfo, if set. |
File |
getSupportNativeLibFolder() Returns the native lib folder for the renderscript mode. |
com.android.sdklib.IAndroidTarget |
getTarget() Returns the compilation target, if set. |
String |
getTargetCodename() |
TargetInfo |
getTargetInfo() Returns the TargetInfo, if set. |
boolean |
isPreviewTarget() Returns whether the compilation target is a preview. |
void |
mergeManifests(File mainManifest, List<File> manifestOverlays, List<? extends ManifestDependency> libraries, String packageOverride, int versionCode, String versionName, String minSdkVersion, String targetSdkVersion, Integer maxSdkVersion, String outManifestLocation, com.android.manifmerger.ManifestMerger2$MergeType mergeType, Map<String, String> placeHolders, File reportFile) Invoke the Manifest Merger version 2. |
void |
packageApk(String androidResPkgLocation, File dexFolder, Collection<File> dexedLibraries, Collection<File> packagedJars, String javaResourcesLocation, Collection<File> jniLibsFolders, Set<String> abiFilters, boolean jniDebugBuild, com.android.builder.model.SigningConfig signingConfig, com.android.builder.model.PackagingOptions packagingOptions, String outApkLocation) Packages the apk. |
void |
preDexLibrary(File inputFile, File outFile, boolean multiDex, DexOptions dexOptions) Converts the bytecode to Dalvik format |
static List<File> |
preDexLibrary(File inputFile, File outFile, boolean multiDex, DexOptions dexOptions, com.android.sdklib.BuildToolInfo buildToolInfo, boolean verbose, com.android.ide.common.internal.CommandLineRunner commandLineRunner) Converts the bytecode to Dalvik format |
void |
processResources(AaptPackageCommandBuilder aaptCommand, boolean enforceUniquePackageName) Process the resources and generate R.java and/or the packaged resources. |
void |
processTestManifest(String testApplicationId, String minSdkVersion, String targetSdkVersion, String testedApplicationId, String instrumentationRunner, Boolean handleProfiling, Boolean functionalTest, File testManifestFile, List<? extends ManifestDependency> libraries, File outManifest, File tmpDir) Creates the manifest for a test variant |
void |
setTargetInfo(SdkInfo sdkInfo, TargetInfo targetInfo) Sets the SdkInfo and the targetInfo on the builder. |
void |
signApk(File in, com.android.builder.model.SigningConfig signingConfig, File out) Signs a single jar file using the passed com.android.builder.model.SigningConfig. |
Creates an AndroidBuilder.
verboseExec is needed on top of the ILogger due to remote exec tools not being able to output info and verbose messages separately.createdBy
- the createdBy String for the apk manifest.logger
- the LoggerverboseExec
- whether external tools are launched in verbose modeCompiles the given aidl file.
aidlFile
- the AIDL file to compilesourceOutputDir
- the output dir in which to generate the source codeimportFolders
- all the import folders, including the source folders.dependencyFileProcessor
- the dependencyFileProcessor to record the dependencies
of the compilation.Compiles all the aidl files found in the given source folders.
sourceFolders
- all the source folders to find files to compilesourceOutputDir
- the output dir in which to generate the source codeimportFolders
- import foldersdependencyFileProcessor
- the dependencyFileProcessor to record the dependencies
of the compilation.Compiles all the renderscript files found in the given source folders. Right now this is the only way to compile them as the renderscript compiler requires all renderscript files to be passed for all compilation. Therefore whenever a renderscript file or header changes, all must be recompiled.
sourceFolders
- all the source folders to find files to compileimportFolders
- all the import folders.sourceOutputDir
- the output dir in which to generate the source coderesOutputDir
- the output dir in which to generate the bitcode filetargetApi
- the target apidebugBuild
- whether the build is debugoptimLevel
- the optimization levelsupportMode
- support mode flag to generate .so files.abiFilters
- ABI filters in case of support modeConverts the bytecode to Dalvik format
inputs
- the input filespreDexedLibraries
- the list of pre-dexed librariesoutDexFolder
- the location of the output folderdexOptions
- dex optionsadditionalParameters
- list of additional parameters to give to dxincremental
- true if it should attempt incremental dex if applicableConverts the bytecode of a library to the jack format
inputFile
- the input fileoutFile
- the location of the output classes.dex filedexOptions
- dex optionsReturns an com.android.ide.common.internal.PngCruncher using aapt underneath
Helper method to get the boot classpath to be used during compilation.
Helper method to get the boot classpath to be used during compilation.
Returns the compile classpath for this config. If the config tests a library, this will include the classpath of the tested config. If the SDK was loaded, this may include the renderscript support jar.
Computes and returns the leaf folders based on a given file extension. This looks through all the given root import folders, and recursively search for leaf folders containing files matching the given extensions. All the leaf folders are gathered and returned in the list.
extension
- the extension to search for.importFolders
- an array of list of root folders.Returns the list of packaged jars for this config. If the config tests a library, this will include the jars of the tested config If the SDK was loaded, this may include the renderscript support jar.
Returns the jar file for the renderscript mode. This may return null if the SDK has not been loaded yet.
Returns the SdkInfo, if set.
Returns the native lib folder for the renderscript mode. This may return null if the SDK has not been loaded yet.
Returns the compilation target, if set.
Returns the TargetInfo, if set.
Returns whether the compilation target is a preview.
Invoke the Manifest Merger version 2.
Packages the apk.
androidResPkgLocation
- the location of the packaged resource filedexFolder
- the folder with the dex file.dexedLibraries
- optional collection of additional dex files to put in the apk.packagedJars
- the jars that are packaged (libraries + jar dependencies)javaResourcesLocation
- the processed Java resource folderjniLibsFolders
- the folders containing jni shared librariesabiFilters
- optional ABI filterjniDebugBuild
- whether the app should include jni debug datasigningConfig
- the signing configurationpackagingOptions
- the packaging optionsoutApkLocation
- location of the APK.Converts the bytecode to Dalvik format
inputFile
- the input fileoutFile
- the output file or folder if multi-dex is enabled.multiDex
- whether multidex is enabled.dexOptions
- dex optionsConverts the bytecode to Dalvik format
inputFile
- the input fileoutFile
- the output file or folder if multi-dex is enabled.multiDex
- whether multidex is enabled.dexOptions
- the dex optionsbuildToolInfo
- the build tools infoverbose
- verbose flagcommandLineRunner
- the command line runnerProcess the resources and generate R.java and/or the packaged resources.
aaptCommand
- aapt command invocation parameters.enforceUniquePackageName
- if true method will fail if some libraries share the same
package nameCreates the manifest for a test variant
testApplicationId
- the application id of the test applicationminSdkVersion
- the minSdkVersion of the test applicationtargetSdkVersion
- the targetSdkVersion of the test applicationtestedApplicationId
- the application id of the tested applicationinstrumentationRunner
- the name of the instrumentation runnerhandleProfiling
- whether or not the Instrumentation object will turn profiling on and offfunctionalTest
- whether or not the Instrumentation class should run as a functional testtestManifestFile
- optionally user provided AndroidManifest.xml for testing applicationlibraries
- the library dependency graphoutManifest
- the output location for the merged manifestSets the SdkInfo and the targetInfo on the builder. This is required to actually build (some of the steps).
sdkInfo
- the SdkInfotargetInfo
- the TargetInfoSigns a single jar file using the passed com.android.builder.model.SigningConfig.
in
- the jar file to sign.signingConfig
- the signing configurationout
- the file path for the signed jar.