Java Code Examples for com.android.tools.build.bundletool.model.BundleModule#Builder

The following examples show how to use com.android.tools.build.bundletool.model.BundleModule#Builder . 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: BundleModuleMerger.java    From bundletool with Apache License 2.0 6 votes vote down vote up
private static void mergeAndroidManifest(
    ImmutableSet<BundleModule> bundleModulesToFuse, BundleModule.Builder mergedBaseModule) {
  HashMultimap<BundleModuleName, AndroidManifest> manifests =
      bundleModulesToFuse.stream()
          .collect(
              toMultimap(
                  BundleModule::getName, BundleModule::getAndroidManifest, HashMultimap::create));
  AndroidManifest mergedManifest = new FusingAndroidManifestMerger().merge(manifests);
  mergedManifest =
      mergedManifest
          .toEditor()
          .setFusedModuleNames(
              bundleModulesToFuse.stream()
                  .map(module -> module.getName().getName())
                  .collect(toImmutableList()))
          .save();
  mergedBaseModule.setAndroidManifest(mergedManifest);
}
 
Example 2
Source File: AppBundleObfuscationPreprocessor.java    From bundletool with Apache License 2.0 5 votes vote down vote up
private static BundleModule obfuscateBundleModule(
    BundleModule bundleModule,
    HashMap<String, String> resourceNameMapping,
    Predicate<ZipPath> shouldObfuscate) {
  ImmutableSet<ModuleEntry> toBeObfuscatedEntries =
      bundleModule
          .findEntriesUnderPath(RESOURCES_DIRECTORY)
          .filter(moduleEntry -> shouldObfuscate.test(moduleEntry.getPath()))
          .collect(toImmutableSet());

  ImmutableList<ModuleEntry> otherEntries =
      bundleModule.getEntries().stream()
          .filter(moduleEntry -> !toBeObfuscatedEntries.contains(moduleEntry))
          .collect(toImmutableList());

  BundleModule.Builder obfuscatedBundleModule =
      bundleModule.toBuilder()
          .setRawEntries(
              ImmutableList.<ModuleEntry>builder()
                  .addAll(obfuscateModuleEntries(toBeObfuscatedEntries, resourceNameMapping))
                  .addAll(otherEntries)
                  .build());
  if (bundleModule.getResourceTable().isPresent()) {
    obfuscatedBundleModule.setResourceTable(
        obfuscateResourceTableEntries(
            bundleModule.getResourceTable().get(), ImmutableMap.copyOf(resourceNameMapping)));
  }
  return obfuscatedBundleModule.build();
}
 
Example 3
Source File: BundleModuleMerger.java    From bundletool with Apache License 2.0 4 votes vote down vote up
/**
 * Merge install-time modules into base module, unless they have {@code <dist:removable
 * dist:value="true" />} in install-time attribute.
 */
public static AppBundle mergeNonRemovableInstallTimeModules(
    AppBundle appBundle, boolean overrideBundleToolVersion) throws IOException {
  ImmutableSet<BundleModule> bundleModulesToFuse =
      Stream.concat(
              Stream.of(appBundle.getBaseModule()),
              appBundle.getFeatureModules().values().stream()
                  .filter(
                      module ->
                          shouldMerge(
                              module, appBundle.getBundleConfig(), overrideBundleToolVersion)))
          .collect(toImmutableSet());

  // If only base module should be fused there is nothing to do.
  if (bundleModulesToFuse.size() == 1) {
    return appBundle;
  }

  BundleModule.Builder mergedBaseModule =
      BundleModule.builder()
          .setName(BundleModuleName.BASE_MODULE_NAME)
          .setBundleConfig(appBundle.getBundleConfig());

  mergeApexTable(bundleModulesToFuse).ifPresent(mergedBaseModule::setApexConfig);
  mergeAssetsTable(bundleModulesToFuse).ifPresent(mergedBaseModule::setAssetsConfig);
  mergeNativeLibraryTable(bundleModulesToFuse).ifPresent(mergedBaseModule::setNativeConfig);
  mergeResourceTable(bundleModulesToFuse).ifPresent(mergedBaseModule::setResourceTable);
  mergeAndroidManifest(bundleModulesToFuse, mergedBaseModule);

  ImmutableList<ModuleEntry> renamedDexEntries =
      ModuleSplitsToShardMerger.renameDexFromAllModulesToSingleShard(
          getDexEntries(bundleModulesToFuse));

  mergedBaseModule
      .addEntries(getAllEntriesExceptDexAndSpecial(bundleModulesToFuse))
      .addEntries(renamedDexEntries);

  return appBundle.toBuilder()
      .setRawModules(
          Stream.concat(
                  Stream.of(mergedBaseModule.build()),
                  appBundle.getModules().values().stream()
                      .filter(module -> !bundleModulesToFuse.contains(module)))
              .collect(toImmutableSet()))
      .build();
}
 
Example 4
Source File: ModuleNamesValidatorTest.java    From bundletool with Apache License 2.0 4 votes vote down vote up
private static BundleModule.Builder buildBundleModule(String moduleName) {
  return BundleModule.builder()
      .setName(BundleModuleName.create(moduleName))
      .setBundleConfig(BundleConfig.getDefaultInstance());
}