private ImmutableList<ModuleSplit> generateSplitsInternal( ImmutableList<BundleModule> modules, BundleMetadata bundleMetadata, ApkOptimizations apkOptimizations, Optional<DeviceSpec> deviceSpec) { BundleSharder bundleSharder = new BundleSharder(tempDir, bundleVersion, generate64BitShards, deviceSpec); ImmutableList<ModuleSplit> shardedApks = bundleSharder.shardBundle(modules, apkOptimizations.getSplitDimensions(), bundleMetadata); return setVariantTargetingAndSplitType(shardedApks, splitType); }
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(), DEFAULT_METADATA);
bundleSharder.shardBundle( ImmutableList.of(baseModule, featureModule1, featureModule2), ImmutableSet.of(OptimizationDimension.ABI),
@Test public void shardByDensity_havingNoResources_producesOneApk() throws Exception { BundleModule bundleModule = new BundleModuleBuilder("base") .addFile("assets/file.txt") .addFile("dex/classes.dex") .addFile("lib/x86/libtest.so") .addFile("root/license.dat") .setManifest(androidManifest("com.test.app")) .build(); ImmutableList<ModuleSplit> shards = bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.SCREEN_DENSITY), DEFAULT_METADATA); assertThat(shards).hasSize(1); ModuleSplit shard = shards.get(0); assertThat(shard.getApkTargeting()).isEqualToDefaultInstance(); assertThat(shard.getVariantTargeting()).isEqualToDefaultInstance(); Truth.assertThat(shard.getSplitType()).isEqualTo(SplitType.STANDALONE); assertThat(shard.getResourceTable()).isEmpty(); assertThat(extractPaths(shard.getEntries())) .containsExactly( "assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "root/license.dat"); }
@Test public void manyModulesShardByDensity_havingNoResources_producesOneApk() throws Exception { BundleModule baseModule = new BundleModuleBuilder("base") .addFile("dex/classes.dex") .addFile("root/license.dat") .setManifest(androidManifest("com.test.app")) .build(); BundleModule featureModule = new BundleModuleBuilder("feature") .addFile("assets/file.txt") .setManifest(androidManifest("com.test.app")) .build(); ImmutableList<ModuleSplit> shards = bundleSharder.shardBundle( ImmutableList.of(baseModule, featureModule), ImmutableSet.of(OptimizationDimension.SCREEN_DENSITY), DEFAULT_METADATA); assertThat(shards).hasSize(1); ModuleSplit fatShard = shards.get(0); assertThat(fatShard.getApkTargeting()).isEqualToDefaultInstance(); assertThat(fatShard.getVariantTargeting()).isEqualToDefaultInstance(); assertThat(fatShard.getSplitType()).isEqualTo(SplitType.STANDALONE); assertThat(extractPaths(fatShard.getEntries())) .containsExactly("assets/file.txt", "dex/classes.dex", "root/license.dat"); }
@Test public void manyModulesShardByAbiAndDensity_havingNoAbiAndNoResources_producesOneApk() throws Exception { BundleModule baseModule = new BundleModuleBuilder("base") .addFile("dex/classes.dex") .addFile("root/license.dat") .setManifest(androidManifest("com.test.app")) .build(); BundleModule featureModule = new BundleModuleBuilder("feature") .addFile("assets/file.txt") .setManifest(androidManifest("com.test.app")) .build(); ImmutableList<ModuleSplit> shards = bundleSharder.shardBundle( ImmutableList.of(baseModule, featureModule), ImmutableSet.of(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY), DEFAULT_METADATA); assertThat(shards).hasSize(1); ModuleSplit fatShard = shards.get(0); assertThat(fatShard.getApkTargeting()).isEqualToDefaultInstance(); assertThat(fatShard.getVariantTargeting()).isEqualToDefaultInstance(); assertThat(fatShard.getSplitType()).isEqualTo(SplitType.STANDALONE); assertThat(extractPaths(fatShard.getEntries())) .containsExactly("assets/file.txt", "dex/classes.dex", "root/license.dat"); }
@Test @Theory public void shardByAbiAndDensity_havingNoAbiAndNoResources_producesOneApk( @FromDataPoints("deviceSpecs") Optional<DeviceSpec> deviceSpec) throws Exception { bundleSharder = new BundleSharder( tmpDir, BundleToolVersion.getCurrentVersion(), /* generate64BitShards= */ true, deviceSpec); BundleModule bundleModule = new BundleModuleBuilder("base") .addFile("assets/file.txt") .addFile("dex/classes.dex") .addFile("root/license.dat") .setManifest(androidManifest("com.test.app")) .build(); ImmutableList<ModuleSplit> shards = bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY), DEFAULT_METADATA); assertThat(shards).hasSize(1); ModuleSplit fatShard = shards.get(0); assertThat(fatShard.getApkTargeting()).isEqualToDefaultInstance(); assertThat(fatShard.getVariantTargeting()).isEqualToDefaultInstance(); assertThat(fatShard.getSplitType()).isEqualTo(SplitType.STANDALONE); assertThat(extractPaths(fatShard.getEntries())) .containsExactly("assets/file.txt", "dex/classes.dex", "root/license.dat"); }
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.SCREEN_DENSITY),
@Test public void shardByAbi_64BitAbisDisabled_filteredOut() throws Exception { BundleModule bundleModule = new BundleModuleBuilder("base") .addFile("dex/classes.dex") .addFile("lib/x86/libtest.so") .addFile("lib/x86_64/libtest.so") .setManifest(androidManifest("com.test.app")) .setNativeConfig( nativeLibraries( targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))) .build(); BundleSharder bundleSharder = new BundleSharder( tmpDir, BundleToolVersion.getCurrentVersion(), /* generate64BitShards= */ false); ImmutableList<ModuleSplit> shards = bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.ABI), DEFAULT_METADATA); assertThat(shards).hasSize(1); ModuleSplit shard = shards.get(0); assertThat(shard.getSplitType()).isEqualTo(SplitType.STANDALONE); assertThat(shard.getVariantTargeting()).isEqualToDefaultInstance(); assertThat(extractPaths(shard.getEntries())) .containsAllOf("dex/classes.dex", "lib/x86/libtest.so"); assertThat(shard.getApkTargeting()).isEqualTo(apkAbiTargeting(X86)); }
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.SCREEN_DENSITY),
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY),
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.ABI),
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.ABI),
bundleSharder.shardBundle( ImmutableList.of(baseModule, featureModule), ImmutableSet.of(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY),
bundleSharder.shardBundle( ImmutableList.of(baseModule, featureModule1, featureModule2), ImmutableSet.of(OptimizationDimension.ABI),
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.ABI),
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(), DEFAULT_METADATA);
bundleSharder.shardBundle( ImmutableList.of(bundleModule), ImmutableSet.of(OptimizationDimension.ABI),
bundleSharder.shardBundle( ImmutableList.of(baseModule, featureModule), ImmutableSet.of(OptimizationDimension.SCREEN_DENSITY),
bundleSharder.shardBundle( ImmutableList.of(baseModule, featureModule), ImmutableSet.of(), DEFAULT_METADATA);