Java Code Examples for com.android.bundle.Files.NativeLibraries#getDirectoryList()

The following examples show how to use com.android.bundle.Files.NativeLibraries#getDirectoryList() . 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: TargetingGeneratorTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
public void generateTargetingForNativeLibraries_createsSingleDirectoryGroup() throws Exception {
  Collection<String> manyDirectories =
      Arrays.stream(AbiName.values())
          .map(AbiName::getPlatformName)
          .map(abi -> "lib/" + abi)
          .collect(toImmutableList());
  checkState(manyDirectories.size() > 1); // Otherwise this test is useless.

  NativeLibraries nativeTargeting =
      generator.generateTargetingForNativeLibraries(manyDirectories);

  List<TargetedNativeDirectory> directories = nativeTargeting.getDirectoryList();
  assertThat(directories).hasSize(manyDirectories.size());
}
 
Example 2
Source File: TargetingGeneratorTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
public void generateTargetingForNativeLibraries_sanitizer() throws Exception {
  NativeLibraries nativeTargeting =
      generator.generateTargetingForNativeLibraries(ImmutableList.of("lib/arm64-v8a-hwasan"));

  List<TargetedNativeDirectory> directories = nativeTargeting.getDirectoryList();
  assertThat(directories).hasSize(1);
  assertThat(directories.get(0))
      .isEqualTo(
          TargetedNativeDirectory.newBuilder()
              .setPath("lib/arm64-v8a-hwasan")
              .setTargeting(
                  nativeDirectoryTargeting(AbiAlias.ARM64_V8A, SanitizerAlias.HWADDRESS))
              .build());
}
 
Example 3
Source File: NativeTargetingValidator.java    From bundletool with Apache License 2.0 4 votes vote down vote up
private static void validateTargeting(BundleModule module, NativeLibraries nativeLibraries) {
  for (TargetedNativeDirectory targetedDirectory : nativeLibraries.getDirectoryList()) {
    ZipPath path = ZipPath.create(targetedDirectory.getPath());
    NativeDirectoryTargeting targeting = targetedDirectory.getTargeting();

    if (!targeting.hasAbi()) {
      throw InvalidBundleException.builder()
          .withUserMessage(
              "Targeted native directory '%s' does not have the ABI dimension set.",
              targetedDirectory.getPath())
          .build();
    }

    if (!path.startsWith(LIB_DIRECTORY) || path.getNameCount() != 2) {
      throw InvalidBundleException.builder()
          .withUserMessage(
              "Path of targeted native directory must be in format 'lib/<directory>' but "
                  + "found '%s'.",
              path)
          .build();
    }

    if (BundleValidationUtils.directoryContainsNoFiles(module, path)) {
      throw InvalidBundleException.builder()
          .withUserMessage("Targeted directory '%s' is empty.", path)
          .build();
    }
  }

  SetView<String> libDirsWithoutTargeting =
      Sets.difference(
          module
              .findEntriesUnderPath(LIB_DIRECTORY)
              .map(libFile -> libFile.getPath().subpath(0, 2).toString())
              .collect(toImmutableSet()),
          nativeLibraries.getDirectoryList().stream()
              .map(TargetedNativeDirectory::getPath)
              .collect(toImmutableSet()));
  if (!libDirsWithoutTargeting.isEmpty()) {
    throw InvalidBundleException.builder()
        .withUserMessage(
            "Following native directories are not targeted: %s", libDirsWithoutTargeting)
        .build();
  }
}
 
Example 4
Source File: AndroidAppBundleIntegrationTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test
public void testAppBundleHaveDeterministicTimestamps() throws IOException {
  // TODO(bduff): a lot of this tests the operation of bundletool. We probably don't need to.
  String target = "//apps/sample:app_bundle_1";
  ProcessResult result = workspace.runBuckCommand("build", target);
  result.assertSuccess();

  // Iterate over each of the entries, expecting to see all zeros in the time fields.
  Path aab =
      workspace.getPath(
          BuildTargetPaths.getGenPath(
              filesystem, BuildTargetFactory.newInstance(target), "%s.signed.aab"));
  Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME));
  try (ZipInputStream is = new ZipInputStream(Files.newInputStream(aab))) {
    for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
      assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch));
    }
  }

  ZipInspector zipInspector = new ZipInspector(aab);
  zipInspector.assertFileExists("BundleConfig.pb");
  zipInspector.assertFileExists("base/dex/classes.dex");
  zipInspector.assertFileExists("base/assets.pb");
  zipInspector.assertFileExists("base/resources.pb");
  zipInspector.assertFileExists("base/manifest/AndroidManifest.xml");
  zipInspector.assertFileExists("base/assets/asset_file.txt");
  zipInspector.assertFileExists("base/res/drawable/tiny_black.png");
  zipInspector.assertFileExists("base/native.pb");
  zipInspector.assertFileExists("base/lib/armeabi-v7a/libnative_cxx_lib.so");
  zipInspector.assertFileExists("base/assets/secondary-program-dex-jars/secondary-1.dex.jar");
  NativeLibraries nativeLibraries =
      NativeLibraries.parseFrom(zipInspector.getFileContents("base/native.pb"));

  // Two abis under lib that have at least 1 file (armeabi-v7a, x86)
  assertEquals(2, nativeLibraries.getDirectoryList().size());
  for (TargetedNativeDirectory targetedNativeDirectory : nativeLibraries.getDirectoryList()) {
    assertTrue(targetedNativeDirectory.getTargeting().hasAbi());
  }

  Assets assets = Assets.parseFrom(zipInspector.getFileContents("base/assets.pb"));
  assertEquals(2, assets.getDirectoryList().size());

  BundleConfig bundleConfig =
      BundleConfig.parseFrom(zipInspector.getFileContents("BundleConfig.pb"));

  System.err.println(bundleConfig);

  assertTrue(bundleConfig.hasBundletool());

  assertTrue(bundleConfig.hasOptimizations());
  assertOptimizations(bundleConfig.getOptimizations());

  assertTrue(bundleConfig.hasCompression());
  assertCompression(bundleConfig.getCompression());
}