com.android.builder.core.VariantConfiguration Java Examples

The following examples show how to use com.android.builder.core.VariantConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransformManager.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static List<TransformTask> findTransformTaskByTransformType(VariantContext appVariantContext, Class<?>
    transformClass) {
    List<TransformTask> transformTasksList = Lists.newArrayList();
    VariantConfiguration config = appVariantContext.getVariantConfiguration();
    TaskCollection<TransformTask> transformTasks = appVariantContext.getProject().getTasks().withType(
        TransformTask.class);
    SortedMap<String, TransformTask> transformTaskSortedMap = transformTasks.getAsMap();
    String variantName = config.getFullName();
    for (String taskName : transformTaskSortedMap.keySet()) {
        TransformTask transformTask = transformTaskSortedMap.get(taskName);
        if (variantName == transformTask.getVariantName()) {
            if (transformTask.getTransform().getClass() == transformClass) {
                transformTasksList.add(transformTask);
            }
        }
    }
    return transformTasksList;
}
 
Example #2
Source File: MergeAwbAssets.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
        public void execute(@NonNull MergeAwbAssets mergeAssetsTask) {
            BaseVariantData variantData = scope.getVariantData();
            VariantConfiguration variantConfig = variantData.getVariantConfiguration();

            mergeAssetsTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
            mergeAssetsTask.setVariantName(variantConfig.getFullName());
            mergeAssetsTask.setIncrementalFolder(scope.getIncrementalDir(getName()));
//            final Project project = scope.getGlobalScope().getProject();
//            final Function<SourceProvider, Collection<File>> assetDirFunction =
//                    SourceProvider::getJniLibsDirectories;
//            mergeAssetsTask.assetSetSupplier =
//                    () -> variantConfig.getSourceFilesAsAssetSets(assetDirFunction);
//            mergeAssetsTask.sourceFolderInputs =
//                    TaskInputHelper.bypassFileSupplier(
//                            () -> variantConfig.getSourceFiles(assetDirFunction));

            mergeAssetsTask.assetSetSupplier = () -> ImmutableList.of();
            mergeAssetsTask.sourceFolderInputs = ()-> ImmutableList.of();
            mergeAssetsTask.awbBundle = awbBundle;
            if (!variantConfig.getType().equals(VariantType.LIBRARY)) {
                mergeAssetsTask.libraries = awbBundle.getAndroidLibraries();
            }
            mergeAssetsTask.setOutputDir(variantContext.getAwbMergeNativeLibsOutputDir(awbBundle));
        }
 
Example #3
Source File: MergeAwbAssets.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
        public void execute(@NonNull MergeAwbAssets mergeAssetsTask) {
            BaseVariantData variantData = scope.getVariantData();
            VariantConfiguration variantConfig = variantData.getVariantConfiguration();

            mergeAssetsTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
            mergeAssetsTask.setVariantName(variantConfig.getFullName());
            mergeAssetsTask.setIncrementalFolder(scope.getIncrementalDir(getName()));
            final Project project = scope.getGlobalScope().getProject();

            final Function<SourceProvider, Collection<File>> assetDirFunction =
                    SourceProvider::getShadersDirectories;
//            mergeAssetsTask.assetSetSupplier =
//                    () -> variantConfig.getSourceFilesAsAssetSets(assetDirFunction);
//            mergeAssetsTask.sourceFolderInputs =
//                    TaskInputHelper.bypassFileSupplier(
//                            () -> variantConfig.getSourceFiles(assetDirFunction));
            mergeAssetsTask.assetSetSupplier = () -> ImmutableList.of();
            mergeAssetsTask.sourceFolderInputs = () -> ImmutableList.of();

            mergeAssetsTask.awbBundle = awbBundle;
            if (!variantConfig.getType().equals(VariantType.LIBRARY)) {
                mergeAssetsTask.libraries = awbBundle.getAndroidLibraries();
            }
            mergeAssetsTask.setOutputDir(variantContext.getMergeShadersOutputDir(awbBundle));
        }
 
