/** Builds a map of module dependencies. */ private static ImmutableMultimap<String, String> buildAdjacencyMap(Variant variant) { ImmutableMultimap.Builder<String, String> moduleDependenciesMap = ImmutableMultimap.builder(); variant .getApkSetList() .stream() .map(ApkSet::getModuleMetadata) .forEach( moduleMetadata -> { moduleDependenciesMap.putAll( moduleMetadata.getName(), moduleMetadata.getDependenciesList()); moduleDependenciesMap.put(moduleMetadata.getName(), "base"); }); return moduleDependenciesMap.build(); }
@VisibleForTesting ImmutableList<Path> execute(PrintStream output) { validateInput(); BuildApksResult toc = ResultUtils.readTableOfContents(getApksArchivePath()); Optional<ImmutableSet<String>> requestedModuleNames = getModules() .map( modules -> modules.contains(ALL_MODULES_SHORTCUT) ? toc.getVariantList().stream() .flatMap(variant -> variant.getApkSetList().stream()) .map(apkSet -> apkSet.getModuleMetadata().getName()) .collect(toImmutableSet()) : modules); ApkMatcher apkMatcher = new ApkMatcher(getDeviceSpec(), requestedModuleNames, getInstant()); ImmutableList<ZipPath> matchedApks = apkMatcher.getMatchingApks(toc); if (Files.isDirectory(getApksArchivePath())) { return matchedApks.stream() .map(matchedApk -> getApksArchivePath().resolve(matchedApk.toString())) .collect(toImmutableList()); } else { return extractMatchedApksFromApksArchive(matchedApks); } }
public ImmutableList<ZipPath> getMatchingApksFromVariant(Variant variant) { ImmutableList.Builder<ZipPath> matchedApksBuilder = ImmutableList.builder(); Predicate<String> moduleNameMatcher = getModuleNameMatcher(variant); for (ApkSet apkSet : variant.getApkSetList()) { String moduleName = apkSet.getModuleMetadata().getName(); for (ApkDescription apkDescription : apkSet.getApkDescriptionList()) { ApkTargeting apkTargeting = apkDescription.getTargeting(); boolean isSplit = !apkDescription.hasStandaloneApkMetadata(); checkCompatibleWithApkTargeting(apkTargeting); if (matchesApk(apkTargeting, isSplit, moduleName, moduleNameMatcher)) { matchedApksBuilder.add(ZipPath.create(apkDescription.getPath())); } } } return matchedApksBuilder.build(); }
.collect( toImmutableMap( apkSet -> apkSet.getModuleMetadata().getName(), apkSet -> apkSet.getApkDescriptionList())); assertThat(splitApksByModule.keySet())
List<ApkSet> splitApkSetList = splitApkVariants(result).get(0).getApkSetList(); Map<String, ApkSet> modules = Maps.uniqueIndex(splitApkSetList, apkSet -> apkSet.getModuleMetadata().getName()); assertThat(modules.keySet()).containsExactly("base", "feature");
ImmutableMap<String, ApkSet> splitApkSetByModuleName = Maps.uniqueIndex( splitApkVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName()); assertThat(splitApkSetByModuleName).hasSize(4);
ImmutableMap<String, ApkSet> splitApkSetByModuleName = Maps.uniqueIndex( splitApkVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName()); assertThat(splitApkSetByModuleName).hasSize(2); assertThat(baseSplits.getModuleMetadata().getName()).isEqualTo("base"); assertThat(baseSplits.getModuleMetadata().getOnDemand()).isFalse(); assertThat(baseSplits.getApkDescriptionList()).hasSize(1); assertThat(onDemandSplits.getModuleMetadata().getName()).isEqualTo("onDemand"); assertThat(onDemandSplits.getModuleMetadata().getOnDemand()).isTrue(); assertThat(onDemandSplits.getApkDescriptionList()).hasSize(1);
assertThat(standaloneApkVariant.getApkSetList()).hasSize(1); ApkSet shards = standaloneApkVariant.getApkSet(0); assertThat(shards.getModuleMetadata().getName()).isEqualTo("base"); assertThat(shards.getApkDescriptionList()).hasSize(1);
@Test public void buildApksCommand_standalone_oneModuleOneVariant() throws Exception { bundlePath = FileUtils.getRandomFilePath(tmp, "bundle-", ".aab"); AppBundle appBundle = new AppBundleBuilder() .addModule( "base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app"))) .build(); bundleSerializer.writeToDisk(appBundle, bundlePath); BuildApksCommand command = BuildApksCommand.builder() .setBundlePath(bundlePath) .setOutputFile(outputFilePath) .setAapt2Command(aapt2Command) .build(); Path apkSetFilePath = execute(command); ZipFile apkSetFile = new ZipFile(apkSetFilePath.toFile()); BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir); assertThat(standaloneApkVariants(result)).hasSize(1); Variant standaloneApkVariant = standaloneApkVariants(result).get(0); assertThat(standaloneApkVariant.getApkSetList()).hasSize(1); ApkSet shards = standaloneApkVariant.getApkSet(0); assertThat(shards.getModuleMetadata().getName()).isEqualTo("base"); assertThat(shards.getApkDescriptionList()).hasSize(1); assertThat(ZipPath.create(shards.getApkDescription(0).getPath()).getFileName()) .isEqualTo(ZipPath.create("standalone.apk")); assertThat(apkSetFile).hasFile(shards.getApkDescription(0).getPath()); }