Beispiel #1
0
  @Override
  public ImmutableList<Step> getBuildSteps(
      BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();

    final Path pathToNativeLibs = getPathToNativeLibsDir();
    steps.add(new MakeCleanDirectoryStep(pathToNativeLibs));

    final Path pathToNativeLibsAssets = getPathToNativeLibsAssetsDir();
    steps.add(new MakeCleanDirectoryStep(pathToNativeLibsAssets));

    for (SourcePath nativeLibDir : nativeLibDirectories.asList().reverse()) {
      copyNativeLibrary(
          getProjectFilesystem(),
          getResolver().getPath(nativeLibDir),
          pathToNativeLibs,
          cpuFilters,
          steps);
    }

    addStepsForCopyingNativeLibrariesOrAssets(filteredNativeLibraries, pathToNativeLibs, steps);
    addStepsForCopyingNativeLibrariesOrAssets(
        filteredNativeLibrariesAssets, pathToNativeLibsAssets, steps);

    final Path pathToMetadataTxt = getPathToMetadataTxt();
    steps.add(
        new AbstractExecutionStep("hash_native_libs") {
          @Override
          public int execute(ExecutionContext context) {
            ProjectFilesystem filesystem = context.getProjectFilesystem();
            ImmutableList.Builder<String> metadataLines = ImmutableList.builder();
            try {
              for (Path nativeLib : filesystem.getFilesUnderPath(pathToNativeLibs)) {
                String filesha1 = filesystem.computeSha1(nativeLib);
                Path relativePath = pathToNativeLibs.relativize(nativeLib);
                metadataLines.add(String.format("%s %s", relativePath.toString(), filesha1));
              }

              for (Path nativeLib : filesystem.getFilesUnderPath(pathToNativeLibsAssets)) {
                String filesha1 = filesystem.computeSha1(nativeLib);
                Path relativePath = pathToNativeLibsAssets.relativize(nativeLib);
                metadataLines.add(String.format("%s %s", relativePath.toString(), filesha1));
              }
              filesystem.writeLinesToPath(metadataLines.build(), pathToMetadataTxt);
            } catch (IOException e) {
              context.logError(e, "There was an error hashing native libraries.");
              return 1;
            }
            return 0;
          }
        });

    buildableContext.recordArtifact(pathToNativeLibs);
    buildableContext.recordArtifact(pathToNativeLibsAssets);
    buildableContext.recordArtifact(pathToMetadataTxt);

    return steps.build();
  }
Beispiel #2
0
  @Override
  public ImmutableList<Step> getBuildSteps(
      BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> commands = ImmutableList.builder();

    // Create temp folder to store the files going to be zipped
    commands.add(new MakeCleanDirectoryStep(getProjectFilesystem(), temp));

    // Remove the output .aar file
    commands.add(new RmStep(getProjectFilesystem(), pathToOutputFile, /* force delete */ true));

    // put manifest into tmp folder
    commands.add(
        CopyStep.forFile(
            getProjectFilesystem(),
            manifest.getPathToOutput(),
            temp.resolve("AndroidManifest.xml")));

    // put R.txt into tmp folder
    commands.add(
        CopyStep.forFile(
            getProjectFilesystem(),
            Preconditions.checkNotNull(androidResource.getPathToOutput()),
            temp.resolve("R.txt")));

    // put res/ and assets/ into tmp folder
    commands.add(
        CopyStep.forDirectory(
            getProjectFilesystem(),
            assembledResourceDirectory,
            temp.resolve("res"),
            CopyStep.DirectoryMode.CONTENTS_ONLY));
    commands.add(
        CopyStep.forDirectory(
            getProjectFilesystem(),
            assembledAssetsDirectory,
            temp.resolve("assets"),
            CopyStep.DirectoryMode.CONTENTS_ONLY));

    // Create our Uber-jar, and place it in the tmp folder.
    commands.add(
        new JarDirectoryStep(
            getProjectFilesystem(),
            temp.resolve("classes.jar"),
            ImmutableSet.copyOf(getTransitiveClasspathEntries().values()),
            null,
            null));

    // move native libs into tmp folder under jni/
    if (assembledNativeLibs.isPresent()) {
      commands.add(
          CopyStep.forDirectory(
              getProjectFilesystem(),
              assembledNativeLibs.get(),
              temp.resolve("jni"),
              CopyStep.DirectoryMode.CONTENTS_ONLY));
    }

    // move native assets into tmp folder under assets/lib/
    for (SourcePath dir : nativeLibAssetsDirectories) {
      CopyNativeLibraries.copyNativeLibrary(
          getProjectFilesystem(),
          getResolver().getPath(dir),
          temp.resolve("assets").resolve("lib"),
          ImmutableSet.<TargetCpuType>of(),
          commands);
    }

    // do the zipping
    commands.add(
        new ZipStep(
            getProjectFilesystem(),
            pathToOutputFile,
            ImmutableSet.<Path>of(),
            false,
            ZipStep.DEFAULT_COMPRESSION_LEVEL,
            temp));

    return commands.build();
  }