Example #4
Source File: PreDex.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(PreDex preDexTask) {
    ApkVariantData variantData = (ApkVariantData) scope.getVariantData();
    VariantConfiguration config = variantData.getVariantConfiguration();

    boolean isMultiDexEnabled = config.isMultiDexEnabled();

    variantData.preDexTask = preDexTask;
    preDexTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
    preDexTask.setVariantName(config.getFullName());
    preDexTask.dexOptions = scope.getGlobalScope().getExtension().getDexOptions();
    preDexTask.multiDex = isMultiDexEnabled;

    ConventionMappingHelper.map(preDexTask, "inputFiles", inputLibraries);
    ConventionMappingHelper.map(preDexTask, "outputFolder", new Callable<File>() {
        @Override
        public File call() throws Exception {
            return scope.getPreDexOutputDir();
        }
    });
}
 
Example #5
Source File: ProcessManifest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(@NonNull ProcessManifest processManifest) {
    final VariantConfiguration config = scope.getVariantConfiguration();
    final AndroidBuilder androidBuilder = scope.getGlobalScope().getAndroidBuilder();

    // get single output for now.
    final BaseVariantOutputData variantOutputData = scope.getVariantData().getOutputs().get(0);

    variantOutputData.manifestProcessorTask = processManifest;
    processManifest.setAndroidBuilder(androidBuilder);
    processManifest.setVariantName(config.getFullName());

    processManifest.setVariantConfiguration(config);

    final ProductFlavor mergedFlavor = config.getMergedFlavor();
    processManifest.setMinSdkVersion(getMinSdkVersion(androidBuilder, mergedFlavor, processManifest));
    processManifest.setTargetSdkVersion(getTargetSdkVersion(androidBuilder, mergedFlavor, processManifest));
    processManifest.setMaxSdkVersion(getMaxSdkVersion(androidBuilder, mergedFlavor));
    processManifest.setManifestOutputFile(variantOutputData.getScope().getManifestOutputFile());

    processManifest.setAaptFriendlyManifestOutputFile(
            new File(scope.getGlobalScope().getIntermediatesDir(),
                    TaskManager.DIR_BUNDLES + "/" + config.getDirName() + "/aapt/AndroidManifest.xml"));
}
 
Example #6
Source File: AndroidResourceProcessor.java    From bazel with Apache License 2.0 5 votes vote down vote up
void writeDependencyPackageRJavaFiles(
    List<DependencyAndroidData> dependencyData,
    String customPackageForR,
    Path androidManifest,
    Path sourceOut)
    throws IOException {
  List<SymbolFileProvider> libraries = new ArrayList<>();
  for (DependencyAndroidData dataDep : dependencyData) {
    SymbolFileProvider library = dataDep.asSymbolFileProvider();
    libraries.add(library);
  }
  String appPackageName = customPackageForR;
  if (appPackageName == null) {
    appPackageName = VariantConfiguration.getManifestPackage(androidManifest.toFile());
  }
  Multimap<String, ResourceSymbols> libSymbolMap = ArrayListMultimap.create();
  Path primaryRTxt = sourceOut != null ? sourceOut.resolve("R.txt") : null;
  if (primaryRTxt != null && !libraries.isEmpty()) {
    ResourceSymbols fullSymbolValues =
        loadResourceSymbolTable(libraries, appPackageName, primaryRTxt, libSymbolMap);
    // Loop on all the package name, merge all the symbols to write, and write.
    for (String packageName : libSymbolMap.keySet()) {
      Collection<ResourceSymbols> symbols = libSymbolMap.get(packageName);
      fullSymbolValues.writeSourcesTo(sourceOut, packageName, symbols, /* finalFields= */ true);
    }
  }
}
 
Example #7
Source File: MergeAwbAssets.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
        public void execute(@NonNull MergeAwbAssets mergeAssetsTask) {
            BaseVariantData variantData = scope.getVariantData();
            VariantConfiguration variantConfig = variantData.getVariantConfiguration();
            mergeAssetsTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
            mergeAssetsTask.setVariantName(variantConfig.getFullName());
            mergeAssetsTask.setIncrementalFolder(scope.getIncrementalDir(getName()));
            final Project project = scope.getGlobalScope().getProject();

            final Function<SourceProvider, Collection<File>> assetDirFunction =
                    SourceProvider::getAssetsDirectories;
//            mergeAssetsTask.assetSetSupplier =
//                    () -> variantConfig.getSourceFilesAsAssetSets(assetDirFunction);

            mergeAssetsTask.assetSetSupplier = ()-> ImmutableList.of();
            mergeAssetsTask.sourceFolderInputs = () -> ImmutableList.of();
//            mergeAssetsTask.sourceFolderInputs =
//                    TaskInputHelper.bypassFileSupplier(
//                            () -> variantConfig.getSourceFiles(assetDirFunction));

            mergeAssetsTask.shadersOutputDir = project.files(variantContext.getAwbShadersOutputDir(awbBundle));
            if (variantData.copyApkTask != null) {
                mergeAssetsTask.copyApk = project.files(variantData.copyApkTask.getDestinationDir());
            }

            AaptOptions options = scope.getGlobalScope().getExtension().getAaptOptions();
            if (options != null) {
                mergeAssetsTask.ignoreAssets = options.getIgnoreAssets();
            }

            if (!variantConfig.getType().equals(VariantType.LIBRARY)) {
                mergeAssetsTask.libraries = awbBundle.getAndroidLibraries();
            }

            mergeAssetsTask.awbBundle = awbBundle;
            mergeAssetsTask.variantContext = (AppVariantContext) this.variantContext;
            mergeAssetsTask.setOutputDir(outputDir);
        }
 
