Search in sources :

Example 21 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class InstallApksCommandTest method installAssetModules.

@Test
@Theory
public void installAssetModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) 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 tableOfContent = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.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 apksFile = createApks(tableOfContent, apksInDirectory);
    List<Path> installedApks = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of(installTimeModule1)).build().execute();
    assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), installTimeMasterApk1.toString(), installTimeEnApk1.toString());
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) 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) Theory(org.junit.experimental.theories.Theory)

Example 22 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath 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 23 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath 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 24 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class ApkMatcherTest method apkMatch_textureSplit_noBetterAlternative.

@Test
public void apkMatch_textureSplit_noBetterAlternative() {
    ZipPath apk = ZipPath.create("master-etc1_rgb8.apk");
    BuildApksResult buildApksResult = buildApksResult(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(Versions.ANDROID_L_API_VERSION)), apkTextureTargeting(ETC1_RGB8, ImmutableSet.of(ATC, PVRTC)), apk));
    assertThat(new ApkMatcher(lDeviceWithGlExtensions("GL_OES_compressed_ETC1_RGB8_texture")).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 25 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class ApkMatcherTest method variantMatching_SdkAbiDensity.

@Test
public void variantMatching_SdkAbiDensity() {
    ZipPath apk = ZipPath.create("sample.apk");
    BuildApksResult buildApksResult = buildApksResult(standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI_V7A, ARM64_V8A)), variantDensityTargeting(XHDPI, ImmutableSet.of(LDPI, XXHDPI))), ApkTargeting.getDefaultInstance(), apk));
    assertThat(new ApkMatcher(deviceWith(19, ImmutableList.of("x86_64", "x86", "arm64-v8a"), HDPI)).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(apk));
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Aggregations

ZipPath (com.android.tools.build.bundletool.model.ZipPath)194 Test (org.junit.Test)154 BuildApksResult (com.android.bundle.Commands.BuildApksResult)106 Path (java.nio.file.Path)55 DeviceSpec (com.android.bundle.Devices.DeviceSpec)44 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)23 ImmutableSet (com.google.common.collect.ImmutableSet)23 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)19 Variant (com.android.bundle.Commands.Variant)16 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)15 BundleModule (com.android.tools.build.bundletool.model.BundleModule)13 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)10 Theory (org.junit.experimental.theories.Theory)10 AdbServer (com.android.tools.build.bundletool.device.AdbServer)9 IOException (java.io.IOException)9 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)8 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)8 UncheckedIOException (java.io.UncheckedIOException)8