use of com.android.bundle.Targeting.SdkVersion 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.SdkVersion 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.SdkVersion 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))));
}
use of com.android.bundle.Targeting.SdkVersion in project bundletool by google.
the class SdkVersionMatcher method matchesTargeting.
@Override
public boolean matchesTargeting(SdkVersionTargeting targeting) {
checkArgument(targeting.getValueCount() <= 1, "Found more than one SDK version value in the variant targeting.");
SdkVersion sdkValue = targeting.getValueCount() == 0 ? SdkVersion.getDefaultInstance() : targeting.getValue(0);
if (!matchesDeviceSdk(sdkValue, deviceSdkVersion)) {
return false;
}
// Check if there is a better match among alternatives.
for (SdkVersion alternativeSdkValue : targeting.getAlternativesList()) {
if (isBetterSdkMatch(/* candidate= */
alternativeSdkValue, /* contestedValue= */
sdkValue, deviceSdkVersion)) {
return false;
}
}
return true;
}
use of com.android.bundle.Targeting.SdkVersion in project bundletool by google.
the class SdkVersionMatcher method checkDeviceCompatibleInternal.
@Override
protected void checkDeviceCompatibleInternal(SdkVersionTargeting targeting) {
SdkVersion sdkValue = targeting.getValueCount() == 0 ? SdkVersion.getDefaultInstance() : targeting.getValue(0);
boolean anyMatch = Stream.concat(Stream.of(sdkValue), targeting.getAlternativesList().stream()).anyMatch(sdkVal -> matchesDeviceSdk(sdkVal, deviceSdkVersion));
if (!anyMatch) {
throw IncompatibleDeviceException.builder().withUserMessage("The app doesn't support SDK version of the device: (%d).", getDeviceSpec().getSdkVersion()).build();
}
}
Aggregations