Search in sources :

Example 26 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class AlternativeVariantTargetingPopulatorTest method splitAndStandalones_addsAlternatives.

@Test
public void splitAndStandalones_addsAlternatives() throws Exception {
    SdkVersion lPlusVersion = sdkVersionFrom(Versions.ANDROID_L_API_VERSION);
    VariantTargeting lPlusTargeting = variantSdkTargeting(lPlusVersion);
    VariantTargeting emptySdkTargeting = variantSdkTargeting(SdkVersion.getDefaultInstance());
    // Post-L splits with 2 modules.
    ImmutableList<ModuleSplit> postLSplits = ImmutableList.of(createModuleSplit(lPlusTargeting), createModuleSplit(lPlusTargeting));
    // 3 density shards.
    ImmutableList<ModuleSplit> standaloneShards = ImmutableList.of(createStandaloneModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.MDPI))), createStandaloneModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.HDPI))), createStandaloneModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.XHDPI))));
    GeneratedApks generatedApks = GeneratedApks.builder().setStandaloneApks(standaloneShards).setSplitApks(postLSplits).build();
    GeneratedApks processedApks = AlternativeVariantTargetingPopulator.populateAlternativeVariantTargeting(generatedApks);
    assertThat(processedApks.size()).isEqualTo(5);
    ImmutableCollection<ModuleSplit> processedShards = processedApks.getStandaloneApks();
    assertThat(processedShards).hasSize(3);
    assertThat(processedShards.stream().map(ModuleSplit::getVariantTargeting).collect(toImmutableSet())).containsExactly(mergeVariantTargeting(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(lPlusVersion)), variantDensityTargeting(DensityAlias.MDPI, ImmutableSet.of(DensityAlias.HDPI, DensityAlias.XHDPI))), mergeVariantTargeting(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(lPlusVersion)), variantDensityTargeting(DensityAlias.HDPI, ImmutableSet.of(DensityAlias.MDPI, DensityAlias.XHDPI))), mergeVariantTargeting(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(lPlusVersion)), variantDensityTargeting(DensityAlias.XHDPI, ImmutableSet.of(DensityAlias.MDPI, DensityAlias.HDPI))));
}
Also used : GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) SdkVersion(com.android.bundle.Targeting.SdkVersion) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Test(org.junit.Test)

Example 27 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class AssetModuleSizeAggregatorTest method getSize_multipleAssetModules_withDeviceSpecAndVariantTargeting.

@Test
public void getSize_multipleAssetModules_withDeviceSpecAndVariantTargeting() throws Exception {
    ImmutableList<AssetSliceSet> assetModules = ImmutableList.of(ASSET_MODULE_1, ASSET_MODULE_2);
    VariantTargeting variantTargeting = variantTextureTargeting(ETC2);
    ConfigurationSizes configurationSizes = new AssetModuleSizeAggregator(assetModules, variantTargeting, SIZE_BY_APK_PATHS, getSizeCommand.setDimensions(ImmutableSet.of(TEXTURE_COMPRESSION_FORMAT, SDK)).setDeviceSpec(sdkVersion(21)).build()).getSize();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setTextureCompressionFormat("etc2").setSdkVersion("21").build(), ASSET_1_MASTER_SIZE + ASSET_1_ETC2_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ETC2_SIZE);
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setTextureCompressionFormat("etc2").setSdkVersion("21").build(), ASSET_1_MASTER_SIZE + ASSET_1_ETC2_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ETC2_SIZE);
}
Also used : ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) ApksArchiveHelpers.createAssetSliceSet(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) Test(org.junit.Test)

Example 28 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class SameTargetingMerger method mergeSplits.

