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