Search in sources :

Example 16 with DeviceSpec

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

the class InstallApksCommandTest method deviceAbiIncompatible_throws.

@Test
public void deviceAbiIncompatible_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(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));
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksArchiveFile).setAdbPath(adbPath).setAdbServer(adbServer).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) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 17 with DeviceSpec

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

the class InstallApksCommandTest method badDensityDevice_throws.

@Test
@Theory
public void badDensityDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    Path apksFile = createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory);
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(-1), abis("x86_64", "x86"), locales("en-US"));
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).build();
    Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
    assertThat(exception).hasMessageThat().contains("Error retrieving device density");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 18 with DeviceSpec

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

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_standaloneApkMatches_throws.

@Test
public void apkMatch_withModuleNameFiltering_standaloneApkMatches_throws() {
    DeviceSpec x86Device = lDeviceWithAbis("x86");
    ZipPath apk = ZipPath.create("master-x86.apk");
    BuildApksResult buildApksResult = buildApksResult(standaloneVariant(variantAbiTargeting(X86), apkAbiTargeting(X86), apk));
    // Sanity-check that the device matches the standalone APK.
    assertThat(new ApkMatcher(x86Device).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createMatcher(x86Device, baseModuleOnly).getMatchingApks(buildApksResult));
    assertThat(exception).hasMessageThat().contains("Cannot restrict modules");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 19 with DeviceSpec

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

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_checksModuleName.

// Module name filtering.
@Test
public void apkMatch_withModuleNameFiltering_splitApks_checksModuleName() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath apk = ZipPath.create("master-de-fr.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), apk))));
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
    Optional<ImmutableSet<String>> unknownModuleOnly = Optional.of(ImmutableSet.of("unknown_module"));
    InvalidCommandException exception = assertThrows(InvalidCommandException.class, () -> createMatcher(device, unknownModuleOnly).getMatchingApks(buildApksResult));
    assertThat(exception).hasMessageThat().contains("The APK Set archive does not contain the following modules: [unknown_module]");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 20 with DeviceSpec

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

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_moduleWithDependency.

@Test
public void apkMatch_withModuleNameFiltering_splitApks_moduleWithDependency() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath baseApk = ZipPath.create("master-base.apk");
    ZipPath feature1Apk = ZipPath.create("master-feature1.apk");
    ZipPath feature2Apk = ZipPath.create("master-feature2.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), splitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), feature1Apk)), splitApkSet(/* moduleName= */
    "feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), splitApkDescription(ApkTargeting.getDefaultInstance(), feature2Apk))));
    // By default on-demand features are not installed.
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
    Optional<ImmutableSet<String>> feature2ModuleOnly = Optional.of(ImmutableSet.of("feature2"));
    assertThat(createMatcher(device, feature2ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
    "feature1", ON_DEMAND), matchedApk(feature2Apk, /* moduleName=*/
    "feature2", ON_DEMAND));
    Optional<ImmutableSet<String>> feature1ModuleOnly = Optional.of(ImmutableSet.of("feature1"));
    assertThat(createMatcher(device, feature1ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
    "feature1", ON_DEMAND));
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) 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