private ConfigurationSizes getSizeStandaloneVariant() { checkState( !getSizeRequest.getInstant(), "Standalone Variants cant be selected when instant flag is set"); // When modules are specified we ignore standalone variants. if (getSizeRequest.getModules().isPresent()) { return ConfigurationSizes.create(ImmutableMap.of(), ImmutableMap.of()); } VariantTargeting variantTargeting = variant.getTargeting(); SizeConfiguration sizeConfiguration = mergeWithDeviceSpec( getSizeConfiguration( variantTargeting.getSdkVersionTargeting(), variantTargeting.getAbiTargeting(), variantTargeting.getScreenDensityTargeting(), LanguageTargeting.getDefaultInstance()), getSizeRequest.getDeviceSpec()); // Variants of standalone APKs have only one APK each. long compressedSize = sizeByApkPaths.get( Iterables.getOnlyElement( Iterables.getOnlyElement(variant.getApkSetList()).getApkDescriptionList()) .getPath()); ImmutableMap<SizeConfiguration, Long> sizeConfigurationMap = ImmutableMap.of(sizeConfiguration, compressedSize); return ConfigurationSizes.create(sizeConfigurationMap, sizeConfigurationMap); }
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(); }
/** Writes the given split to the path subdirectory in the APK Set. */ private ApkDescription writeToDisk( ModuleSplit split, Path outputDirectory, BiFunction<ApkDescription.Builder, SplitApkMetadata, ApkDescription.Builder> setApkMetadata) { checkState(isDirectory(outputDirectory), "Output directory does not exist."); ZipPath apkPath = apkPathManager.getApkPath(split); apkSerializerHelper.writeToZipFile(split, outputDirectory.resolve(apkPath.toString())); ApkDescription.Builder builder = ApkDescription.newBuilder() .setPath(apkPath.toString()) .setTargeting(split.getApkTargeting()); return setApkMetadata .apply( builder, SplitApkMetadata.newBuilder() .setSplitId(split.getAndroidManifest().getSplitId().orElse("")) .setIsMasterSplit(split.isMasterSplit()) .build()) .build(); } }
assertThat(standaloneApkDescription).hasSize(1); File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApkDescription.get(0).getPath(), outputDir); try (ZipFile standaloneZip = new ZipFile(standaloneApkFile)) { assertThat(filesUnderPath(standaloneZip, ZipPath.create("res"))) Maps.uniqueIndex( baseModuleApks, apkDescription -> apkDescription.getSplitApkMetadata().getIsMasterSplit()); File baseMasterFile = extractFromApkSetFile(apkSetFile, baseMaster.getPath(), outputDir); try (ZipFile baseMasterZip = new ZipFile(baseMasterFile)) { assertThat(filesUnderPath(baseMasterZip, ZipPath.create("res"))) File baseFrFile = extractFromApkSetFile(apkSetFile, baseFr.getPath(), outputDir); try (ZipFile baseFrZip = new ZipFile(baseFrFile)) { assertThat(filesUnderPath(baseFrZip, ZipPath.create("res"))) Maps.uniqueIndex( featureModuleApks, apkDescription -> apkDescription.getSplitApkMetadata().getIsMasterSplit()); File featureMasterFile = extractFromApkSetFile(apkSetFile, featureMaster.getPath(), outputDir); try (ZipFile featureMasterZip = new ZipFile(featureMasterFile)) { assertThat(filesUnderPath(featureMasterZip, ZipPath.create("res"))) File featureFrFile = extractFromApkSetFile(apkSetFile, featureFr.getPath(), outputDir); try (ZipFile featureFrZip = new ZipFile(featureFrFile)) { assertThat(filesUnderPath(featureFrZip, ZipPath.create("res")))
assertThat(systemApks) .containsExactly( ApkDescription.newBuilder() .setPath("system/system.apk") .setTargeting(ApkTargeting.getDefaultInstance()) assertThat(systemApks) .containsExactly( ApkDescription.newBuilder() .setPath("system/system.apk") .setTargeting(ApkTargeting.getDefaultInstance()) .addAllFusedModuleName(ImmutableList.of("base", "fused"))) .build(), ApkDescription.newBuilder() .setPath("system/system.apk.gz") .setTargeting(ApkTargeting.getDefaultInstance())
Maps.uniqueIndex( apkDescriptions(standaloneApkVariants(result)), apkDesc -> getOnlyElement(apkDesc.getTargeting().getAbiTargeting().getValueList())); apkSetFile, standaloneApksByAbi.get(toAbi(AbiAlias.X86)).getPath(), outputDir); try (ZipFile x86Zip = new ZipFile(x86ApkFile)) { apkSetFile, standaloneApksByAbi.get(toAbi(AbiAlias.X86_64)).getPath(), outputDir); try (ZipFile x64Zip = new ZipFile(x64ApkFile)) {
ApkSet apkSet = getOnlyElement(variant.getApkSetList()); ApkDescription apkDescription = getOnlyElement(apkSet.getApkDescriptionList()); assertThat(apkSetFile).hasFile(apkDescription.getPath());
Maps.uniqueIndex( apkDescriptions(systemVariant), apkDescription -> apkDescription.getSystemApkMetadata().getSystemApkType()); assertThat(apkTypeApkMap.keySet()) .containsExactly(SystemApkType.SYSTEM_STUB, SystemApkType.SYSTEM_COMPRESSED); assertThat(stubSystemApk.getTargeting()).isEqualToDefaultInstance(); File systemApkFile = extractFromApkSetFile(apkSetFile, stubSystemApk.getPath(), outputDir); try (ZipFile systemApkZipFile = new ZipFile(systemApkFile)) { assertThat(systemApkZipFile) Path compressedSystemApkFile = uncompressGzipFile( extractFromApkSetFile(apkSetFile, compressedSystemApk.getPath(), outputDir).toPath(), outputDir.resolve("output.apk")); try (ZipFile compressedSystemApkZipFile = new ZipFile(compressedSystemApkFile.toFile())) {
.forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
ApkDescription shard = apkDescriptions(standaloneApkVariants(result)).get(0); assertThat(apkSetFile).hasFile(shard.getPath()); try (ZipFile shardZip = new ZipFile(extractFromApkSetFile(apkSetFile, shard.getPath(), outputDir))) { assertThat(shardZip).hasFile("classes.dex"); assertThat(shardZip).hasFile("classes2.dex");
apkDescriptions(standaloneApkVariants(result).get(0)); assertThat(standaloneApks).hasSize(1); assertThat(standaloneApks.get(0).hasStandaloneApkMetadata()).isTrue(); assertThat(standaloneApks.get(0).getStandaloneApkMetadata().getFusedModuleNameList()) .containsExactly("base", "fused"); File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApks.get(0).getPath(), outputDir);
ApkDescription apkDescription = getOnlyElement(apkDescriptions(variant)); return getOnlyElement( apkDescription.getTargeting().getAbiTargeting().getValueList()); }); ApkDescription apkDescription = apkDescriptions(variant).get(0); return getOnlyElement( apkDescription.getTargeting().getAbiTargeting().getValueList()); }); apkSet .getApkDescriptionList() .forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
variant -> { ApkDescription apkDescription = getOnlyElement(apkDescriptions(variant)); return getOnlyElement(apkDescription.getTargeting().getAbiTargeting().getValueList()); }); assertThat(standaloneVariantsByAbi.keySet()) ApkSet apkSet = variant.getApkSet(0); assertThat(apkSet.getApkDescriptionList()).hasSize(1); assertThat(apkSetFile).hasFile(apkSet.getApkDescription(0).getPath());
assertThat(universalApk.getStandaloneApkMetadata().getFusedModuleNameList()) .containsExactly("base", "feature"); File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir); try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) { assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("assets")))
assertThat(universalApk.getTargeting()).isEqualToDefaultInstance(); File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir); try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) { assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("lib")))
assertThat(systemApk.getTargeting()).isEqualToDefaultInstance(); File systemApkFile = extractFromApkSetFile(apkSetFile, systemApk.getPath(), outputDir); try (ZipFile systemApkZipFile = new ZipFile(systemApkFile)) {
assertThat(baseSplits.getModuleMetadata().getOnDemand()).isFalse(); assertThat(baseSplits.getApkDescriptionList()).hasSize(1); assertThat(apkSetFile).hasFile(baseSplits.getApkDescription(0).getPath()); assertThat(onDemandSplits.getModuleMetadata().getOnDemand()).isTrue(); assertThat(onDemandSplits.getApkDescriptionList()).hasSize(1); assertThat(apkSetFile).hasFile(onDemandSplits.getApkDescription(0).getPath());
Maps.uniqueIndex( apkDescriptions(splitApkVariants(result)), apkDesc -> apkDesc.getTargeting().getAbiTargeting()); assertThat(splitApksByAbiTargeting.keySet()) .containsExactly(AbiTargeting.getDefaultInstance(), abiTargeting(AbiAlias.X86)); assertThat(standaloneApks.get(0).getTargeting().getAbiTargeting()) .isEqualTo(abiTargeting(AbiAlias.X86, ImmutableSet.of())); File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApks.get(0).getPath(), outputDir); try (ZipFile standaloneApkZipFile = new ZipFile(standaloneApkFile)) { assertThat(filesUnderPath(standaloneApkZipFile, ZipPath.create("lib")))
assertThat(apkSetFile).hasFile(shard.getPath()); assertThat(ZipPath.create(shard.getPath()).getFileName()) .isEqualTo(ZipPath.create("standalone.apk")); try (ZipFile shardZip = new ZipFile(extractFromApkSetFile(apkSetFile, shard.getPath(), outputDir))) { assertThat(shardZip).hasFile("classes.dex"); byte[] mergedDexData =
variant -> getOnlyElement(getOnlyElement(variant.getApkSetList()).getApkDescriptionList()) .getPath()) .collect(toImmutableSet()); assertThat(apkPaths)