com.android.ide.common.internal.PngCruncher Java Examples

The following examples show how to use com.android.ide.common.internal.PngCruncher. 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: AARLibraries.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Merges the resources from all of the dependent AAR libraries into the main resource bundle for
 * the compiling app.
 *
 * @param outputDir the output directory to write the R.java files.
 * @param mainResDir the resource directory where the resource descriptors for the app reside.
 * @param cruncher configured PNG cruncher utility for reducing the size of PNG assets.
 * @return true if the merge was successful, otherwise false.
 */
public boolean mergeResources(File outputDir, File mainResDir, PngCruncher cruncher) {
  List<ResourceSet> resourceSets = getResourceSets();
  ResourceSet mainResSet = new ResourceSet("main");
  mainResSet.addSource(mainResDir);
  resourceSets.add(mainResSet);
  ResourceMerger merger = new ResourceMerger();

  try {
    for (ResourceSet resourceSet : resourceSets) {
      resourceSet.loadFromFiles(LOG);
      merger.addDataSet(resourceSet);
    }

    MergedResourceWriter writer = new MergedResourceWriter(outputDir, cruncher, false, false, null);
    writer.setInsertSourceMarkers(true);
    merger.mergeData(writer, false);
    return true;
  } catch(MergingException e) {
    e.printStackTrace();
    return false;
  }
}
 
Example #2
Source File: MergeResources.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private PngCruncher getCruncher() {
    if (getUseNewCruncher()) {
        return QueuedCruncher.Builder.INSTANCE.newCruncher(
                getBuilder().getTargetInfo().getBuildTools().getPath(
                        BuildToolInfo.PathId.AAPT), getILogger());
    }
    return getBuilder().getAaptCruncher(new LoggedProcessOutputHandler(getBuilder().getLogger()));
}
 
Example #3
Source File: MergedResourceWriter.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public MergedResourceWriter(@NonNull File rootFolder,
        @NonNull PngCruncher pngRunner,
        boolean crunchPng,
        boolean process9Patch,
        @Nullable File publicFile,
        @NonNull ResourcePreprocessor preprocessor) {
    super(rootFolder);
    mCruncher = pngRunner;
    mCruncherKey = mCruncher.start();
    mCrunchPng = crunchPng;
    mProcess9Patch = process9Patch;
    mPublicFile = publicFile;
    mPreprocessor = preprocessor;
}
 
Example #4
Source File: AndroidBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns an {@link PngCruncher} using aapt underneath
 *
 * @return an PngCruncher object
 */
@NonNull
public PngCruncher getAaptCruncher(ProcessOutputHandler processOutputHandler) {
    checkState(mTargetInfo != null,
            "Cannot call getAaptCruncher() before setTargetInfo() is called.");
    return new AaptCruncher(
            mTargetInfo.getBuildTools().getPath(BuildToolInfo.PathId.AAPT),
            mProcessExecutor,
            processOutputHandler);
}
 
Example #5
Source File: Compiler.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Merge XML resources from different dependencies into a single file that can be passed to AAPT.
 *
 * @param mainResDir Directory for resources from the application (i.e., not libraries)
 * @param buildDir Build directory path. Merged resources will be placed at $buildDir/intermediates/res/merged
 * @param aaptTool Path to the AAPT tool
 * @return true if the resources were merged successfully, otherwise false
 */
private boolean mergeResources(File mainResDir, File buildDir, String aaptTool) {
  // these should exist from earlier build steps
  File intermediates = createDir(buildDir, "intermediates");
  File resDir = createDir(intermediates, "res");
  mergedResDir = createDir(resDir, "merged");
  PngCruncher cruncher = new AaptCruncher(getResource(aaptTool), null, null);
  return explodedAarLibs.mergeResources(mergedResDir, mainResDir, cruncher);
}
 
Example #6
Source File: AndroidDataWriter.java    From bazel with Apache License 2.0 5 votes vote down vote up
private AndroidDataWriter(
    Path destination,
    Path resourceDirectory,
    Path assetsDirectory,
    PngCruncher cruncher,
    ListeningExecutorService executorService) {
  this.destination = destination;
  this.resourceDirectory = resourceDirectory;
  this.assetDirectory = assetsDirectory;
  this.cruncher = cruncher;
  this.executorService = executorService;
}
 
Example #7
Source File: AndroidDataWriter.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new writer.
 *
 * @param manifestDirectory The base directory for the AndroidManifest.
 * @param resourceDirectory The directory to copy resources into.
 * @param assetsDirectory The directory to copy assets into.
 * @param cruncher The cruncher for png files. If the cruncher is null, it will be replaced with a
 *     noop cruncher.
 * @param executorService An execution service for multi-threaded writing.
 * @return A new {@link AndroidDataWriter}.
 */
public static AndroidDataWriter createWith(
    Path manifestDirectory,
    Path resourceDirectory,
    Path assetsDirectory,
    @Nullable PngCruncher cruncher,
    ListeningExecutorService executorService) {
  return new AndroidDataWriter(
      manifestDirectory,
      resourceDirectory,
      assetsDirectory,
      cruncher == null ? NOOP_CRUNCHER : cruncher,
      executorService);
}
 