private ModuleSplit mergeSplits(ImmutableCollection<ModuleSplit> splits) {
    ModuleSplit.Builder builder = ModuleSplit.builder();
    ImmutableList.Builder<ModuleEntry> entries = ImmutableList.builder();
    AndroidManifest mergedManifest = null;
    ResourceTable mergedResourceTable = null;
    NativeLibraries mergedNativeConfig = null;
    Map<String, TargetedAssetsDirectory> mergedAssetsConfig = new HashMap<>();
    ApexImages mergedApexConfig = null;
    ImmutableList<ApexEmbeddedApkConfig> mergedApexEmbeddedApkConfigs = null;
    BundleModuleName mergedModuleName = null;
    Boolean mergedIsMasterSplit = null;
    VariantTargeting mergedVariantTargeting = null;
    for (ModuleSplit split : splits) {
        mergedManifest = getSameValueOrNonNull(mergedManifest, split.getAndroidManifest()).orElseThrow(() -> new IllegalStateException("Encountered two distinct manifests while merging."));
        if (split.getResourceTable().isPresent()) {
            mergedResourceTable = getSameValueOrNonNull(mergedResourceTable, split.getResourceTable().get()).orElseThrow(() -> new IllegalStateException("Unsupported case: encountered two distinct resource tables while " + "merging."));
        }
        if (split.getNativeConfig().isPresent()) {
            mergedNativeConfig = getSameValueOrNonNull(mergedNativeConfig, split.getNativeConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct native configs while merging."));
        }
        if (split.getApexConfig().isPresent()) {
            mergedApexConfig = getSameValueOrNonNull(mergedApexConfig, split.getApexConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex configs while merging."));
        }
        mergedApexEmbeddedApkConfigs = getSameValueOrNonNull(mergedApexEmbeddedApkConfigs, split.getApexEmbeddedApkConfigs()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex embedded apk configs while merging."));
        mergedModuleName = getSameValueOrNonNull(mergedModuleName, split.getModuleName()).orElseThrow(() -> new IllegalStateException("Encountered two distinct module names while merging."));
        mergedIsMasterSplit = getSameValueOrNonNull(mergedIsMasterSplit, Boolean.valueOf(split.isMasterSplit())).orElseThrow(() -> new IllegalStateException("Encountered conflicting isMasterSplit flag values while merging."));
        mergedVariantTargeting = getSameValueOrNonNull(mergedVariantTargeting, split.getVariantTargeting()).orElseThrow(() -> new IllegalStateException("Encountered conflicting variant targeting values while merging."));
        entries.addAll(split.getEntries());
        builder.setApkTargeting(split.getApkTargeting());
        split.getAssetsConfig().ifPresent(assetsConfig -> {
            mergeTargetedAssetsDirectories(mergedAssetsConfig, assetsConfig.getDirectoryList());
        });
    }
    if (mergedManifest != null) {
        builder.setAndroidManifest(mergedManifest);
    }
    if (mergedResourceTable != null) {
        builder.setResourceTable(mergedResourceTable);
    }
    if (mergedNativeConfig != null) {
        builder.setNativeConfig(mergedNativeConfig);
    }
    if (!mergedAssetsConfig.isEmpty()) {
        builder.setAssetsConfig(Assets.newBuilder().addAllDirectory(mergedAssetsConfig.values()).build());
    }
    if (mergedApexConfig != null) {
        builder.setApexConfig(mergedApexConfig);
    }
    if (mergedApexEmbeddedApkConfigs != null) {
        builder.setApexEmbeddedApkConfigs(mergedApexEmbeddedApkConfigs);
    }
    if (mergedModuleName != null) {
        builder.setModuleName(mergedModuleName);
    }
    if (mergedIsMasterSplit != null) {
        builder.setMasterSplit(mergedIsMasterSplit);
    }
    builder.setVariantTargeting(mergedVariantTargeting);
    builder.setEntries(entries.build());
    return builder.build();
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) TargetedAssetsDirectory(com.android.bundle.Files.TargetedAssetsDirectory) NativeLibraries(com.android.bundle.Files.NativeLibraries) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ApexEmbeddedApkConfig(com.android.bundle.Config.ApexEmbeddedApkConfig) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) ResourceTable(com.android.aapt.Resources.ResourceTable)

Example 29 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class TargetingNormalizerTest method normalizeVariantTargeting_allTargetingDimensionsAreHandled.

@Test
public void normalizeVariantTargeting_allTargetingDimensionsAreHandled() {
    VariantTargeting variantTargeting = ProtoFuzzer.randomProtoMessage(VariantTargeting.class);
    VariantTargeting shuffledVariantTargeting = ProtoFuzzer.shuffleRepeatedFields(variantTargeting);
    // Sanity-check that the testing data was generated alright.
    assertThat(variantTargeting).isNotEqualTo(shuffledVariantTargeting);
    // The following check fails, if the normalizing logic forgets to handle some dimension.
    // This would typically happen when the targeting proto is extended by a new dimension.
    assertThat(TargetingNormalizer.normalizeVariantTargeting(variantTargeting)).isEqualTo(TargetingNormalizer.normalizeVariantTargeting(shuffledVariantTargeting));
}
Also used : VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Test(org.junit.Test)

Example 30 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class StandaloneApksGeneratorTest method shardByAbi_havingManyAbis_producesManyApks.

@Test
public void shardByAbi_havingManyAbis_producesManyApks() throws Exception {
    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");
    }
    ApkTargeting armTargeting = apkAbiTargeting(ARMEABI, ImmutableSet.of(X86, X86_64));
    ApkTargeting x86Targeting = apkAbiTargeting(X86, ImmutableSet.of(ARMEABI, X86_64));
    ApkTargeting x64Targeting = apkAbiTargeting(X86_64, ImmutableSet.of(ARMEABI, X86));
    ImmutableMap<ApkTargeting, ModuleSplit> shardsByTargeting = Maps.uniqueIndex(shards, ModuleSplit::getApkTargeting);
    assertThat(shardsByTargeting.keySet()).containsExactly(armTargeting, x86Targeting, x64Targeting);
    assertThat(extractPaths(shardsByTargeting.get(armTargeting).getEntries())).contains("lib/armeabi/libtest.so");
    assertThat(extractPaths(shardsByTargeting.get(armTargeting).getEntries())).containsNoneOf("lib/x86/libtest.so", "lib/x86_64/libtest.so");
    assertThat(extractPaths(shardsByTargeting.get(x86Targeting).getEntries())).contains("lib/x86/libtest.so");
    assertThat(extractPaths(shardsByTargeting.get(x86Targeting).getEntries())).containsNoneOf("lib/armeabi/libtest.so", "lib/x86_64/libtest.so");
    assertThat(extractPaths(shardsByTargeting.get(x64Targeting).getEntries())).contains("lib/x86_64/libtest.so");
    assertThat(extractPaths(shardsByTargeting.get(x64Targeting).getEntries())).containsNoneOf("lib/armeabi/libtest.so", "lib/x86/libtest.so");
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) 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)

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