Search in sources :

Example 16 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method sdk_maxSdk_extraAlternativePopulated.

@Test
public void sdk_maxSdk_extraAlternativePopulated() {
    VariantTargeting lollipopTargeting = variantSdkTargeting(sdkVersionFrom(21));
    VariantTargeting marshmallowTargeting = variantSdkTargeting(sdkVersionFrom(23));
    ImmutableList<ModuleSplit> outputVariants = new SdkVersionAlternativesPopulator(Optional.of(/* maxSdkVersion= */
    25)).addAlternativeVariantTargeting(ImmutableList.of(createModuleSplit(lollipopTargeting), createModuleSplit(marshmallowTargeting)));
    ModuleSplit lollipopVariant = outputVariants.get(0);
    assertThat(lollipopVariant.getVariantTargeting()).ignoringRepeatedFieldOrder().isEqualTo(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(23), sdkVersionFrom(26))));
    ModuleSplit marshmallowVariant = outputVariants.get(1);
    assertThat(marshmallowVariant.getVariantTargeting()).ignoringRepeatedFieldOrder().isEqualTo(variantSdkTargeting(sdkVersionFrom(23), ImmutableSet.of(sdkVersionFrom(21), sdkVersionFrom(26))));
}
Also used : SdkVersionAlternativesPopulator(com.android.tools.build.bundletool.model.targeting.AlternativeVariantTargetingPopulator.SdkVersionAlternativesPopulator) 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 17 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method instantPassThrough.

@Test
public void instantPassThrough() throws Exception {
    SdkVersion lPlusVersion = sdkVersionFrom(Versions.ANDROID_L_API_VERSION);
    VariantTargeting lPlusTargeting = variantSdkTargeting(lPlusVersion);
    VariantTargeting emptySdkTargeting = variantSdkTargeting(SdkVersion.getDefaultInstance());
    // Post-L splits with 1 module.
    ImmutableList<ModuleSplit> postLSplits = ImmutableList.of(createModuleSplit(lPlusTargeting));
    // Post-L instant splits with 2 modules
    ImmutableList<ModuleSplit> instantSplits = ImmutableList.of(createModuleSplit(lPlusTargeting, SplitType.INSTANT), createModuleSplit(lPlusTargeting, SplitType.INSTANT));
    // 1 density shard.
    ImmutableList<ModuleSplit> standaloneShards = ImmutableList.of(createStandaloneModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.XHDPI))));
    GeneratedApks generatedApks = GeneratedApks.builder().setStandaloneApks(standaloneShards).setInstantApks(instantSplits).setSplitApks(postLSplits).build();
    GeneratedApks processedApks = AlternativeVariantTargetingPopulator.populateAlternativeVariantTargeting(generatedApks);
    assertThat(processedApks.size()).isEqualTo(4);
    ImmutableCollection<ModuleSplit> processedSplits = processedApks.getSplitApks();
    assertThat(processedSplits).hasSize(1);
    ImmutableCollection<ModuleSplit> processedShards = processedApks.getStandaloneApks();
    assertThat(processedShards).hasSize(1);
    ImmutableCollection<ModuleSplit> processedInstantSplits = processedApks.getInstantApks();
    assertThat(processedInstantSplits).containsExactlyElementsIn(instantSplits);
}
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 18 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method archivedApksPassThrough.

@Test
public void archivedApksPassThrough() {
    VariantTargeting emptySdkTargeting = variantSdkTargeting(SdkVersion.getDefaultInstance());
    ImmutableList<ModuleSplit> archivedSplits = ImmutableList.of(createModuleSplit(emptySdkTargeting, SplitType.ARCHIVE));
    GeneratedApks generatedApks = GeneratedApks.builder().setArchivedApks(archivedSplits).build();
    GeneratedApks processedApks = AlternativeVariantTargetingPopulator.populateAlternativeVariantTargeting(generatedApks);
    assertThat(processedApks.size()).isEqualTo(1);
    assertThat(processedApks.getInstantApks()).isEmpty();
    assertThat(processedApks.getStandaloneApks()).isEmpty();
    assertThat(processedApks.getSplitApks()).isEmpty();
    assertThat(processedApks.getSystemApks()).isEmpty();
    assertThat(processedApks.getArchivedApks()).isEqualTo(archivedSplits);
}
Also used : GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) 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 19 with VariantTargeting

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

the class SplitApksGenerator method generateVariants.

private ImmutableSet<VariantTargeting> generateVariants(ImmutableList<BundleModule> modules, ApkGenerationConfiguration apkGenerationConfiguration) {
    ImmutableSet.Builder<VariantTargeting> builder = ImmutableSet.builder();
    for (BundleModule module : modules) {
        ImmutableSet<VariantTargeting> splitApks = variantGenerator.generateVariants(module, apkGenerationConfiguration);
        builder.addAll(splitApks);
    }
    return generateAllVariantTargetings(builder.build());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Example 20 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method screenDensity_oneVariantDensityAgnostic_throws.

@Test
public void screenDensity_oneVariantDensityAgnostic_throws() throws Exception {
    VariantTargeting ldpiTargeting = variantDensityTargeting(DensityAlias.LDPI);
    VariantTargeting nonDensityTargeting = variantSdkTargeting(sdkVersionFrom(21));
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new ScreenDensityAlternativesPopulator().addAlternativeVariantTargeting(ImmutableList.of(createModuleSplit(ldpiTargeting), createModuleSplit(nonDensityTargeting))));
    assertThat(exception).hasMessageThat().contains("Some variants are agnostic to the dimension, and some are not");
}
Also used : ScreenDensityAlternativesPopulator(com.android.tools.build.bundletool.model.targeting.AlternativeVariantTargetingPopulator.ScreenDensityAlternativesPopulator) TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) 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