use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_withAssetModules.
@Test
public void buildApksCommand_universal_withAssetModules() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("lib/x86/libsome.so").setManifest(androidManifest("com.test.app"))).addModule("upfront_asset_module", builder -> builder.addFile("assets/upfront_asset.jpg").setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery()))).addModule("on_demand_asset_module", builder -> builder.addFile("assets/on_demand_asset.jpg").setManifest(androidManifestForAssetModule("com.test.app", withOnDemandDelivery()))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(universalVariant.getTargeting()).isEqualTo(UNRESTRICTED_VARIANT_TARGETING);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
assertThat(universalApk.getTargeting()).isEqualToDefaultInstance();
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("lib"))).containsExactly("lib/x86/libsome.so");
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("assets"))).containsExactly("assets/upfront_asset.jpg");
}
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTextureTargetingInDifferentPacksWithSameFolderName.
@Test
public void buildApksCommand_standalone_mixedTextureTargetingInDifferentPacksWithSameFolderName() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("feature_tcf_assets", builder -> builder.addFile("assets/textures/untargeted_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", assetsDirectoryTargeting(alternativeTextureCompressionTargeting(ETC1_RGB8))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifest("com.test.app", withDelivery(DeliveryType.INSTALL_TIME), withFusingAttribute(true)))).addModule("feature_assets_without_tcf", builder -> builder.addFile("assets/textures/another_untargeted_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", AssetsDirectoryTargeting.getDefaultInstance()))).setManifest(androidManifest("com.test.app", withDelivery(DeliveryType.INSTALL_TIME), withFusingAttribute(true)))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false, /* stripSuffix= */
true, /* defaultSuffix= */
"").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(TEXTURE_COMPRESSION_FORMAT).build());
InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> buildApksManager.execute());
assertThat(e).hasMessageThat().contains("Encountered conflicting targeting values while merging assets config.");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method deviceGroupTargetedConditionalModule.
@Test
public void deviceGroupTargetedConditionalModule() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("device_tier_feature", builder -> builder.setManifest(androidManifest("com.test", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withFusingAttribute(false), withDeviceGroupsCondition(ImmutableList.of("group1", "group2"))))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ModuleMetadata deviceTierModule = result.getVariantList().stream().flatMap(variant -> variant.getApkSetList().stream()).map(ApkSet::getModuleMetadata).filter(moduleMetadata -> moduleMetadata.getName().equals("device_tier_feature")).distinct().collect(onlyElement());
assertThat(deviceTierModule.getTargeting()).isEqualTo(moduleDeviceGroupsTargeting("group1", "group2"));
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_generatesSingleApkWithSingleFallbackTcf.
@Test
public void buildApksCommand_universal_generatesSingleApkWithSingleFallbackTcf() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("tcf_assets", builder -> builder.addFile("assets/textures/fallback_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", assetsDirectoryTargeting(alternativeTextureCompressionTargeting(ETC1_RGB8))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery()))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Check APK content
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
// Only the requested format texture is included in the standalone APK.
// Even if suffix stripping is not activated, the universal APK must only contain one TCF.
assertThat(filesUnderPath(universalApkZipFile, ASSETS_DIRECTORY)).containsExactly("assets/textures/fallback_texture.dat");
}
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_populatesDependencies.
@Test
public void buildApksCommand_populatesDependencies() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("feature1", builder -> builder.setManifest(androidManifest("com.test.app", withOnDemandAttribute(false), withFusingAttribute(true)))).addModule("feature2", builder -> builder.setManifest(androidManifest("com.test.app", withUsesSplit("feature1"), withOnDemandAttribute(false), withFusingAttribute(true)))).addModule("feature3", builder -> builder.setManifest(androidManifest("com.test.app", withUsesSplit("feature1", "feature2"), withOnDemandAttribute(false), withFusingAttribute(true)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// split APKs
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApkVariant = splitApkVariants(result).get(0);
ImmutableMap<String, ApkSet> splitApkSetByModuleName = Maps.uniqueIndex(splitApkVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName());
assertThat(splitApkSetByModuleName).hasSize(4);
ApkSet baseSplits = splitApkSetByModuleName.get("base");
assertThat(baseSplits.getModuleMetadata().getDependenciesList()).isEmpty();
ApkSet feature1Splits = splitApkSetByModuleName.get("feature1");
assertThat(feature1Splits.getModuleMetadata().getDependenciesList()).isEmpty();
ApkSet feature2Splits = splitApkSetByModuleName.get("feature2");
assertThat(feature2Splits.getModuleMetadata().getDependenciesList()).containsExactly("feature1");
ApkSet feature3Splits = splitApkSetByModuleName.get("feature3");
assertThat(feature3Splits.getModuleMetadata().getDependenciesList()).containsExactly("feature1", "feature2");
// standalone APK
assertThat(standaloneApkVariants(result)).hasSize(1);
List<ApkSet> apkSetList = standaloneApkVariants(result).get(0).getApkSetList();
assertThat(apkSetList).hasSize(1);
assertThat(apkSetList.get(0).getModuleMetadata().getDependenciesList()).isEmpty();
}
Aggregations