Search in sources :

Example 16 with InvalidCommandException

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

the class AddTransparencyCommandTest method execute_defaultMode_dexMergingChoiceReject_fail.

@Test
public void execute_defaultMode_dexMergingChoiceReject_fail() throws Exception {
    createBundle(bundlePath, /* hasSharedUserId= */
    false, /* minSdkVersion= */
    19);
    AddTransparencyCommand addTransparencyCommand = AddTransparencyCommand.builder().setMode(Mode.DEFAULT).setDexMergingChoice(DexMergingChoice.REJECT).setBundlePath(bundlePath).setOutputPath(outputBundlePath).setSignerConfig(signerConfig).build();
    InvalidCommandException exception = assertThrows(InvalidCommandException.class, addTransparencyCommand::execute);
    assertThat(exception).hasMessageThat().contains("'add-transparency' command is rejected");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) Test(org.junit.Test)

Example 17 with InvalidCommandException

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

the class BuildApksCommandTest method optimizationDimensionsWithUniversal_throws.

@Test
public void optimizationDimensionsWithUniversal_throws() throws Exception {
    InvalidCommandException builderException = assertThrows(InvalidCommandException.class, () -> BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setAapt2Command(aapt2Command).setApkBuildMode(UNIVERSAL).setOptimizationDimensions(ImmutableSet.of(ABI)).build());
    assertThat(builderException).hasMessageThat().contains("Optimization dimension can be only set when running with 'default' mode flag.");
    InvalidCommandException flagsException = assertThrows(InvalidCommandException.class, () -> BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--optimize-for=abi", "--mode=UNIVERSAL"), fakeAdbServer));
    assertThat(flagsException).hasMessageThat().contains("Optimization dimension can be only set when running with 'default' mode flag.");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 18 with InvalidCommandException

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

the class InstallMultiApksCommandTest method execute_timeout_androidQ_throws.

@Test
public void execute_timeout_androidQ_throws() throws Exception {
    // GIVEN a fake .apks file with an .apex file.
    BuildApksResult toc = fakeTableOfContents(PKG_NAME_1);
    Path apksPath = createApksArchiveFile(toc, tmpDir.resolve("package1.apks"));
    // GIVEN an install command with the --staged flag...
    InstallMultiApksCommand command = InstallMultiApksCommand.builder().setAdbServer(fakeServerOneDevice(device)).setDeviceId(DEVICE_ID).setAdbPath(adbPath).setTimeout(Duration.ofSeconds(20)).setApksArchivePaths(ImmutableList.of(apksPath)).setAapt2Command(createFakeAapt2Command(ImmutableMap.of(PKG_NAME_1, 1L))).setAdbCommand(// EXPECT the --staged flag to be included.
    createFakeAdbCommand(expectedInstallApks(PKG_NAME_1, toc), /* expectedStaged= */
    false, /* expectedEnableRollback= */
    false, /* expectedTimeout= */
    Optional.of(Duration.ofSeconds(20)), Optional.of(DEVICE_ID))).build();
    givenEmptyListPackages(device);
    InvalidCommandException exception = assertThrows(InvalidCommandException.class, command::execute);
    assertThat(exception).hasMessageThat().isEqualTo("'timeout-millis' flag is supported for Android 12+ devices.");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) BuildApksResult(com.android.bundle.Commands.BuildApksResult) Test(org.junit.Test)

Example 19 with InvalidCommandException

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

the class DumpCommandTest method dumpResources_moduleSet_throws.

@Test
public void dumpResources_moduleSet_throws() throws Exception {
    createBundle(bundlePath);
    DumpCommand dumpCommand = DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.RESOURCES).setModuleName("base").build();
    InvalidCommandException exception = assertThrows(InvalidCommandException.class, dumpCommand::execute);
    assertThat(exception).hasMessageThat().contains("The module is unnecessary");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) Test(org.junit.Test)

Example 20 with InvalidCommandException

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

the class DumpCommandTest method dumpResources_withXPath_throws.

@Test
public void dumpResources_withXPath_throws() throws Exception {
    createBundle(bundlePath);
    DumpCommand dumpCommand = DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.RESOURCES).setXPathExpression("/manifest/@nothing-that-exists").build();
    InvalidCommandException exception = assertThrows(InvalidCommandException.class, dumpCommand::execute);
    assertThat(exception).hasMessageThat().contains("Cannot pass an XPath expression when dumping resources.");
}
Also used : InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) Test(org.junit.Test)

Aggregations

InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)26 Test (org.junit.Test)26 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)12 ZipPath (com.android.tools.build.bundletool.model.ZipPath)6 BuildApksResult (com.android.bundle.Commands.BuildApksResult)4 DeviceSpec (com.android.bundle.Devices.DeviceSpec)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Path (java.nio.file.Path)3 SystemEnvironmentProvider (com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider)1 FakeSystemEnvironmentProvider (com.android.tools.build.bundletool.testing.FakeSystemEnvironmentProvider)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1