Search in sources :

Example 66 with DeviceSpec

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

the class ExtractApksCommandTest method outputDirectorySetWhenUsingDirectory_throws.

@Test
public void outputDirectorySetWhenUsingDirectory_throws() throws Exception {
    Path apksArchivePath = createApksDirectory(minimalApkSet(), tmpDir);
    DeviceSpec deviceSpec = deviceWithSdk(21);
    Throwable exception = assertThrows(IllegalArgumentException.class, () -> ExtractApksCommand.builder().setApksArchivePath(apksArchivePath).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).build().execute());
    assertThat(exception).hasMessageThat().contains("Output directory should not be set when APKs are inside directory");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) Test(org.junit.Test)

Example 67 with DeviceSpec

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

the class ExtractApksCommandTest method extractAssetModules.

@Test
public void extractAssetModules() throws Exception {
    String installTimeModule1 = "installtime_assetmodule1";
    String installTimeModule2 = "installtime_assetmodule2";
    String onDemandModule = "ondemand_assetmodule";
    ZipPath installTimeMasterApk1 = ZipPath.create(installTimeModule1 + "-master.apk");
    ZipPath installTimeEnApk1 = ZipPath.create(installTimeModule1 + "-en.apk");
    ZipPath installTimeMasterApk2 = ZipPath.create(installTimeModule2 + "-master.apk");
    ZipPath installTimeEnApk2 = ZipPath.create(installTimeModule2 + "-en.apk");
    ZipPath onDemandMasterApk = ZipPath.create(onDemandModule + "-master.apk");
    ZipPath baseApk = ZipPath.create("base-master.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(), baseApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule1).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk1)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk1))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeModule2).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeMasterApk2)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeEnApk2))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandModule).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandMasterApk))).build();
    Path apksArchiveFile = createApksArchiveFile(buildApksResult, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = lDeviceWithLocales("en-US");
    ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).build().execute();
    assertThat(matchedApks).containsExactly(inOutputDirectory(installTimeMasterApk1), inOutputDirectory(installTimeEnApk1), inOutputDirectory(installTimeMasterApk2), inOutputDirectory(installTimeEnApk2), inOutputDirectory(baseApk));
    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 68 with DeviceSpec

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

the class ExtractApksCommandTest method oneModule_Kdevice_noMatchingSdkVariant_throws.

@Test
public void oneModule_Kdevice_noMatchingSdkVariant_throws() throws Exception {
    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(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apkL)).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(23), ImmutableSet.of(sdkVersionFrom(21))), ApkTargeting.getDefaultInstance(), apkM)).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = deviceWithSdk(19);
    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 SDK version of the device: (19).");
}
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 69 with DeviceSpec

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

the class ExtractApksCommandTest method extractInstant_withModulesFlag.

@Test
public void extractInstant_withModulesFlag() throws Exception {
    ZipPath apkPreL = ZipPath.create("apkPreL.apk");
    ZipPath apkLBase = ZipPath.create("apkL-base.apk");
    ZipPath apkLFeature = ZipPath.create("apkL-feature.apk");
    ZipPath apkLOther = ZipPath.create("apkL-other.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createStandaloneApkSet(ApkTargeting.getDefaultInstance(), apkPreL))).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createInstantApkSet("base", ApkTargeting.getDefaultInstance(), apkLBase), createInstantApkSet("feature", ApkTargeting.getDefaultInstance(), apkLFeature), createInstantApkSet("other", ApkTargeting.getDefaultInstance(), apkLOther))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = deviceWithSdk(21);
    ImmutableList<Path> matchedApks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).setInstant(true).setModules(ImmutableSet.of("feature")).build().execute();
    assertThat(matchedApks).containsExactly(inOutputDirectory(apkLBase), inOutputDirectory(apkLFeature));
    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 70 with DeviceSpec

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

the class ExtractApksCommandTest method extractApks_aboveMaxSdk_throws.

@Test
public void extractApks_aboveMaxSdk_throws() throws Exception {
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(// The variant contains a fake alternative to limit the matching up to 23.
    sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(24))), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))))).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = deviceWithSdk(26);
    IncompatibleDeviceException exception = assertThrows(IncompatibleDeviceException.class, () -> ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setInstant(true).build().execute());
    assertThat(exception).hasMessageThat().contains("No compatible APKs found for the 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)

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