Search in sources :

Example 31 with Variant

use of com.android.bundle.Commands.Variant in project bundletool by google.

the class VariantMatcherTest method getAllMatchingVariants_apexVariants_fullDeviceSpec.

@Test
public void getAllMatchingVariants_apexVariants_fullDeviceSpec() {
    ZipPath x86Apk = ZipPath.create("standalone-x86.apk");
    ZipPath x64X86Apk = ZipPath.create("standalone-x86_64.x86.apk");
    ImmutableSet<ImmutableSet<AbiAlias>> x86Set = ImmutableSet.of(ImmutableSet.of(X86));
    ImmutableSet<ImmutableSet<AbiAlias>> x64X86Set = ImmutableSet.of(ImmutableSet.of(X86_64, X86));
    MultiAbiTargeting x86Targeting = multiAbiTargeting(x86Set, x64X86Set);
    MultiAbiTargeting x64X86Targeting = multiAbiTargeting(x64X86Set, x86Set);
    Variant x86Variant = multiAbiTargetingApexVariant(x86Targeting, x86Apk);
    Variant x64X86Variant = multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(ImmutableList.of(x86Variant, x64X86Variant)).build();
    assertThat(new VariantMatcher(abis("x86")).getAllMatchingVariants(buildApksResult)).containsExactly(x86Variant);
    assertThat(new VariantMatcher(abis("x86_64", "x86")).getAllMatchingVariants(buildApksResult)).containsExactly(x64X86Variant);
    assertThat(new VariantMatcher(abis("x86_64", "x86", "armeabi-v7a")).getAllMatchingVariants(buildApksResult)).containsExactly(x64X86Variant);
    // Other device specs don't affect the matching variant.
    assertThat(new VariantMatcher(mergeSpecs(abis("x86"), density(HDPI))).getAllMatchingVariants(buildApksResult)).containsExactly(x86Variant);
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) Test(org.junit.Test)

Example 32 with Variant

use of com.android.bundle.Commands.Variant in project bundletool by google.

the class VariantTotalSizeAggregatorTest method splitVariant_singleModule_SingleTargeting.

@Test
public void splitVariant_singleModule_SingleTargeting() {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))));
    ConfigurationSizes configurationSizes = new VariantTotalSizeAggregator(ImmutableMap.of("base-master.apk", 10L), BundleToolVersion.getCurrentVersion(), lVariant, getSizeCommand.build()).getSize();
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 10L);
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 10L);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) Test(org.junit.Test)

Example 33 with Variant

use of com.android.bundle.Commands.Variant in project bundletool by google.

the class VariantTotalSizeAggregatorTest method getSize_standaloneVariants_withAllDeviceSpecAndDimensions.

@Test
public void getSize_standaloneVariants_withAllDeviceSpecAndDimensions() {
    ZipPath apk = ZipPath.create("sample.apk");
    Variant variant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(15), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARM64_V8A, ImmutableSet.of(X86)), variantDensityTargeting(MDPI, ImmutableSet.of(XXHDPI, XXXHDPI))), ApkTargeting.getDefaultInstance(), apk);
    ConfigurationSizes configurationSizes = new VariantTotalSizeAggregator(ImmutableMap.of("sample.apk", 11L), BundleToolVersion.getCurrentVersion(), variant, getSizeCommand.setDimensions(ImmutableSet.of(ABI, SCREEN_DENSITY, LANGUAGE, SDK)).setDeviceSpec(mergeSpecs(locales("fr", "jp"), abis("arm64-v8a", "mips"), density(MDPI), sdkVersion(15))).build()).getSize();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).isEqualTo(configurationSizes.getMaxSizeConfigurationMap());
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setSdkVersion("15").setScreenDensity("160").setLocale("fr,jp").setAbi("arm64-v8a,mips").build(), 11L);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 34 with Variant

use of com.android.bundle.Commands.Variant in project bundletool by google.

the class VariantTotalSizeAggregatorTest method splitVariant_multipleModules_selectModules.

@Test
public void splitVariant_multipleModules_selectModules() {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature1-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature2", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("feature2-master.apk"))));
    ConfigurationSizes configurationSizes = new VariantTotalSizeAggregator(ImmutableMap.<String, Long>builder().put("base-master.apk", 10L).put("feature-master.apk", 15L).put("feature1-master.apk", 6L).put("feature2-master.apk", 4L).build(), BundleToolVersion.getCurrentVersion(), lVariant, getSizeCommand.setModules(ImmutableSet.of("base", "feature1")).build()).getSize();
    // base, feature1, feature2 (install-time) modules are selected.
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 20L);
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), 20L);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) Test(org.junit.Test)

Example 35 with Variant

use of com.android.bundle.Commands.Variant in project bundletool by google.

the class VariantTotalSizeAggregatorTest method splitVariant_singleModule_multipleTargeting_withIncompatibleAbiDeviceSpecs.

@Test
public void splitVariant_singleModule_multipleTargeting_withIncompatibleAbiDeviceSpecs() {
    Variant lVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21)), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("apkL.apk")), createApkDescription(apkAbiTargeting(AbiAlias.X86, ImmutableSet.of()), ZipPath.create("apkL-x86.apk"), /* isMasterSplit= */
    false)));
    VariantTotalSizeAggregator variantTotalSizeAggregator = new VariantTotalSizeAggregator(ImmutableMap.<String, Long>builder().put("apkL.apk", 10L).put("apkL-x86.apk", 6L).build(), BundleToolVersion.getCurrentVersion(), lVariant, getSizeCommand.setDeviceSpec(mergeSpecs(abis("arm64-v8a"), locales("en"), density(XHDPI))).build());
    Throwable exception = assertThrows(IncompatibleDeviceException.class, variantTotalSizeAggregator::getSize);
    assertThat(exception).hasMessageThat().contains("The app doesn't support ABI architectures of the device. Device ABIs: [arm64-v8a], " + "app ABIs: [x86]");
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Test(org.junit.Test)

Aggregations

Variant (com.android.bundle.Commands.Variant)134 Test (org.junit.Test)130 BuildApksResult (com.android.bundle.Commands.BuildApksResult)100 ZipPath (com.android.tools.build.bundletool.model.ZipPath)82 Path (java.nio.file.Path)80 ZipFile (java.util.zip.ZipFile)79 AppBundle (com.android.tools.build.bundletool.model.AppBundle)66 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)66 ApkSet (com.android.bundle.Commands.ApkSet)63 ApkDescription (com.android.bundle.Commands.ApkDescription)60 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)59 File (java.io.File)59 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)56 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)55 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)55 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)54 ApkSetUtils.parseTocFromFile (com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile)54 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)54 ImmutableSet (com.google.common.collect.ImmutableSet)54 ApkVerifier (com.android.apksig.ApkVerifier)53