Search in sources :

Example 6 with VariantTargeting

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;
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) SuffixManager(com.android.tools.build.bundletool.model.SuffixManager) OptimizationDimension(com.android.tools.build.bundletool.model.OptimizationDimension) SdkVersion(com.android.bundle.Targeting.SdkVersion) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ImmutableCollection(com.google.common.collect.ImmutableCollection) TargetingUtils.getMinSdk(com.android.tools.build.bundletool.model.targeting.TargetingUtils.getMinSdk) SdkVersionTargeting(com.android.bundle.Targeting.SdkVersionTargeting) PIN_LOWEST_DENSITY_OF_EACH_STYLE_TO_MASTER(com.android.tools.build.bundletool.model.version.VersionGuardedFeature.PIN_LOWEST_DENSITY_OF_EACH_STYLE_TO_MASTER) SameTargetingMerger(com.android.tools.build.bundletool.mergers.SameTargetingMerger) ResourceId(com.android.tools.build.bundletool.model.ResourceId) ResourceTableEntry(com.android.tools.build.bundletool.model.ResourceTableEntry) ImmutableList(com.google.common.collect.ImmutableList) ManifestMutator(com.android.tools.build.bundletool.model.ManifestMutator) Predicates(com.google.common.base.Predicates) Version(com.android.tools.build.bundletool.model.version.Version) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Int32Value(com.google.protobuf.Int32Value) ImmutableSet(com.google.common.collect.ImmutableSet) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) Predicate(java.util.function.Predicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) StampType(com.android.tools.build.bundletool.model.SourceStamp.StampType) BundleMetadata(com.android.tools.build.bundletool.model.BundleMetadata) ANDROID_L_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_L_API_VERSION) TargetingProtoUtils.sdkVersionFrom(com.android.tools.build.bundletool.model.utils.TargetingProtoUtils.sdkVersionFrom) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleConfig(com.android.bundle.Config.BundleConfig) Optional(java.util.Optional) ManifestEditor(com.android.tools.build.bundletool.model.ManifestEditor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModule(com.android.tools.build.bundletool.model.BundleModule) TargetingProtoUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.model.utils.TargetingProtoUtils.lPlusVariantTargeting) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) SameTargetingMerger(com.android.tools.build.bundletool.mergers.SameTargetingMerger)

Example 7 with VariantTargeting

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();
}
Also used : SourceStamp(com.android.tools.build.bundletool.model.SourceStamp) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StampType(com.android.tools.build.bundletool.model.SourceStamp.StampType) Inject(javax.inject.Inject) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ImmutableList(com.google.common.collect.ImmutableList) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Optional(java.util.Optional) TargetingUtils.generateAllVariantTargetings(com.android.tools.build.bundletool.model.targeting.TargetingUtils.generateAllVariantTargetings) Version(com.android.tools.build.bundletool.model.version.Version) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModule(com.android.tools.build.bundletool.model.BundleModule) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Example 8 with VariantTargeting

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");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetingUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 9 with VariantTargeting

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");
    }
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 10 with VariantTargeting

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();
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

VariantTargeting (com.android.bundle.Targeting.VariantTargeting)37 Test (org.junit.Test)31 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)16 TargetingUtils.mergeVariantTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting)16 BundleModule (com.android.tools.build.bundletool.model.BundleModule)12 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)9 SdkVersion (com.android.bundle.Targeting.SdkVersion)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)5 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)5 GeneratedApks (com.android.tools.build.bundletool.model.GeneratedApks)5 TargetingUtils.lPlusVariantTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting)5 ImmutableList (com.google.common.collect.ImmutableList)5 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)4 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)3 BundleConfig (com.android.bundle.Config.BundleConfig)3 ApexImages (com.android.bundle.Files.ApexImages)3 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 ApexManifest (com.android.apex.ApexManifestProto.ApexManifest)2