use of com.android.ide.common.res2.MergingException in project bazel by bazelbuild.
the class LibraryRClassGeneratorAction 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 aaptConfigOptions = optionsParser.getOptions(AaptConfigOptions.class);
Options options = optionsParser.getOptions(Options.class);
logger.fine(String.format("Option parsing finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_resource_generated")) {
AndroidResourceClassWriter resourceClassWriter = AndroidResourceClassWriter.createWith(aaptConfigOptions.androidJar, scopedTmp.getPath(), Strings.nullToEmpty(options.packageForR));
resourceClassWriter.setIncludeClassFile(true);
resourceClassWriter.setIncludeJavaFile(false);
final AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(stdLogger);
logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
final ParsedAndroidData data = resourceProcessor.deserializeSymbolsToData(options.symbols);
logger.fine(String.format("Deserialization finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
data.writeResourcesTo(resourceClassWriter);
resourceClassWriter.flush();
logger.fine(String.format("R writing finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
AndroidResourceOutputs.createClassJar(scopedTmp.getPath(), options.classJarOutput);
logger.fine(String.format("Creating class jar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
} catch (IOException | MergingException | DeserializationException e) {
logger.log(Level.SEVERE, "Errors during R generation.", e);
throw e;
}
}
use of com.android.ide.common.res2.MergingException in project bazel by bazelbuild.
the class AndroidResourceProcessor method deserializeSymbolsToData.
/** Deserializes a list of serialized resource paths to a {@link ParsedAndroidData}. */
public ParsedAndroidData deserializeSymbolsToData(List<Path> symbolPaths) throws IOException, MergingException {
AndroidDataDeserializer deserializer = AndroidDataDeserializer.create();
final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(15));
final Builder deserializedDataBuilder = ParsedAndroidData.Builder.newBuilder();
try (Closeable closeable = ExecutorServiceCloser.createWith(executorService)) {
List<ListenableFuture<Boolean>> deserializing = new ArrayList<>();
for (final Path symbolPath : symbolPaths) {
deserializing.add(executorService.submit(new Deserialize(deserializer, symbolPath, deserializedDataBuilder)));
}
FailedFutureAggregator<MergingException> aggregator = FailedFutureAggregator.createForMergingExceptionWithMessage("Failure(s) during dependency parsing");
aggregator.aggregateAndMaybeThrow(deserializing);
}
return deserializedDataBuilder.build();
}
use of com.android.ide.common.res2.MergingException in project bazel by bazelbuild.
the class AarGeneratorAction method main.
public static void main(String[] args) {
Stopwatch timer = Stopwatch.createStarted();
OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class);
optionsParser.parseAndExitUponError(args);
Options options = optionsParser.getOptions(Options.class);
checkFlags(options);
AndroidResourceProcessor resourceProcessor = new AndroidResourceProcessor(new StdLogger(com.android.utils.StdLogger.Level.VERBOSE));
try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("aar_gen_tmp")) {
Path tmp = scopedTmp.getPath();
Path resourcesOut = tmp.resolve("merged_resources");
Files.createDirectories(resourcesOut);
Path assetsOut = tmp.resolve("merged_assets");
Files.createDirectories(assetsOut);
logger.fine(String.format("Setup finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
// There aren't any dependencies, but we merge to combine primary resources from different
// res/assets directories into a single res and single assets directory.
MergedAndroidData mergedData = AndroidResourceMerger.mergeData(options.mainData, ImmutableList.<DependencyAndroidData>of(), ImmutableList.<DependencyAndroidData>of(), resourcesOut, assetsOut, null, VariantType.LIBRARY, null);
logger.fine(String.format("Merging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
writeAar(options.aarOutput, mergedData, options.manifest, options.rtxt, options.classes);
logger.fine(String.format("Packaging finished at %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
} catch (IOException | MergingException e) {
logger.log(Level.SEVERE, "Error during merging resources", e);
System.exit(1);
}
System.exit(0);
}
use of com.android.ide.common.res2.MergingException in project paraphrase by JakeWharton.
the class ValueResourceParser method parseDocument.
private static Document parseDocument(File file) throws MergingException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
BufferedInputStream stream = null;
try {
stream = new BufferedInputStream(new FileInputStream(file));
InputSource is = new InputSource(stream);
factory.setNamespaceAware(true);
factory.setValidating(false);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(is);
} catch (SAXParseException e) {
String message = e.getLocalizedMessage();
MergingException exception = new MergingException(message, e);
exception.setFile(file);
int lineNumber = e.getLineNumber();
if (lineNumber != -1) {
// make line numbers 0-based
exception.setLine(lineNumber - 1);
exception.setColumn(e.getColumnNumber() - 1);
}
throw exception;
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new MergingException(e).setFile(file);
} finally {
Closeables.closeQuietly(stream);
}
}
use of com.android.ide.common.res2.MergingException in project bazel by bazelbuild.
the class AndroidResourceMergingAction 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 aaptConfigOptions = optionsParser.getOptions(AaptConfigOptions.class);
Options options = optionsParser.getOptions(Options.class);
Preconditions.checkNotNull(options.primaryData);
Preconditions.checkNotNull(options.primaryManifest);
Preconditions.checkNotNull(options.classJarOutput);
try (ScopedTemporaryDirectory scopedTmp = new ScopedTemporaryDirectory("android_resource_merge_tmp")) {
Path tmp = scopedTmp.getPath();
Path mergedAssets = tmp.resolve("merged_assets");
Path mergedResources = tmp.resolve("merged_resources");
Path generatedSources = tmp.resolve("generated_resources");
Path processedManifest = tmp.resolve("manifest-processed/AndroidManifest.xml");
logger.fine(String.format("Setup finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
VariantType packageType = VariantType.LIBRARY;
AndroidResourceClassWriter resourceClassWriter = AndroidResourceClassWriter.createWith(aaptConfigOptions.androidJar, generatedSources, Strings.nullToEmpty(options.packageForR));
resourceClassWriter.setIncludeClassFile(true);
resourceClassWriter.setIncludeJavaFile(false);
final MergedAndroidData mergedData = AndroidResourceMerger.mergeData(options.primaryData, options.primaryManifest, options.directData, options.transitiveData, mergedResources, mergedAssets, new StubPngCruncher(), packageType, options.symbolsBinOut, resourceClassWriter);
logger.fine(String.format("Merging finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
// the manifests compatible with the old manifest merger.
if (options.manifestOutput != null) {
MergedAndroidData processedData = AndroidManifestProcessor.with(stdLogger).processManifest(packageType, options.packageForR, null, /* applicationId */
-1, /* versionCode */
null, /* versionName */
mergedData, processedManifest);
AndroidResourceOutputs.copyManifestToOutput(processedData, options.manifestOutput);
}
AndroidResourceOutputs.createClassJar(generatedSources, options.classJarOutput);
logger.fine(String.format("Create classJar finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
if (options.resourcesOutput != null) {
Path resourcesDir = AndroidResourceProcessor.processDataBindings(mergedData.getResourceDir(), options.dataBindingInfoOut, packageType, options.packageForR, options.primaryManifest);
// For now, try compressing the library resources that we pass to the validator. This takes
// extra CPU resources to pack and unpack (~2x), but can reduce the zip size (~4x).
AndroidResourceOutputs.createResourcesZip(resourcesDir, mergedData.getAssetDir(), options.resourcesOutput, true);
logger.fine(String.format("Create resources.zip finished at %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
} catch (MergingException e) {
logger.log(Level.SEVERE, "Error during merging resources", e);
throw e;
} catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected", e);
throw e;
}
logger.fine(String.format("Resources merged in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
}
Aggregations