variants.stream() .flatMap(variant -> variant.getApkSetList().stream()) .flatMap(apkSet -> apkSet.getApkDescriptionList().stream()) .map(ApkDescription::getPath) .distinct()
@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); } }
ApkSet.newBuilder() .setModuleMetadata(appBundle.getModule(moduleName).getModuleMetadata()) .addAllApkDescription(
assertThat(standaloneApkSets).hasSize(1); List<ApkDescription> standaloneApkDescription = standaloneApkSets.get(0).getApkDescriptionList(); assertThat(standaloneApkDescription).hasSize(1); File standaloneApkFile = 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"); List<ApkDescription> baseModuleApks = modules.get("base").getApkDescriptionList(); assertThat(baseModuleApks).hasSize(2); Map<Boolean, ApkDescription> apkBaseMaster = List<ApkDescription> featureModuleApks = modules.get("feature").getApkDescriptionList(); assertThat(featureModuleApks).hasSize(2); Map<Boolean, ApkDescription> apkFeatureMaster =
.collect( toImmutableMap( apkSet -> apkSet.getModuleMetadata().getName(), apkSet -> apkSet.getApkDescriptionList())); assertThat(splitApksByModule.keySet()) .containsExactly("base", "abi_feature", "language_feature");
for (Variant variant : standaloneVariantsByAbi.values()) { ApkSet apkSet = getOnlyElement(variant.getApkSetList()); ApkDescription apkDescription = getOnlyElement(apkSet.getApkDescriptionList()); assertThat(apkSetFile).hasFile(apkDescription.getPath());
ApkSet apkSet = variant.getApkSet(0); apkSet .getApkDescriptionList() .forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
assertThat(variant.getApkSetList()).hasSize(1); ApkSet apkSet = variant.getApkSet(0); assertThat(apkSet.getApkDescriptionList()).hasSize(1); assertThat(apkSetFile).hasFile(apkSet.getApkDescription(0).getPath());
if (systemApkBuildMode.equals(SYSTEM)) { assertThat(apkSet.getApkDescriptionList()).hasSize(1); } else { assertThat(apkSet.getApkDescriptionList()).hasSize(2); .getApkDescriptionList() .forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
ImmutableMap<String, ApkSet> splitApkSetByModuleName = Maps.uniqueIndex( splitApkVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName()); assertThat(splitApkSetByModuleName).hasSize(4); assertThat(baseSplits.getModuleMetadata().getDependenciesList()).isEmpty(); assertThat(feature1Splits.getModuleMetadata().getDependenciesList()).isEmpty(); assertThat(feature2Splits.getModuleMetadata().getDependenciesList()) .containsExactly("feature1"); assertThat(feature3Splits.getModuleMetadata().getDependenciesList()) .containsExactly("feature1", "feature2"); List<ApkSet> apkSetList = standaloneApkVariants(result).get(0).getApkSetList(); assertThat(apkSetList).hasSize(1); assertThat(apkSetList.get(0).getModuleMetadata().getDependenciesList()).isEmpty();
.map( variant -> getOnlyElement(getOnlyElement(variant.getApkSetList()).getApkDescriptionList()) .getPath()) .collect(toImmutableSet());
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(apkSetFile).hasFile(baseSplits.getApkDescription(0).getPath()); assertThat(onDemandSplits.getModuleMetadata().getName()).isEqualTo("onDemand"); assertThat(onDemandSplits.getModuleMetadata().getOnDemand()).isTrue(); assertThat(onDemandSplits.getApkDescriptionList()).hasSize(1); assertThat(apkSetFile).hasFile(onDemandSplits.getApkDescription(0).getPath());
assertThat(standaloneApkVariant.getApkSetList()).hasSize(1); ApkSet shards = standaloneApkVariant.getApkSet(0); assertThat(shards.getModuleMetadata().getName()).isEqualTo("base"); assertThat(shards.getApkDescriptionList()).hasSize(1); ApkDescription shard = shards.getApkDescription(0); assertThat(apkSetFile).hasFile(shard.getPath()); assertThat(ZipPath.create(shard.getPath()).getFileName())
ApkSet apkSet = variant.getApkSet(0); assertThat(apkSet.getApkDescriptionList()).hasSize(1); assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-xhdpi.apk");
ApkSet apkSet = variant.getApkSet(0); assertThat(apkSet.getApkDescriptionList()).hasSize(2); assertThat(apkNamesInSet(apkSet)) .containsExactly("splits/base-master.apk", "splits/base-mdpi.apk");
assertThat(variant.getApkSetList()).hasSize(1); ApkSet apkSet = variant.getApkSetList().get(0); assertThat(apkSet.getModuleMetadata().getIsInstant()).isTrue(); assertThat(apkSetFile).hasFile(apkSet.getApkDescription(0).getPath()); assertThat(variant.getApkSetList()).hasSize(1); apkSet = variant.getApkSetList().get(0); assertThat(apkSet.getModuleMetadata().getIsInstant()).isTrue(); assertThat(apkSetFile).hasFile(apkSet.getApkDescription(0).getPath());
ApkSet apkSet = variant.getApkSet(0); assertThat(apkSet.getApkDescriptionList()).hasSize(1); assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-hdpi.apk");
ApkSet apkSet = variant.getApkSet(0); assertThat(apkSet.getApkDescriptionList()).hasSize(2); assertThat(apkNamesInSet(apkSet)) .containsExactly("splits/base-master.apk", "splits/base-xhdpi.apk");
@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()); }
@Test public void deviceSpec_instantSplitsGenerated() throws Exception { DeviceSpec deviceSpec = lDeviceWithDensity(XHDPI); bundleSerializer.writeToDisk(createInstantBundle(), bundlePath); BuildApksCommand command = BuildApksCommand.builder() .setBundlePath(bundlePath) .setOutputFile(outputFilePath) .setDeviceSpec(deviceSpec) .build(); Path apksArchive = command.execute(); ZipFile apksZipFile = new ZipFile(apksArchive.toFile()); assertThat(apksZipFile) .containsExactlyEntries( "toc.pb", "splits/base-master.apk", "instant/instant-base-master.apk"); BuildApksResult result = extractTocFromApkSetFile(apksZipFile, outputDir); assertThat(instantApkVariants(result)).hasSize(1); assertThat(splitApkVariants(result)).hasSize(1); Variant variant = splitApkVariants(result).get(0); assertThat(variant.getApkSetList()).hasSize(1); ApkSet apkSet = variant.getApkSet(0); assertThat(apkSet.getApkDescriptionList()).hasSize(1); assertThat(apkNamesInSet(apkSet)).containsExactly("splits/base-master.apk"); variant = instantApkVariants(result).get(0); assertThat(variant.getApkSetList()).hasSize(1); apkSet = variant.getApkSet(0); assertThat(apkSet.getApkDescriptionList()).hasSize(1); assertThat(apkNamesInSet(apkSet)).containsExactly("instant/instant-base-master.apk"); }