Search in sources :

Example 81 with DeviceSpec

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

the class ExtractApksCommandTest method incompleteApksFile_missingMatchedAbiSplit_throws.

@Test
public void incompleteApksFile_missingMatchedAbiSplit_throws() throws Exception {
    // Partial APK Set file where 'x86' split is included and 'x86_64' split is not included because
    // device spec sent to 'build-apks' command doesn't support it.
    // Next, device spec that should be matched to 'x86_64' split is provided to 'extract-apks'
    // command and command throws IncompatibleDeviceException.
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), splitApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), ZipPath.create("base-x86.apk"))))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContent, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = mergeSpecs(deviceWithSdk(21), abis("x86_64", "x86"));
    ExtractApksCommand command = ExtractApksCommand.builder().setDeviceSpec(deviceSpec).setApksArchivePath(apksArchiveFile).setOutputDirectory(tmpDir).build();
    IncompatibleDeviceException exception = assertThrows(IncompatibleDeviceException.class, command::execute);
    assertThat(exception).hasMessageThat().isEqualTo("Missing APKs for [ABI] dimensions in the module 'base' for the provided 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) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) Test(org.junit.Test)

Example 82 with DeviceSpec

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

the class ExtractApksCommandTest method oneModule_Kdevice_matchesPreLSplit.

@Test
@Theory
public void oneModule_Kdevice_matchesPreLSplit(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    ZipPath apkPreL = ZipPath.create("standalones/apkPreL.apk");
    ZipPath apkL = ZipPath.create("splits/apkL.apk");
    ZipPath apkM = ZipPath.create("splits/apkM.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(sdkVersionFrom(21), sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apkPreL)).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance(), sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apkL)).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(23), ImmutableSet.of(SdkVersion.getDefaultInstance(), sdkVersionFrom(21))), ApkTargeting.getDefaultInstance(), apkM)).build();
    Path apksPath = createApks(tableOfContentsProto, apksInDirectory);
    DeviceSpec deviceSpec = deviceWithSdk(19);
    ExtractApksCommand.Builder extractedApksCommand = ExtractApksCommand.builder().setApksArchivePath(apksPath).setDeviceSpec(deviceSpec);
    if (!apksInDirectory) {
        extractedApksCommand.setOutputDirectory(tmpDir);
    }
    ImmutableList<Path> matchedApks = extractedApksCommand.build().execute();
    if (apksInDirectory) {
        assertThat(matchedApks).containsExactly(inTempDirectory(apkPreL.toString()));
    } else {
        assertThat(matchedApks).containsExactly(inOutputDirectory(apkPreL.getFileName()));
    }
    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) Theory(org.junit.experimental.theories.Theory)

Example 83 with DeviceSpec

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

the class GetDeviceSpecCommandTest method oneDevice_badAbis_throws.

@Test
public void oneDevice_badAbis_throws() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis(), locales("en-US"));
    Path outputPath = tmp.getRoot().toPath().resolve("device.json");
    // We set up a fake ADB server because the real one won't work on Forge.
    GetDeviceSpecCommand command = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).build();
    Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
    assertThat(exception).hasMessageThat().contains("Error retrieving device ABIs");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) Test(org.junit.Test)

Example 84 with DeviceSpec

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

the class GetDeviceSpecCommandTest method oneDevice_badDensity_throws.

@Test
public void oneDevice_badDensity_throws() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(-1), abis("x86_64", "x86"), locales("en-US"));
    Path outputPath = tmp.getRoot().toPath().resolve("device.json");
    // We set up a fake ADB server because the real one won't work on Forge.
    GetDeviceSpecCommand command = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).build();
    Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
    assertThat(exception).hasMessageThat().contains("Error retrieving device density");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) Test(org.junit.Test)

Example 85 with DeviceSpec

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

the class GetDeviceSpecCommandTest method oneDevice_noDeviceId_works.

@Test
public void oneDevice_noDeviceId_works() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), abis("x86_64", "x86"), locales("en-GB"), density(360));
    Path outputPath = tmp.getRoot().toPath().resolve("device.json");
    // We set up a fake ADB server because the real one won't work on Forge.
    GetDeviceSpecCommand command = GetDeviceSpecCommand.builder().setAdbPath(adbPath).setAdbServer(fakeServerOneDevice(deviceSpec)).setOutputPath(outputPath).build();
    assertThat(command.execute()).isEqualTo(deviceSpec);
    try (Reader deviceSpecReader = BufferedIo.reader(outputPath)) {
        DeviceSpec.Builder writtenSpecBuilder = DeviceSpec.newBuilder();
        JsonFormat.parser().merge(deviceSpecReader, writtenSpecBuilder);
        assertThat(writtenSpecBuilder.build()).isEqualTo(deviceSpec);
    }
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) Reader(java.io.Reader) 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