Search in sources :

Example 21 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method splitAndStandalones_addsAlternatives_withMaxSdk.

@Test
public void splitAndStandalones_addsAlternatives_withMaxSdk() 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));
    // 2 density shards.
    ImmutableList<ModuleSplit> standaloneShards = ImmutableList.of(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, /* maxSdkVersion= */
    23);
    assertThat(processedApks.size()).isEqualTo(3);
    ImmutableCollection<ModuleSplit> processedShards = processedApks.getStandaloneApks();
    assertThat(processedShards).hasSize(2);
    assertThat(processedShards.stream().map(ModuleSplit::getVariantTargeting).collect(toImmutableSet())).containsExactly(mergeVariantTargeting(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(lPlusVersion, sdkVersionFrom(24))), variantDensityTargeting(DensityAlias.HDPI, ImmutableSet.of(DensityAlias.XHDPI))), mergeVariantTargeting(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(lPlusVersion, sdkVersionFrom(24))), variantDensityTargeting(DensityAlias.XHDPI, ImmutableSet.of(DensityAlias.HDPI))));
    assertThat(processedApks.getSplitApks()).hasSize(1);
    assertThat(processedApks.getSplitApks().get(0).getVariantTargeting()).ignoringRepeatedFieldOrder().isEqualTo(variantSdkTargeting(lPlusVersion, ImmutableSet.of(SdkVersion.getDefaultInstance(), sdkVersionFrom(24))));
}
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 22 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method abi_oneVariantAbiAgnostic_throws.

@Test
public void abi_oneVariantAbiAgnostic_throws() throws Exception {
    VariantTargeting x86Targeting = variantAbiTargeting(AbiAlias.X86);
    VariantTargeting nonAbiTargeting = variantSdkTargeting(sdkVersionFrom(21));
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new AbiAlternativesPopulator().addAlternativeVariantTargeting(ImmutableList.of(createModuleSplit(x86Targeting), createModuleSplit(nonAbiTargeting))));
    assertThat(exception).hasMessageThat().contains("Some variants are agnostic to the dimension, and some are not");
}
Also used : TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) AbiAlternativesPopulator(com.android.tools.build.bundletool.model.targeting.AlternativeVariantTargetingPopulator.AbiAlternativesPopulator) Test(org.junit.Test)

Example 23 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method sdk_oneVariantSdkAgnostic_throws.

@Test
public void sdk_oneVariantSdkAgnostic_throws() throws Exception {
    VariantTargeting lPlusTargeting = variantSdkTargeting(sdkVersionFrom(21));
    VariantTargeting nonSdkTargeting = variantAbiTargeting(AbiAlias.X86);
    IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new SdkVersionAlternativesPopulator().addAlternativeVariantTargeting(ImmutableList.of(createModuleSplit(lPlusTargeting), createModuleSplit(nonSdkTargeting))));
    assertThat(exception).hasMessageThat().contains("Some variants are agnostic to the dimension, and some are not");
}
Also used : SdkVersionAlternativesPopulator(com.android.tools.build.bundletool.model.targeting.AlternativeVariantTargetingPopulator.SdkVersionAlternativesPopulator) TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Test(org.junit.Test)

Example 24 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method systemApksPassThrough.

@Test
public void systemApksPassThrough() {
    VariantTargeting emptySdkTargeting = variantSdkTargeting(SdkVersion.getDefaultInstance());
    ImmutableList<ModuleSplit> systemSplits = ImmutableList.of(createModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.LDPI)), SplitType.SYSTEM));
    GeneratedApks generatedApks = GeneratedApks.builder().setSystemApks(systemSplits).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.getArchivedApks()).isEmpty();
    assertThat(processedApks.getSystemApks()).isEqualTo(systemSplits);
}
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 25 with VariantTargeting

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

the class AlternativeVariantTargetingPopulatorTest method abi_alternativesPopulated.

@Test
public void abi_alternativesPopulated() throws Exception {
    VariantTargeting x86Targeting = variantAbiTargeting(AbiAlias.X86);
    VariantTargeting x64Targeting = variantAbiTargeting(AbiAlias.X86_64);
    VariantTargeting defaultAbiTargeting = variantAbiTargeting(Abi.getDefaultInstance());
    ImmutableList<ModuleSplit> outputSplits = new AbiAlternativesPopulator().addAlternativeVariantTargeting(ImmutableList.of(createModuleSplit(x86Targeting), createModuleSplit(x64Targeting), createModuleSplit(defaultAbiTargeting)));
    assertThat(outputSplits).hasSize(3);
    ModuleSplit x86VariantNew = outputSplits.get(0);
    assertThat(x86VariantNew.getVariantTargeting()).ignoringRepeatedFieldOrder().isEqualTo(variantAbiTargeting(toAbi(AbiAlias.X86), ImmutableSet.of(Abi.getDefaultInstance(), toAbi(AbiAlias.X86_64))));
    ModuleSplit x64VariantNew = outputSplits.get(1);
    assertThat(x64VariantNew.getVariantTargeting()).ignoringRepeatedFieldOrder().isEqualTo(variantAbiTargeting(toAbi(AbiAlias.X86_64), ImmutableSet.of(Abi.getDefaultInstance(), toAbi(AbiAlias.X86))));
    ModuleSplit defaultAbiVariantNew = outputSplits.get(2);
    assertThat(defaultAbiVariantNew.getVariantTargeting()).ignoringRepeatedFieldOrder().isEqualTo(variantAbiTargeting(Abi.getDefaultInstance(), ImmutableSet.of(toAbi(AbiAlias.X86), toAbi(AbiAlias.X86_64))));
}
Also used : ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) AbiAlternativesPopulator(com.android.tools.build.bundletool.model.targeting.AlternativeVariantTargetingPopulator.AbiAlternativesPopulator) 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