Search in sources :

Example 1 with ExtractApksResult

use of com.android.bundle.Commands.ExtractApksResult 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)

Aggregations

BuildApksResult (com.android.bundle.Commands.BuildApksResult)1 ExtractApksResult (com.android.bundle.Commands.ExtractApksResult)1 DeviceSpec (com.android.bundle.Devices.DeviceSpec)1 ZipPath (com.android.tools.build.bundletool.model.ZipPath)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1 Theory (org.junit.experimental.theories.Theory)1