use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class ModuleSplitter method runSplitters.
private ImmutableList<ModuleSplit> runSplitters() {
if (targetsOnlyPreL(module)) {
throw CommandExecutionException.builder().withInternalMessage("Cannot split module '%s' because it does not target devices on Android L or above.", module.getName()).build();
}
ImmutableList.Builder<ModuleSplit> splits = ImmutableList.builder();
// Resources splits.
SplittingPipeline resourcesPipeline = createResourcesSplittingPipeline();
splits.addAll(resourcesPipeline.split(ModuleSplit.forResources(module, variantTargeting)));
// Native libraries splits.
SplittingPipeline nativePipeline = createNativeLibrariesSplittingPipeline();
splits.addAll(nativePipeline.split(ModuleSplit.forNativeLibraries(module, variantTargeting)));
// Assets splits.
SplittingPipeline assetsPipeline = createAssetsSplittingPipeline();
splits.addAll(assetsPipeline.split(ModuleSplit.forAssets(module, variantTargeting)));
// Dex Files.
SplittingPipeline dexPipeline = createDexSplittingPipeline();
splits.addAll(dexPipeline.split(ModuleSplit.forDex(module, variantTargeting)));
// Other files.
splits.add(ModuleSplit.forRoot(module, variantTargeting));
// Merging and making a master split.
ImmutableList<ModuleSplit> mergedSplits = new SameTargetingMerger().merge(applyMasterManifestMutators(splits.build()));
// Check that we have only one split with default targeting - the master split.
ImmutableList<ModuleSplit> defaultTargetingSplits = mergedSplits.stream().filter(split -> split.getApkTargeting().equals(ApkTargeting.getDefaultInstance())).collect(toImmutableList());
checkState(defaultTargetingSplits.size() == 1, "Expected one split with default targeting.");
return mergedSplits;
}
use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class SplitApksGenerator method generateSplitApks.
private ImmutableList<ModuleSplit> generateSplitApks(ImmutableList<BundleModule> modules, ApkGenerationConfiguration apkGenerationConfiguration, VariantTargeting variantTargeting) {
ImmutableSet<String> allModuleNames = modules.stream().map(module -> module.getName().getName()).collect(toImmutableSet());
ImmutableList.Builder<ModuleSplit> splits = ImmutableList.builder();
for (BundleModule module : modules) {
ModuleSplitter moduleSplitter = ModuleSplitter.create(module, bundletoolVersion, appBundle, apkGenerationConfiguration, variantTargeting, allModuleNames, stampSource.map(SourceStamp::getSource), StampType.STAMP_TYPE_DISTRIBUTION_APK);
splits.addAll(moduleSplitter.splitModule());
}
return splits.build();
}
use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class SplitApksGeneratorTest method multipleModules_withOnlyBaseModuleWithNativeLibraries.
@Test
public void multipleModules_withOnlyBaseModuleWithNativeLibraries() throws Exception {
ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("assets/leftover.txt").addFile("lib/x86_64/libsome.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).build(), new BundleModuleBuilder("test").addFile("assets/test.txt").setManifest(androidManifest("com.test.app")).build());
ImmutableList<ModuleSplit> moduleSplits = splitApksGenerator.generateSplits(bundleModule, ApkGenerationConfiguration.builder().setEnableUncompressedNativeLibraries(true).build());
VariantTargeting lVariantTargeting = variantMinSdkTargeting(/* minSdkVersion= */
ANDROID_L_API_VERSION, /* alternativeSdkVersions...= */
ANDROID_M_API_VERSION);
VariantTargeting mVariantTargeting = variantMinSdkTargeting(/* minSdkVersion= */
ANDROID_M_API_VERSION, /* alternativeSdkVersions...= */
ANDROID_L_API_VERSION);
// 2 splits for L and M variants.
assertThat(moduleSplits).hasSize(4);
assertThat(moduleSplits.stream().map(ModuleSplit::getVariantTargeting).collect(toImmutableSet())).containsExactly(lVariantTargeting, mVariantTargeting);
ModuleSplit baseLModule = getModuleSplit(moduleSplits, lVariantTargeting, "base");
assertThat(baseLModule.getSplitType()).isEqualTo(SplitType.SPLIT);
assertThat(extractPaths(baseLModule.getEntries())).containsExactly("assets/leftover.txt", "lib/x86_64/libsome.so");
assertThat(getForceUncompressed(baseLModule, "lib/x86_64/libsome.so")).isFalse();
ModuleSplit testLModule = getModuleSplit(moduleSplits, lVariantTargeting, "test");
assertThat(testLModule.getSplitType()).isEqualTo(SplitType.SPLIT);
assertThat(extractPaths(testLModule.getEntries())).containsExactly("assets/test.txt");
ModuleSplit baseMModule = getModuleSplit(moduleSplits, mVariantTargeting, "base");
assertThat(baseMModule.getSplitType()).isEqualTo(SplitType.SPLIT);
assertThat(extractPaths(baseMModule.getEntries())).containsExactly("assets/leftover.txt", "lib/x86_64/libsome.so");
assertThat(getForceUncompressed(baseMModule, "lib/x86_64/libsome.so")).isTrue();
ModuleSplit testMModule = getModuleSplit(moduleSplits, mVariantTargeting, "test");
assertThat(testMModule.getSplitType()).isEqualTo(SplitType.SPLIT);
assertThat(extractPaths(testMModule.getEntries())).containsExactly("assets/test.txt");
}
use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbi_havingManyAbis_producesManyApks_withTransparency.
@Test
public void shardByAbi_havingManyAbis_producesManyApks_withTransparency() throws Exception {
TestComponent.useTestModule(this, TestModule.builder().withBundleConfig(bundleConfigNodexmergestrategy).withBundleMetadata(BUNDLE_METADATA_WITH_TRANSPARENCY).build());
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/armeabi/libtest.so").addFile("lib/x86/libtest.so").addFile("lib/x86_64/libtest.so").addFile("res/drawable/image.jpg").addFile("res/drawable-mdpi/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi", nativeDirectoryTargeting(ARMEABI)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(DEFAULT_DENSITY_VALUE, "res/drawable/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.ABI));
assertThat(shards).hasSize(3);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
VariantTargeting armVariantTargeting = mergeVariantTargeting(variantAbiTargeting(ARMEABI, ImmutableSet.of(X86, X86_64)), VARIANT_TARGETING_WITH_SDK_1);
VariantTargeting x86VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(ARMEABI, X86_64)), VARIANT_TARGETING_WITH_SDK_1);
VariantTargeting x64VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(ARMEABI, X86)), VARIANT_TARGETING_WITH_SDK_1);
assertThat(shards.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(armVariantTargeting, x64VariantTargeting, x86VariantTargeting);
for (ModuleSplit shard : shards) {
assertThat(extractPaths(shard.getEntries())).containsAtLeast("assets/file.txt", "dex/classes.dex", "res/drawable/image.jpg", "res/drawable-mdpi/image.jpg", "root/license.dat", "META-INF/code_transparency_signed.jwt");
}
}
use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class NativeLibsCompressionVariantGeneratorTest method variantsWithoutNativeLibs.
@Test
public void variantsWithoutNativeLibs() throws Exception {
NativeLibsCompressionVariantGenerator nativeLibsCompressionVariantGenerator = new NativeLibsCompressionVariantGenerator(ApkGenerationConfiguration.builder().setEnableUncompressedNativeLibraries(true).build());
BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("assets/leftover.txt").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).build();
ImmutableCollection<VariantTargeting> splits = nativeLibsCompressionVariantGenerator.generate(bundleModule).collect(toImmutableList());
assertThat(splits).isEmpty();
}
Aggregations