Search in sources :

Example 56 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ExtractApksCommandTest method conditionalModule_deviceMatching.

@Test
public void conditionalModule_deviceMatching() 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(24), deviceFeatures("android.hardware.camera.ar"));
    ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).build().execute();
    assertThat(matchedApks).containsExactly(inOutputDirectory(apkConditional), 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 57 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec 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 58 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec 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 59 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec 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 60 with DeviceSpec

use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.

the class ExtractApksCommandTest method builderAndFlagsConstruction_optionalInstantFalse_equivalent.

@Test
public void builderAndFlagsConstruction_optionalInstantFalse_equivalent() throws Exception {
    DeviceSpec deviceSpec = deviceWithSdk(21);
    Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
    BuildApksResult tableOfContentsProto = minimalApkSet();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ExtractApksCommand fromFlags = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile));
    ExtractApksCommand fromBuilderApi = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setInstant(false).build();
    assertThat(fromFlags).isEqualTo(fromBuilderApi);
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Aggregations

DeviceSpec (com.android.bundle.Devices.DeviceSpec)124 Test (org.junit.Test)113 Path (java.nio.file.Path)71 BuildApksResult (com.android.bundle.Commands.BuildApksResult)68 ZipPath (com.android.tools.build.bundletool.model.ZipPath)64 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)19 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)18 AdbServer (com.android.tools.build.bundletool.device.AdbServer)15 ImmutableSet (com.google.common.collect.ImmutableSet)14 Theory (org.junit.experimental.theories.Theory)13 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)12 Variant (com.android.bundle.Commands.Variant)11 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)11 ZipFile (java.util.zip.ZipFile)11 ApkSet (com.android.bundle.Commands.ApkSet)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)7 PrintStream (java.io.PrintStream)7