Search in sources :

Example 71 with DeviceSpec

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

the class ExtractApksCommandTest method deviceSpecFromPbJson.

@Test
public void deviceSpecFromPbJson() throws Exception {
    DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder();
    try (Reader reader = TestData.openReader("testdata/device/pixel2_spec.json")) {
        JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder);
    }
    DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build();
    BuildApksResult tableOfContentsProto = minimalApkSet();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    Path deviceSpecFile = copyToTempDir("testdata/device/pixel2_spec.json");
    ExtractApksCommand command = ExtractApksCommand.fromFlags(new FlagParser().parse("--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile));
    assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec);
}
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) Reader(java.io.Reader) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 72 with DeviceSpec

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

the class ExtractApksCommandTest method extractInstant_withBaseAndSingleInstantModule.

@Test
public void extractInstant_withBaseAndSingleInstantModule() throws Exception {
    ZipPath apkBase = ZipPath.create("apkL-base.apk");
    ZipPath apkInstant = ZipPath.create("apkL-instant.apk");
    ZipPath apkOther = 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())), createInstantApkSet("base", ApkTargeting.getDefaultInstance(), apkBase), createInstantApkSet("instant", ApkTargeting.getDefaultInstance(), apkInstant))).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet("other", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkOther)))).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).build().execute();
    assertThat(matchedApks).containsExactly(inOutputDirectory(apkInstant), inOutputDirectory(apkBase));
    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 73 with DeviceSpec

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

the class ExtractApksCommandTest method oneModule_Ldevice_matchesLmasterSplit.

@Test
@Theory
public void oneModule_Ldevice_matchesLmasterSplit(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    ZipPath apkOne = ZipPath.create("apk_one.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21)), ApkTargeting.getDefaultInstance(), apkOne)).build();
    Path apksPath = createApks(tableOfContentsProto, apksInDirectory);
    DeviceSpec deviceSpec = deviceWithSdk(21);
    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(apkOne.toString()));
    } else {
        assertThat(matchedApks).containsExactly(inOutputDirectory(apkOne.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 74 with DeviceSpec

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

the class ExtractApksCommandTest method extractApks_producesOutputMetadata.

@Test
@Theory
public void extractApks_producesOutputMetadata(@FromDataPoints("localTestingEnabled") boolean localTestingEnabled) throws Exception {
    String onDemandModule = "ondemand_assetmodule";
    ZipPath apkBase = ZipPath.create("base-master.apk");
    ZipPath apkFeature1 = ZipPath.create("feature1-master.apk");
    ZipPath apkFeature2 = ZipPath.create("feature2-master.apk");
    ZipPath onDemandMasterApk = ZipPath.create(onDemandModule + "-master.apk");
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(SdkVersion.getDefaultInstance())), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkBase)), createSplitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature1)), createSplitApkSet(/* moduleName= */
    "feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), apkFeature2)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandModule).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandMasterApk))).build();
    if (localTestingEnabled) {
        tableOfContentsProto = tableOfContentsProto.toBuilder().setPackageName("com.acme.anvil").setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing_dir")).build();
    }
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    DeviceSpec deviceSpec = deviceWithSdk(21);
    ImmutableList<Path> apks = ExtractApksCommand.builder().setApksArchivePath(apksArchiveFile).setDeviceSpec(deviceSpec).setOutputDirectory(tmpDir).setModules(ImmutableSet.of("feature2", "ondemand_assetmodule")).setIncludeMetadata(true).build().execute();
    assertThat(apks).containsExactly(inOutputDirectory(apkBase), inOutputDirectory(apkFeature1), inOutputDirectory(apkFeature2), inOutputDirectory(onDemandMasterApk));
    Path metadataFile = inTempDirectory("metadata.json");
    assertThat(Files.isRegularFile(metadataFile)).isTrue();
    ExtractApksResult expectedResult = ExtractApksResult.newBuilder().addApks(ExtractedApk.newBuilder().setPath(apkBase.toString()).setDeliveryType(DeliveryType.INSTALL_TIME).setModuleName("base").build()).addApks(ExtractedApk.newBuilder().setPath(apkFeature1.toString()).setDeliveryType(DeliveryType.ON_DEMAND).setModuleName("feature1").build()).addApks(ExtractedApk.newBuilder().setPath(apkFeature2.toString()).setDeliveryType(DeliveryType.ON_DEMAND).setModuleName("feature2").build()).addApks(ExtractedApk.newBuilder().setPath(onDemandMasterApk.toString()).setDeliveryType(DeliveryType.ON_DEMAND).setModuleName("ondemand_assetmodule").build()).build();
    if (localTestingEnabled) {
        expectedResult = expectedResult.toBuilder().setLocalTestingInfo(LocalTestingInfoForMetadata.newBuilder().setLocalTestingDir("/sdcard/Android/data/com.acme.anvil/files/local_testing_dir")).build();
    }
    assertThat(parseExtractApksResult(metadataFile)).ignoringRepeatedFieldOrder().isEqualTo(expectedResult);
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) DeviceSpec(com.android.bundle.Devices.DeviceSpec) ExtractApksResult(com.android.bundle.Commands.ExtractApksResult) 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 75 with DeviceSpec

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

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_permanentlyMergedModule.

@Test
public void apkMatch_withModuleNameFiltering_splitApks_permanentlyMergedModule() {
    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)))).toBuilder().addPermanentlyFusedModules(PermanentlyFusedModule.newBuilder().setName("my-module")).build();
    ImmutableList<GeneratedApk> matchedApks = createMatcher(device, Optional.of(ImmutableSet.of("my-module"))).getMatchingApks(buildApksResult);
    assertThat(matchedApks).containsExactly(baseMatchedApk(apk));
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) GeneratedApk(com.android.tools.build.bundletool.device.ApkMatcher.GeneratedApk) 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