Example #8
Source File: ResourceLinker.java    From bazel with Apache License 2.0 5 votes vote down vote up
private Path extractPackages(CompiledResources compiled) throws IOException {
  Path packages = workingDirectory.resolve("packages");
  try (BufferedWriter writer = Files.newBufferedWriter(packages, StandardOpenOption.CREATE_NEW)) {
    for (CompiledResources resources : FluentIterable.from(include).append(compiled)) {
      writer.append(VariantConfiguration.getManifestPackage(resources.getManifest().toFile()));
      writer.newLine();
    }
  }
  return packages;
}
 
Example #9
Source File: AidlCompile.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(AidlCompile compileTask) {
    final VariantConfiguration<?, ?, ?> variantConfiguration = scope.getVariantConfiguration();

    scope.getVariantData().aidlCompileTask = compileTask;

    compileTask.setAndroidBuilder(scope.getGlobalScope().getAndroidBuilder());
    compileTask.setVariantName(scope.getVariantConfiguration().getFullName());
    compileTask.setIncrementalFolder(scope.getAidlIncrementalDir());

    ConventionMappingHelper.map(compileTask, "sourceDirs", new Callable<List<File>>() {
        @Override
        public List<File> call() throws Exception {
            return variantConfiguration.getAidlSourceList();
        }
    });
    ConventionMappingHelper.map(compileTask, "importDirs", new Callable<List<File>>() {
        @Override
        public List<File> call() throws Exception {
            return variantConfiguration.getAidlImports();
        }
    });

    ConventionMappingHelper.map(compileTask, "sourceOutputDir", new Callable<File>() {
        @Override
        public File call() throws Exception {
            return scope.getAidlSourceOutputDir();
        }
    });

    if (variantConfiguration.getType() == VariantType.LIBRARY) {
        compileTask.setAidlParcelableDir(scope.getAidlParcelableDir());
    }
}
 
Example #10
Source File: GradleVariantConfiguration.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public VariantConfiguration addProductFlavor(
        @NonNull CoreProductFlavor productFlavor,
        @NonNull SourceProvider sourceProvider,
        @NonNull String dimensionName) {
    checkNotNull(productFlavor);
    checkNotNull(sourceProvider);
    checkNotNull(dimensionName);
    super.addProductFlavor(productFlavor, sourceProvider, dimensionName);
    return this;
}
 
Example #11
Source File: VariantScope.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
public Set<File> getJniFolders() {
    VariantConfiguration config = getVariantConfiguration();
    ApkVariantData apkVariantData = (ApkVariantData) variantData;
    // for now only the project's compilation output.
    Set<File> set = Sets.newHashSet();
    set.addAll(config.getLibraryJniFolders());
    set.addAll(config.getJniLibsList());

    return set;
}
 
Example #12
Source File: ProcessManifest.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public void setVariantConfiguration(VariantConfiguration variantConfiguration) {
    this.variantConfiguration = variantConfiguration;
}
 
Example #13
Source File: ResourceSymbols.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public String call() throws Exception {
  return VariantConfiguration.getManifestPackage(manifest);
}
 
Example #14
Source File: TaskManager.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the split resources packages task if necessary. AAPT will produce split packages for
 * all --split provided parameters. These split packages should be signed and moved unchanged to
 * the APK build output directory.
 */
