Search in sources :

Example 6 with SdkVersion

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);
}
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 7 with SdkVersion

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))));
}
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 8 with SdkVersion

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))));
}
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 9 with SdkVersion

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;
}
Also used : SdkVersion(com.android.bundle.Targeting.SdkVersion)

Example 10 with SdkVersion

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();
    }
}
Also used : SdkVersion(com.android.bundle.Targeting.SdkVersion)

Aggregations

SdkVersion (com.android.bundle.Targeting.SdkVersion)12 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)10 TargetingUtils.mergeVariantTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting)10 Test (org.junit.Test)10 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)7 ApexManifest (com.android.apex.ApexManifestProto.ApexManifest)7 ApkVerifier (com.android.apksig.ApkVerifier)7 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)7 CodeTransparency (com.android.bundle.CodeTransparencyOuterClass.CodeTransparency)7 ApkDescription (com.android.bundle.Commands.ApkDescription)7 ApkSet (com.android.bundle.Commands.ApkSet)7 AssetModulesInfo (com.android.bundle.Commands.AssetModulesInfo)7 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)7 BuildApksResult (com.android.bundle.Commands.BuildApksResult)7 DefaultTargetingValue (com.android.bundle.Commands.DefaultTargetingValue)7 DeliveryType (com.android.bundle.Commands.DeliveryType)7 InstantMetadata (com.android.bundle.Commands.InstantMetadata)7 ModuleMetadata (com.android.bundle.Commands.ModuleMetadata)7 PermanentlyFusedModule (com.android.bundle.Commands.PermanentlyFusedModule)7 SplitApkMetadata (com.android.bundle.Commands.SplitApkMetadata)7