Search in sources :

Example 61 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class ApkMatcherTest method apkMatch_screenDensitySplit_noBetterAlternative.

@Test
public void apkMatch_screenDensitySplit_noBetterAlternative() {
    ZipPath apk = ZipPath.create("sample.apk");
    BuildApksResult buildApksResult = buildApksResult(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(Versions.ANDROID_L_API_VERSION)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI, HDPI)), apk));
    assertThat(new ApkMatcher(lDeviceWithDensity(XXHDPI)).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 62 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class ApkMatcherTest method ensureDensityAndAbiSplitIsMatchedPerEachModule_split.

@Test
public void ensureDensityAndAbiSplitIsMatchedPerEachModule_split() {
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseX86SplitApk = ZipPath.create("base-x86.apk");
    ZipPath baseMdpiSplitApk = ZipPath.create("base-mdpi.apk");
    ZipPath baseHdpiSplitApk = ZipPath.create("base-hdpi.apk");
    ZipPath screenMdpiApk = ZipPath.create("screen-mdpi.apk");
    BuildApksResult buildApksResult = buildApksResult(splitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), baseX86SplitApk), splitApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(HDPI, XHDPI)), baseMdpiSplitApk), splitApkDescription(apkDensityTargeting(HDPI, ImmutableSet.of(MDPI, XHDPI)), baseHdpiSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(HDPI)), screenMdpiApk))));
    Optional<ImmutableSet<String>> allModules = Optional.of(ImmutableSet.of("base", "screen"));
    assertThat(createSafeMatcher(mergeSpecs(density(MDPI), abis("x86")), allModules).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseMasterSplitApk, "base", INSTALL_TIME), matchedApk(baseX86SplitApk, "base", INSTALL_TIME), matchedApk(baseMdpiSplitApk, "base", INSTALL_TIME), matchedApk(screenMdpiApk, "screen", INSTALL_TIME));
    IncompatibleDeviceException baseException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(MDPI), abis("x86_64")), allModules).getMatchingApks(buildApksResult));
    assertThat(baseException).hasMessageThat().isEqualTo("Missing APKs for [ABI] dimensions in the module 'base' for the provided device.");
    IncompatibleDeviceException screenException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(HDPI), abis("x86")), allModules).getMatchingApks(buildApksResult));
    assertThat(screenException).hasMessageThat().isEqualTo("Missing APKs for [SCREEN_DENSITY] dimensions in the module 'screen' for the provided" + " device.");
    IncompatibleDeviceException multipleDimensionsException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(XHDPI), abis("x86_64")), allModules).getMatchingApks(buildApksResult));
    assertThat(multipleDimensionsException).hasMessageThat().isEqualTo("Missing APKs for [ABI, SCREEN_DENSITY] dimensions in the module 'base' for the" + " provided device.");
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) Test(org.junit.Test)

Example 63 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class ApkMatcherTest method apkNoMatch_deviceDoesntMatchVariantValue_bothBetterAndNoBetterAlternatives.

@Test
public void apkNoMatch_deviceDoesntMatchVariantValue_bothBetterAndNoBetterAlternatives() {
    ZipPath apk = ZipPath.create("sample.apk");
    BuildApksResult buildApksResult = buildApksResult(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1), sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apk));
    assertThat(new ApkMatcher(deviceWithSdk(19)).getMatchingApks(buildApksResult)).isEmpty();
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 64 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_instantApks_checksModuleName_isEmpty.

@Test
public void apkMatch_withModuleNameFiltering_instantApks_checksModuleName_isEmpty() {
    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(createInstantMatcher(device, allModules).getMatchingApks(buildApksResult)).isEmpty();
    Optional<ImmutableSet<String>> baseModuleOnly = Optional.of(ImmutableSet.of("base"));
    assertThat(createInstantMatcher(device, baseModuleOnly).getMatchingApks(buildApksResult)).isEmpty();
    Optional<ImmutableSet<String>> featureModuleOnly = Optional.of(ImmutableSet.of("feature"));
    // No matching instant variant
    assertThat(createInstantMatcher(device, featureModuleOnly).getMatchingApks(buildApksResult)).isEmpty();
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 65 with BuildApksResult

use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.

the class ApkMatcherTest method variantBetterAlternative_preL_abiShard.

@Test
public void variantBetterAlternative_preL_abiShard() {
    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, X86_64))), ApkTargeting.getDefaultInstance(), apk));
    assertThat(new ApkMatcher(deviceWith(19, ImmutableList.of("x86_64", "x86"), MDPI)).getMatchingApks(buildApksResult)).isEmpty();
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Aggregations

BuildApksResult (com.android.bundle.Commands.BuildApksResult)282 Test (org.junit.Test)276 ZipPath (com.android.tools.build.bundletool.model.ZipPath)234 Path (java.nio.file.Path)180 Variant (com.android.bundle.Commands.Variant)120 ZipFile (java.util.zip.ZipFile)109 AppBundle (com.android.tools.build.bundletool.model.AppBundle)96 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)93 ImmutableSet (com.google.common.collect.ImmutableSet)88 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)87 Theory (org.junit.experimental.theories.Theory)86 ApkSet (com.android.bundle.Commands.ApkSet)84 AdbServer (com.android.tools.build.bundletool.device.AdbServer)84 ApkDescription (com.android.bundle.Commands.ApkDescription)82 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)78 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)78 File (java.io.File)78 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)77 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)77 IOException (java.io.IOException)76