public void createSplitResourcesTasks(@NonNull VariantScope scope) {
    BaseVariantData<? extends BaseVariantOutputData> variantData = scope.getVariantData();

    checkState(variantData.getSplitHandlingPolicy().equals(
            BaseVariantData.SplitHandlingPolicy.RELEASE_21_AND_AFTER_POLICY),
            "Can only create split resources tasks for pure splits.");

    final VariantConfiguration config = variantData.getVariantConfiguration();
    Set<String> densityFilters = variantData.getFilters(OutputFile.FilterType.DENSITY);
    Set<String> abiFilters = variantData.getFilters(OutputFile.FilterType.ABI);
    Set<String> languageFilters = variantData.getFilters(OutputFile.FilterType.LANGUAGE);

    List<? extends BaseVariantOutputData> outputs = variantData.getOutputs();
    if (outputs.size() != 1) {
        throw new RuntimeException(
                "In release 21 and later, there can be only one main APK, " +
                        "found " + outputs.size());
    }

    final BaseVariantOutputData variantOutputData = outputs.get(0);
    VariantOutputScope variantOutputScope = variantOutputData.getScope();
    variantOutputData.packageSplitResourcesTask = project.getTasks().create(
            scope.getTaskName("package", "SplitResources"),
            PackageSplitRes.class);
    variantOutputData.packageSplitResourcesTask.setInputDirectory(
            variantOutputScope.getProcessResourcePackageOutputFile().getParentFile());
    variantOutputData.packageSplitResourcesTask.setDensitySplits(densityFilters);
    variantOutputData.packageSplitResourcesTask.setLanguageSplits(languageFilters);
    variantOutputData.packageSplitResourcesTask.setOutputBaseName(config.getBaseName());
    variantOutputData.packageSplitResourcesTask.setSigningConfig(config.getSigningConfig());
    variantOutputData.packageSplitResourcesTask.setOutputDirectory(new File(
            scope.getGlobalScope().getIntermediatesDir(), "splits/" + config.getDirName()));
    variantOutputData.packageSplitResourcesTask.setAndroidBuilder(androidBuilder);
    variantOutputData.packageSplitResourcesTask.setVariantName(config.getFullName());
    variantOutputData.packageSplitResourcesTask.dependsOn(
            variantOutputScope.getProcessResourcesTask().getName());

    SplitZipAlign zipAlign = project.getTasks().create(
            scope.getTaskName("zipAlign", "SplitPackages"),
            SplitZipAlign.class);
    zipAlign.setVariantName(config.getFullName());
    ConventionMappingHelper.map(zipAlign, "zipAlignExe", new Callable<File>() {
        @Override
        public File call() throws Exception {
            final TargetInfo info = androidBuilder.getTargetInfo();
            if (info == null) {
                return null;
            }
            String path = info.getBuildTools().getPath(ZIP_ALIGN);
            if (path == null) {
                return null;
            }
            return new File(path);
        }
    });

    zipAlign.setOutputDirectory(new File(scope.getGlobalScope().getBuildDir(), "outputs/apk"));
    ConventionMappingHelper.map(zipAlign, "densityOrLanguageInputFiles",
            new Callable<List<File>>() {
                @Override
                public List<File> call() {
                    return variantOutputData.packageSplitResourcesTask.getOutputFiles();
                }
            });
    zipAlign.setOutputBaseName(config.getBaseName());
    zipAlign.setAbiFilters(abiFilters);
    zipAlign.setLanguageFilters(languageFilters);
    zipAlign.setDensityFilters(densityFilters);
    File metadataDirectory = new File(zipAlign.getOutputDirectory().getParentFile(),
            "metadata");
    zipAlign.setApkMetadataFile(new File(metadataDirectory, config.getFullName() + ".mtd"));
    ((ApkVariantOutputData) variantOutputData).splitZipAlign = zipAlign;
    zipAlign.dependsOn(variantOutputData.packageSplitResourcesTask);
}
 
Example #15
Source File: FeatureLibManifestTask.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Internal
public VariantConfiguration getVariantConfiguration() {
    return variantConfiguration;
}
 
Example #16
Source File: ProcessManifest.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public VariantConfiguration getVariantConfiguration() {
    return variantConfiguration;
}
 
Example #17
Source File: FeatureLibManifestTask.java    From atlas with Apache License 2.0 4 votes vote down vote up
public void setVariantConfiguration(
        VariantConfiguration<CoreBuildType, CoreProductFlavor, CoreProductFlavor> variantConfiguration) {
    this.variantConfiguration = variantConfiguration;
}