Search in sources :

Example 56 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath 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 57 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath 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 58 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class ExtractApksCommandTest method conditionalModule_deviceNotMatching.

@Test
public void conditionalModule_deviceNotMatching() throws Exception {
    ZipPath apkBase = ZipPath.create("apkL-base.apk");
    ZipPath apkConditional = ZipPath.create("apkN-conditional-module.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkBase)), createConditionalApkSet("conditional", mergeModuleTargeting(moduleMinSdkVersionTargeting(24), moduleFeatureTargeting("android.hardware.camera.ar")), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkConditional)))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = mergeSpecs(deviceWithSdk(21));
    ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).build().execute();
    assertThat(matchedApks).containsExactly(inOutputDirectory(apkBase));
    for (Path matchedApk : matchedApks) {
        checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 59 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class ExtractApksCommandTest method bundleWithDeviceTierTargeting_noDeviceTierSpecifiedNorDefault_usesZeroAsDefault.

@Test
public void bundleWithDeviceTierTargeting_noDeviceTierSpecifiedNorDefault_usesZeroAsDefault() throws Exception {
    ZipPath baseMasterApk = ZipPath.create("base-master.apk");
    ZipPath baseLowApk = ZipPath.create("base-tier_0.apk");
    ZipPath baseHighApk = ZipPath.create("base-tier_1.apk");
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseMasterApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1))), baseLowApk), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0))), baseHighApk)))).build();
    Path apksArchiveFile = createApksArchiveFile(buildApksResult, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = lDevice();
    ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).build().execute();
    // Master and high tier splits for base and asset module.
    assertThat(matchedApks).containsExactly(inOutputDirectory(baseMasterApk), inOutputDirectory(baseLowApk));
    for (Path matchedApk : matchedApks) {
        checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 60 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class ExtractApksCommandTest method moduleWithDependency_extractDependency.

@Test
public void moduleWithDependency_extractDependency() throws Exception {
    ZipPath apkBase = ZipPath.create("base-master.apk");
    ZipPath apkFeature1 = ZipPath.create("feature1-master.apk");
    ZipPath apkFeature2 = ZipPath.create("feature2-master.apk");
    ZipPath apkFeature3 = ZipPath.create("feature3-master.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkBase)), createSplitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature1)), createSplitApkSet(/* moduleName= */
    "feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature2)), createSplitApkSet(/* moduleName= */
    "feature3", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature2"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature3)))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = deviceWithSdk(21);
    ImmutableList<Path> apks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).setModules(ImmutableSet.of("feature2")).build().execute();
    assertThat(apks).containsExactly(inOutputDirectory(apkBase), inOutputDirectory(apkFeature1), inOutputDirectory(apkFeature2));
    for (Path apk : apks) {
        checkFileExistsAndReadable(tmpDir.resolve(apk));
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Aggregations

ZipPath (com.android.tools.build.bundletool.model.ZipPath)194 Test (org.junit.Test)154 BuildApksResult (com.android.bundle.Commands.BuildApksResult)106 Path (java.nio.file.Path)55 DeviceSpec (com.android.bundle.Devices.DeviceSpec)44 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)23 ImmutableSet (com.google.common.collect.ImmutableSet)23 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)19 Variant (com.android.bundle.Commands.Variant)16 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)15 BundleModule (com.android.tools.build.bundletool.model.BundleModule)13 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)10 Theory (org.junit.experimental.theories.Theory)10 AdbServer (com.android.tools.build.bundletool.device.AdbServer)9 IOException (java.io.IOException)9 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)8 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)8 UncheckedIOException (java.io.UncheckedIOException)8