Example #8
Source File: AndroidResourceMerger.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Merges all secondary resources with the primary resources, given that the primary resources
 * have not yet been parsed and serialized.
 */
public static MergedAndroidData mergeDataAndWrite(
    final UnvalidatedAndroidData primary,
    final List<? extends SerializedAndroidData> direct,
    final List<? extends SerializedAndroidData> transitive,
    final Path resourcesOut,
    final Path assetsOut,
    @Nullable final PngCruncher cruncher,
    final VariantType type,
    @Nullable final Path symbolsOut,
    final List<String> filteredResources,
    boolean throwOnResourceConflict) {
  try (ExecutorServiceCloser executorService = ExecutorServiceCloser.createWithFixedPoolOf(15)) {
    final ParsedAndroidData parsedPrimary = ParsedAndroidData.from(primary);
    return mergeDataAndWrite(
        parsedPrimary,
        primary.getManifest(),
        direct,
        transitive,
        resourcesOut,
        assetsOut,
        cruncher,
        type,
        symbolsOut,
        /* rclassWriter= */ null,
        AndroidParsedDataDeserializer.withFilteredResources(filteredResources),
        throwOnResourceConflict,
        executorService);
  } catch (IOException e) {
    throw MergingException.wrapException(e);
  }
}
 
Example #9
Source File: AndroidResourceMerger.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * Merges all secondary resources with the primary resources, given that the primary resources
 * have been separately parsed and serialized.
 */
public static MergedAndroidData mergeDataAndWrite(
    final SerializedAndroidData primary,
    final Path primaryManifest,
    final List<? extends SerializedAndroidData> direct,
    final List<? extends SerializedAndroidData> transitive,
    final Path resourcesOut,
    final Path assetsOut,
    @Nullable final PngCruncher cruncher,
    final VariantType type,
    @Nullable final Path symbolsOut,
    @Nullable final AndroidResourceClassWriter rclassWriter,
    boolean throwOnResourceConflict,
    ListeningExecutorService executorService) {
  final ParsedAndroidData.Builder primaryBuilder = ParsedAndroidData.Builder.newBuilder();
  final AndroidParsedDataDeserializer deserializer = AndroidParsedDataDeserializer.create();
  primary.deserialize(
      DependencyInfo.DependencyType.PRIMARY, deserializer, primaryBuilder.consumers());
  ParsedAndroidData primaryData = primaryBuilder.build();
  return mergeDataAndWrite(
      primaryData,
      primaryManifest,
      direct,
      transitive,
      resourcesOut,
      assetsOut,
      cruncher,
      type,
      symbolsOut,
      rclassWriter,
      deserializer,
      throwOnResourceConflict,
      executorService);
}
 
Example #10
Source File: MergedResourceWriter.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public MergedResourceWriter(@NonNull File rootFolder, @Nullable PngCruncher pngRunner) {
    super(rootFolder);
    mCruncher = pngRunner;
}
 
Example #11
Source File: AndroidDataWriter.java    From bazel with Apache License 2.0 4 votes vote down vote up
private CrunchTask(PngCruncher cruncher, Path destinationPath, Path source) {
  this.cruncher = cruncher;
  this.destinationPath = destinationPath;
  this.source = source;
}
 
Example #12
Source File: AndroidResourceMerger.java    From bazel with Apache License 2.0 4 votes vote down vote up
/** Merges all secondary resources with the primary resources. */
private static MergedAndroidData mergeDataAndWrite(
    final ParsedAndroidData primary,
    final Path primaryManifest,
    final List<? extends SerializedAndroidData> direct,
    final List<? extends SerializedAndroidData> transitive,
    final Path resourcesOut,
    final Path assetsOut,
    @Nullable final PngCruncher cruncher,
    final VariantType type,
    @Nullable final Path symbolsOut,
    @Nullable AndroidResourceClassWriter rclassWriter,
    AndroidParsedDataDeserializer deserializer,
    boolean throwOnResourceConflict,
    ListeningExecutorService executorService) {
  Stopwatch timer = Stopwatch.createStarted();
  try {
    UnwrittenMergedAndroidData merged =
        mergeData(
            executorService,
            transitive,
            direct,
            primary,
            primaryManifest,
            type != VariantType.LIBRARY,
            deserializer,
            throwOnResourceConflict,
            ContentComparingChecker.create());
    timer.reset().start();
    if (symbolsOut != null) {
      AndroidDataSerializer serializer = AndroidDataSerializer.create();
      merged.serializeTo(serializer);
      serializer.flushTo(symbolsOut);
      logger.fine(
          String.format(
              "serialize merge finished in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
      timer.reset().start();
    }
    if (rclassWriter != null) {
      merged.writeResourceClass(rclassWriter);
      logger.fine(
          String.format("write classes finished in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
      timer.reset().start();
    }
    AndroidDataWriter writer =
        AndroidDataWriter.createWith(
            resourcesOut.getParent(), resourcesOut, assetsOut, cruncher, executorService);
    return merged.write(writer);
  } catch (IOException e) {
    throw MergingException.wrapException(e);
  } finally {
    logger.fine(
        String.format("write merge finished in %sms", timer.elapsed(TimeUnit.MILLISECONDS)));
  }
}