Search in sources :

Example 91 with DeviceSpec

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

the class GetSizeCommandTest method builderAndFlagsConstruction_optionalDeviceSpec_inJavaViaFiles_equivalent.

@Test
public void builderAndFlagsConstruction_optionalDeviceSpec_inJavaViaFiles_equivalent() throws Exception {
    DeviceSpec deviceSpec = deviceWithSdk(21);
    Path deviceSpecFile = createDeviceSpecFile(deviceSpec, tmpDir.resolve("device.json"));
    BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    GetSizeCommand fromFlags = GetSizeCommand.fromFlags(new FlagParser().parse("get-size", "total", "--apks=" + apksArchiveFile, // Optional values.
    "--device-spec=" + deviceSpecFile));
    GetSizeCommand fromBuilderApi = GetSizeCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpecFile).setGetSizeSubCommand(GetSizeSubcommand.TOTAL).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)

Example 92 with DeviceSpec

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

the class InstallApksCommandTest method badAbisDevice_throws.

@Test
@Theory
public void badAbisDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    Path apksFile = createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory);
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis(), 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 ABIs");
}
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 93 with DeviceSpec

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

the class InstallApksCommandTest method incompleteApksFile_missingAbiSplitMatchedForDevice_throws.

@Test
public void incompleteApksFile_missingAbiSplitMatchedForDevice_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 'install-apks'
    // command and command must throw IncompatibleDeviceException as mathed split 'x86_64' is not
    // available.
    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 apksFile = createApks(tableOfContent, /* apksInDirectory= */
    false);
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(DensityAlias.MDPI), 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(IncompatibleDeviceException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("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) 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 94 with DeviceSpec

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

the class VariantMatcherTest method getAllMatchingVariants_partialDeviceSpec.

@Test
public void getAllMatchingVariants_partialDeviceSpec() {
    ZipPath standaloneArmXxxhdpiApk = ZipPath.create("standalone-arm.xxxhdpi.apk");
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
    ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
    Variant standaloneVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86)), variantDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), mergeApkTargeting(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), standaloneArmXxxhdpiApk);
    Variant splitVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk)));
    ImmutableList<Variant> variants = ImmutableList.of(standaloneVariant, splitVariant);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(variants).build();
    DeviceSpec preLDevice = mergeSpecs(sdkVersion(19));
    assertThat(new VariantMatcher(preLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneVariant);
    DeviceSpec preLXXXHDPIDevice = mergeSpecs(sdkVersion(19), density(XXXHDPI));
    assertThat(new VariantMatcher(preLXXXHDPIDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneVariant);
    DeviceSpec preLX86Device = mergeSpecs(sdkVersion(19), abis("x86"));
    assertThat(new VariantMatcher(preLX86Device).getAllMatchingVariants(buildApksResult)).isEmpty();
    DeviceSpec postLDevice = mergeSpecs(sdkVersion(21));
    assertThat(new VariantMatcher(postLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(splitVariant);
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) 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 95 with DeviceSpec

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

the class VariantMatcherTest method getAllMatchingVariants_fullDeviceSpec.

@Test
public void getAllMatchingVariants_fullDeviceSpec() {
    ZipPath standaloneX86MdpiApk = ZipPath.create("standalone-x86.mdpi.apk");
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
    ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
    Variant standaloneX86MdpiVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI)), variantDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), mergeApkTargeting(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), standaloneX86MdpiApk);
    Variant splitVariant = createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk)));
    ImmutableList<Variant> variants = ImmutableList.of(standaloneX86MdpiVariant, splitVariant);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(variants).build();
    DeviceSpec preLX86MdpiDevice = mergeSpecs(sdkVersion(19), abis("x86"), density(MDPI), locales("en"));
    assertThat(new VariantMatcher(preLX86MdpiDevice).getAllMatchingVariants(buildApksResult)).containsExactly(standaloneX86MdpiVariant);
    DeviceSpec preLX86HdpiDevice = mergeSpecs(sdkVersion(19), abis("x86"), density(HDPI), locales("en"));
    assertThat(new VariantMatcher(preLX86HdpiDevice).getAllMatchingVariants(buildApksResult)).isEmpty();
    DeviceSpec postLDevice = mergeSpecs(sdkVersion(21), abis("x86"), density(MDPI), locales("en"));
    assertThat(new VariantMatcher(postLDevice).getAllMatchingVariants(buildApksResult)).containsExactly(splitVariant);
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) DeviceSpec(com.android.bundle.Devices.DeviceSpec) 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