use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BundleConfigValidatorTest method optimizations_defaultDeviceTier_targeted_specified.
@Test
public void optimizations_defaultDeviceTier_targeted_specified() throws Exception {
AppBundleBuilder appBundleBuilder = new AppBundleBuilder().setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.DEVICE_TIER, false, false, "1").build()).addModule(new BundleModuleBuilder("base").addFile("assets/textures#tier_1/level1.assets").addFile("assets/textures#tier_2/level1.assets").setManifest(androidManifest("com.test.app")).build());
new BundleConfigValidator().validateBundle(appBundleBuilder.build());
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_splitApks_twoModulesOneOnDemand.
@Test
public void buildApksCommand_splitApks_twoModulesOneOnDemand() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("onDemand", builder -> builder.setManifest(androidManifest("com.test.app", withOnDemandAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withFusingAttribute(true)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
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(2);
ApkSet baseSplits = splitApkSetByModuleName.get("base");
assertThat(baseSplits.getModuleMetadata().getName()).isEqualTo("base");
assertThat(baseSplits.getModuleMetadata().getDeliveryType()).isEqualTo(DeliveryType.INSTALL_TIME);
assertThat(baseSplits.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(baseSplits.getApkDescription(0).getPath());
ApkSet onDemandSplits = splitApkSetByModuleName.get("onDemand");
assertThat(onDemandSplits.getModuleMetadata().getName()).isEqualTo("onDemand");
assertThat(onDemandSplits.getModuleMetadata().getDeliveryType()).isEqualTo(DeliveryType.ON_DEMAND);
assertThat(onDemandSplits.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(onDemandSplits.getApkDescription(0).getPath());
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method defaultUncompressedLibraries_before_0_6_0_disabled_singleVariant.
@Test
public void defaultUncompressedLibraries_before_0_6_0_disabled_singleVariant() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("lib/x86/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifest("com.test.app"))).setBundleConfig(BundleConfigBuilder.create().setVersion("0.5.1").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
assertThat(splitApkVariants).hasSize(1);
assertThat(splitApkVariants.get(0).getTargeting().getSdkVersionTargeting()).isEqualTo(sdkVersionTargeting(L_SDK_VERSION, ImmutableSet.of(LOWEST_SDK_VERSION)));
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTextureTargetingWithFallbackAsDefault.
@Test
public void buildApksCommand_standalone_mixedTextureTargetingWithFallbackAsDefault() 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)))).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());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
assertThat(apkDescriptions(standaloneApkVariants(result))).hasSize(1);
ApkDescription shard = apkDescriptions(standaloneApkVariants(result)).get(0);
// Check APK content.
assertThat(apkSetFile).hasFile(shard.getPath());
try (ZipFile shardZip = new ZipFile(extractFromApkSetFile(apkSetFile, shard.getPath(), outputDir))) {
assertThat(shardZip).hasFile("assets/textures/untargeted_texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures#tcf_etc1/etc1_texture.dat");
}
// Check that no targeting was applied.
assertThat(Iterables.getOnlyElement(standaloneApkVariants(result)).getTargeting().hasTextureCompressionFormatTargeting()).isFalse();
assertThat(shard.getTargeting().hasTextureCompressionFormatTargeting()).isFalse();
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_persistentMode.
@Test
public void buildApksCommand_persistentMode() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.app", withInstant(true)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(PERSISTENT).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(splitApkVariants(result)).isNotEmpty();
assertThat(standaloneApkVariants(result)).isNotEmpty();
assertThat(systemApkVariants(result)).isEmpty();
assertThat(instantApkVariants(result)).isEmpty();
}
Aggregations