use of com.android.ide.common.res2.MergingException in project bazel by bazelbuild.
the class AndroidResourceProcessingAction method main.
public static void main(String[] args) throws Exception {
final Stopwatch timer = Stopwatch.createStarted();
OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class, AaptConfigOptions.class);
optionsParser.enableParamsFileSupport(FileSystems.getDefault());
optionsParser.parseAndExitUponError(args);
aaptConfigOptions = optionsParser.getOptions(AaptConfigOptions.class);
options = optionsParser.getOptions(Options.class);
final AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(STD_LOGGER);
try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_resources_tmp")) {
final Path tmp = scopedTmp.getPath();
final Path mergedAssets = tmp.resolve("merged_assets");
final Path mergedResources = tmp.resolve("merged_resources");
final Path filteredResources = tmp.resolve("resources-filtered");
final Path densityManifest = tmp.resolve("manifest-filtered/AndroidManifest.xml");
final Path processedManifest = tmp.resolve("manifest-processed/AndroidManifest.xml");
final Path dummyManifest = tmp.resolve("manifest-aapt-dummy/AndroidManifest.xml");
Path generatedSources = null;
if (options.srcJarOutput != null || options.rOutput != null || options.symbolsOut != null) {
generatedSources = tmp.resolve("generated_resources");
}
logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
List<DependencyAndroidData> data = ImmutableSet.<DependencyAndroidData>builder().addAll(options.directData).addAll(options.transitiveData).build().asList();
final MergedAndroidData mergedData = AndroidResourceMerger.mergeData(options.primaryData, options.directData, options.transitiveData, mergedResources, mergedAssets, selectPngCruncher(), options.packageType, options.symbolsOut);
logger.fine(String.format("Merging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
final DensityFilteredAndroidData filteredData = mergedData.filter(new DensitySpecificResourceFilter(options.densities, filteredResources, mergedResources), new DensitySpecificManifestProcessor(options.densities, densityManifest));
logger.fine(String.format("Density filtering finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
MergedAndroidData processedData = AndroidManifestProcessor.with(STD_LOGGER).processManifest(options.packageType, options.packageForR, options.applicationId, options.versionCode, options.versionName, filteredData, processedManifest);
// Write manifestOutput now before the dummy manifest is created.
if (options.manifestOutput != null) {
AndroidResourceOutputs.copyManifestToOutput(processedData, options.manifestOutput);
}
if (options.packageType == VariantType.LIBRARY) {
resourceProcessor.writeDummyManifestForAapt(dummyManifest, options.packageForR);
processedData = new MergedAndroidData(processedData.getResourceDir(), processedData.getAssetDir(), dummyManifest);
}
resourceProcessor.processResources(aaptConfigOptions.aapt, aaptConfigOptions.androidJar, aaptConfigOptions.buildToolsVersion, options.packageType, aaptConfigOptions.debug, options.packageForR, new FlagAaptOptions(aaptConfigOptions), aaptConfigOptions.resourceConfigs, aaptConfigOptions.splits, processedData, data, generatedSources, options.packagePath, options.proguardOutput, options.mainDexProguardOutput, options.resourcesOutput != null ? processedData.getResourceDir().resolve("values").resolve("public.xml") : null, options.dataBindingInfoOut);
logger.fine(String.format("aapt finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
if (options.srcJarOutput != null) {
AndroidResourceOutputs.createSrcJar(generatedSources, options.srcJarOutput, VariantType.LIBRARY == options.packageType);
}
if (options.rOutput != null) {
AndroidResourceOutputs.copyRToOutput(generatedSources, options.rOutput, VariantType.LIBRARY == options.packageType);
}
if (options.resourcesOutput != null) {
AndroidResourceOutputs.createResourcesZip(processedData.getResourceDir(), processedData.getAssetDir(), options.resourcesOutput, false);
}
logger.fine(String.format("Packaging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
} catch (MergingException e) {
logger.log(java.util.logging.Level.SEVERE, "Error during merging resources", e);
throw e;
} catch (IOException | InterruptedException | LoggedErrorException | UnrecognizedSplitsException e) {
logger.log(java.util.logging.Level.SEVERE, "Error during processing resources", e);
throw e;
} catch (Exception e) {
logger.log(java.util.logging.Level.SEVERE, "Unexpected", e);
throw e;
} finally {
resourceProcessor.shutdown();
}
logger.fine(String.format("Resources processed in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
use of com.android.ide.common.res2.MergingException in project bazel by bazelbuild.
the class AndroidDataMerger method loadAndMerge.
/**
* Loads a list of dependency {@link SerializedAndroidData} and merge with the primary {@link
* ParsedAndroidData}.
*
* @see AndroidDataMerger#merge(ParsedAndroidData, ParsedAndroidData, UnvalidatedAndroidData,
* boolean) for details.
*/
UnwrittenMergedAndroidData loadAndMerge(List<? extends SerializedAndroidData> transitive, List<? extends SerializedAndroidData> direct, ParsedAndroidData primary, Path primaryManifest, boolean allowPrimaryOverrideAll) throws MergingException {
Stopwatch timer = Stopwatch.createStarted();
try {
final ParsedAndroidData.Builder directBuilder = ParsedAndroidData.Builder.newBuilder();
final ParsedAndroidData.Builder transitiveBuilder = ParsedAndroidData.Builder.newBuilder();
final List<ListenableFuture<Boolean>> tasks = new ArrayList<>();
for (final SerializedAndroidData dependency : direct) {
tasks.add(executorService.submit(new ParseDependencyDataTask(dependency, directBuilder)));
}
for (final SerializedAndroidData dependency : transitive) {
tasks.add(executorService.submit(new ParseDependencyDataTask(dependency, transitiveBuilder)));
}
// Wait for all the parsing to complete.
FailedFutureAggregator<MergingException> aggregator = FailedFutureAggregator.createForMergingExceptionWithMessage("Failure(s) during dependency parsing");
aggregator.aggregateAndMaybeThrow(tasks);
logger.fine(String.format("Merged dependencies read in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
timer.reset().start();
return doMerge(transitiveBuilder.build(), directBuilder.build(), primary, primaryManifest, allowPrimaryOverrideAll);
} finally {
logger.fine(String.format("Resources merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
}
use of com.android.ide.common.res2.MergingException in project buck by facebook.
the class MergeAndroidResourceSourcesStep method execute.
@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
ResourceMerger merger = new ResourceMerger(1);
try {
for (Path resPath : resPaths) {
Preconditions.checkState(resPath.isAbsolute());
ResourceSet set = new ResourceSet(resPath.toString(), true);
set.setDontNormalizeQualifiers(true);
set.addSource(resPath.toFile());
set.loadFromFiles(new ResourcesSetLoadLogger(context.getBuckEventBus()));
merger.addDataSet(set);
}
MergedResourceWriter writer = MergedResourceWriter.createWriterWithoutPngCruncher(outFolderPath.toFile(), null, /*publicFile*/
null, /*blameLogFolder*/
new NoOpResourcePreprocessor(), tmpFolderPath.toFile());
merger.mergeData(writer, /* cleanUp */
false);
} catch (MergingException e) {
LOG.error(e, "Failed merging resources.");
return StepExecutionResult.ERROR;
}
return StepExecutionResult.SUCCESS;
}
use of com.android.ide.common.res2.MergingException in project paraphrase by JakeWharton.
the class ValueResourceParser method parseFile.
/**
* Parses the file and returns a list of {@link ResourceItem} objects.
* @return a list of resources.
*
* @throws MergingException if a merging exception happens
*/
@NonNull
private List<ResourceItem> parseFile() throws MergingException {
Document document = parseDocument(file);
// get the root node
Node rootNode = document.getDocumentElement();
if (rootNode == null) {
return Collections.emptyList();
}
NodeList nodes = rootNode.getChildNodes();
final int count = nodes.getLength();
// list containing the result
List<ResourceItem> resources = Lists.newArrayListWithExpectedSize(count);
for (int i = 0, n = nodes.getLength(); i < n; i++) {
Node node = nodes.item(i);
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
ResourceItem resource = getResource(node);
if (resource != null) {
resources.add(resource);
}
}
return resources;
}
Aggregations