Search in sources :

Example 66 with ZipPath

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

the class ExtractApksCommandTest method bundleWithDeviceTierTargeting_noDeviceTierSpecified_usesDefaults.

@Test
public void bundleWithDeviceTierTargeting_noDeviceTierSpecified_usesDefaults() 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)))).addDefaultTargetingValue(DefaultTargetingValue.newBuilder().setDimension(Value.DEVICE_TIER).setDefaultValue("1")).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(baseHighApk));
    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 67 with ZipPath

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

the class ExtractApksCommandTest method oneModule_MipsDevice_noMatchingAbiSplit_throws.

@Test
public void oneModule_MipsDevice_noMatchingAbiSplit_throws() throws Exception {
    ZipPath apkL = ZipPath.create("splits/apkL.apk");
    ZipPath apkLx86 = ZipPath.create("splits/apkL-x86.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21)), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkL), createApkDescription(apkAbiTargeting(AbiAlias.X86, ImmutableSet.of()), apkLx86, /* isMasterSplit= */
    false)))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), abis("arm64-v8a"), locales("en-US"), density(DensityAlias.HDPI));
    ExtractApksCommand command = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).build();
    Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("The app doesn't support ABI architectures of the device. Device ABIs: [arm64-v8a], " + "app ABIs: [x86]");
}
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 68 with ZipPath

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

the class ExtractApksCommandTest method shortcutToExtractAllModules.

/**
 * Ensures that --modules=_ALL_ extracts all modules.
 */
@Test
public void shortcutToExtractAllModules() throws Exception {
    ZipPath apkBase = ZipPath.create("base-master.apk");
    ZipPath apkBaseXxhdpi = ZipPath.create("base-xxhdpi.apk");
    ZipPath apkFeature = ZipPath.create("feature-master.apk");
    ZipPath apkFeatureXxhdpi = ZipPath.create("feature-xxhdpi.apk");
    ZipPath apkFeature2 = ZipPath.create("feature2.apk");
    ZipPath apkFeature2Arm64 = ZipPath.create("feature2-arm64_v8a.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkBase), createApkDescription(apkDensityTargeting(XXHDPI), apkBaseXxhdpi, false)), createSplitApkSet("feature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature2"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature), createApkDescription(apkDensityTargeting(XXHDPI), apkFeatureXxhdpi, false)), createSplitApkSet("feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature2), createApkDescription(apkAbiTargeting(ARM64_V8A), apkFeature2Arm64, false)))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = deviceWithSdk(21);
    ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).setModules(ImmutableSet.of("_ALL_")).build().execute();
    assertThat(matchedApks).containsExactly(inOutputDirectory(apkBase), inOutputDirectory(apkBaseXxhdpi), inOutputDirectory(apkFeature), inOutputDirectory(apkFeatureXxhdpi), inOutputDirectory(apkFeature2), inOutputDirectory(apkFeature2Arm64));
    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 69 with ZipPath

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

the class ExtractApksCommandTest method oneModule_extractedToTemporaryDirectory.

@Test
public void oneModule_extractedToTemporaryDirectory() throws Exception {
    ZipPath apkOne = ZipPath.create("apk_one.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21)), ApkTargeting.getDefaultInstance(), apkOne)).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = deviceWithSdk(21);
    ExtractApksCommand command = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).build();
    ImmutableList<Path> matchedApks = command.execute();
    assertThat(matchedApks).hasSize(1);
    String apkOnePathPrefix = Paths.get(System.getProperty("java.io.tmpdir")).resolve("bundletool-extracted-apks").toString();
    assertThat(Iterables.getOnlyElement(matchedApks).toString()).startsWith(apkOnePathPrefix);
}
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 70 with ZipPath

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

the class ExtractApksCommandTest method extractInstant_withNoInstantModules.

@Test
public void extractInstant_withNoInstantModules() throws Exception {
    ZipPath apkPreL = ZipPath.create("apkPreL.apk");
    ZipPath apkLBase = ZipPath.create("apkL-base.apk");
    ZipPath apkLFeature = ZipPath.create("apkL-feature.apk");
    ZipPath apkLOther = ZipPath.create("apkL-other.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createStandaloneApkSet(ApkTargeting.getDefaultInstance(), apkPreL))).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLBase)), createSplitApkSet("feature", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLFeature)), createSplitApkSet("other", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkLOther)))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = deviceWithSdk(21);
    IncompatibleDeviceException exception = assertThrows(IncompatibleDeviceException.class, () -> ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setInstant(true).build().execute());
    assertThat(exception).hasMessageThat().contains("No compatible APKs found for the device");
}
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) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) 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