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))));
}
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");
}
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");
}
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);
}
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))));
}
Aggregations