Search in sources :

Example 41 with ZipPath

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

the class ApkMatcherTest method textureVariant_preL_incompatibleDevice.

@Test
public void textureVariant_preL_incompatibleDevice() {
    ZipPath apk = ZipPath.create("master-etc1_rgb8.apk");
    BuildApksResult buildApksResult = buildApksResult(standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantTextureTargeting(ATC)), ApkTargeting.getDefaultInstance(), apk));
    IncompatibleDeviceException exception = assertThrows(IncompatibleDeviceException.class, () -> new ApkMatcher(preLDeviceWithGlExtensions("GL_OES_compressed_ETC1_RGB8_texture")).getMatchingApks(buildApksResult));
    assertThat(exception).hasMessageThat().contains("The app doesn't support texture compression formats of the device. Device formats:" + " [ETC1_RGB8], app formats: [ATC]");
}
Also used : 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 42 with ZipPath

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

the class ApkMatcherTest method apkMatch_languageSplit.

// Language splits.
@Test
public void apkMatch_languageSplit() {
    ZipPath apk = ZipPath.create("master-fr.apk");
    BuildApksResult buildApksResult = buildApksResult(oneApkSplitApkVariant(variantSdkTargeting(sdkVersionFrom(Versions.ANDROID_L_API_VERSION)), apkLanguageTargeting("fr"), apk));
    assertThat(new ApkMatcher(lDeviceWithLocales("fr-FR")).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 43 with ZipPath

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

the class ApkMatcherTest method splitAndStandaloneApks_variousDevices.

// Real-world complex selections.
@Test
public void splitAndStandaloneApks_variousDevices() {
    ZipPath standaloneX86MdpiApk = ZipPath.create("standalone-x86.mdpi.apk");
    ZipPath standaloneX86XxxhdpiApk = ZipPath.create("standalone-x86.xxxhdpi.apk");
    ZipPath standaloneArmMdpiApk = ZipPath.create("standalone-arm.mdpi.apk");
    ZipPath standaloneArmXxxhdpiApk = ZipPath.create("standalone-arm.xxxhdpi.apk");
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseX86SplitApk = ZipPath.create("base-x86.apk");
    ZipPath baseArmSplitApk = ZipPath.create("base-arm.apk");
    ZipPath screenMdpiApk = ZipPath.create("screen-mdpi.apk");
    ZipPath screenXxxhdpiApk = ZipPath.create("screen-xxxhdpi.apk");
    ZipPath langsEnSplitApk = ZipPath.create("langs-en.apk");
    ZipPath langsDeSplitApk = ZipPath.create("langs-de.apk");
    BuildApksResult buildApksResult = buildApksResult(// Standalone X86 MDPI
    standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI)), variantDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), mergeApkTargeting(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), standaloneX86MdpiApk), // Standalone X86 XXXHDI
    standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI)), variantDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), mergeApkTargeting(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), standaloneX86XxxhdpiApk), // Standalone ARM MDPI
    standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86)), variantDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), mergeApkTargeting(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI))), standaloneArmMdpiApk), // Standalone ARM XXXHDI
    standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86)), variantDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), mergeApkTargeting(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI))), standaloneArmXxxhdpiApk), // Splits L+
    splitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(X86, ImmutableSet.of(ARMEABI)), baseX86SplitApk), splitApkDescription(apkAbiTargeting(ARMEABI, ImmutableSet.of(X86)), baseArmSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(XXXHDPI)), screenMdpiApk), splitApkDescription(apkDensityTargeting(XXXHDPI, ImmutableSet.of(MDPI)), screenXxxhdpiApk)), splitApkSet(/* moduleName= */
    "langs", splitApkDescription(apkLanguageTargeting("en"), langsEnSplitApk), splitApkDescription(apkLanguageTargeting("de"), langsDeSplitApk))));
    DeviceSpec preLX86MdpiDevice = mergeSpecs(sdkVersion(19), abis("x86"), density(MDPI), locales("en"));
    assertThat(new ApkMatcher(preLX86MdpiDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(standaloneX86MdpiApk));
    DeviceSpec preLArmXxxdpiDevice = mergeSpecs(sdkVersion(19), abis("armeabi"), density(XXXHDPI), locales("en"));
    assertThat(new ApkMatcher(preLArmXxxdpiDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(standaloneArmXxxhdpiApk));
    DeviceSpec lX86MdpiEnDevice = mergeSpecs(sdkVersion(21), abis("x86"), density(MDPI), locales("en"));
    assertThat(new ApkMatcher(lX86MdpiEnDevice).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseMasterSplitApk), baseMatchedApk(baseX86SplitApk), matchedApk(screenMdpiApk, /* moduleName=*/
    "screen", INSTALL_TIME), matchedApk(langsEnSplitApk, /* moduleName=*/
    "langs", INSTALL_TIME));
    // MIPS ABI is not supported by the app.
    DeviceSpec preLMipsDevice = mergeSpecs(sdkVersion(19), abis("mips"), density(MDPI), locales("en"));
    Throwable exception = assertThrows(IncompatibleDeviceException.class, () -> new ApkMatcher(preLMipsDevice).getMatchingApks(buildApksResult));
    assertThat(exception).hasMessageThat().contains("The app doesn't support ABI architectures of the device. Device ABIs: [mips], " + "app ABIs: [x86, armeabi]");
}
Also used : 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 44 with ZipPath

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

the class ApkMatcherTest method variantMatch_preL_abiShard.

// Pre-L sharding variants tests.
@Test
public void variantMatch_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))), ApkTargeting.getDefaultInstance(), apk));
    assertThat(new ApkMatcher(deviceWith(15, ImmutableList.of("x86"), MDPI)).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 45 with ZipPath

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

the class ApkMatcherTest method apkMatch_withModuleNameFiltering_splitApks_diamondModuleDependenciesGraph.

@Test
public void apkMatch_withModuleNameFiltering_splitApks_diamondModuleDependenciesGraph() {
    DeviceSpec device = deviceWithSdk(21);
    ZipPath baseApk = ZipPath.create("master-base.apk");
    ZipPath feature1Apk = ZipPath.create("master-feature1.apk");
    ZipPath feature2Apk = ZipPath.create("master-feature2.apk");
    ZipPath feature3Apk = ZipPath.create("master-feature3.apk");
    ZipPath feature4Apk = ZipPath.create("master-feature4.apk");
    BuildApksResult buildApksResult = buildApksResult(createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), splitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), feature1Apk)), splitApkSet(/* moduleName= */
    "feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), splitApkDescription(ApkTargeting.getDefaultInstance(), feature2Apk)), splitApkSet(/* moduleName= */
    "feature3", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature1"), splitApkDescription(ApkTargeting.getDefaultInstance(), feature3Apk)), splitApkSet(/* moduleName= */
    "feature4", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature2", "feature3"), splitApkDescription(ApkTargeting.getDefaultInstance(), feature4Apk))));
    // By default on-demand features are not installed.
    Optional<ImmutableSet<String>> allModules = Optional.empty();
    assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
    Optional<ImmutableSet<String>> feature4ModuleOnly = Optional.of(ImmutableSet.of("feature4"));
    assertThat(createMatcher(device, feature4ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
    "feature1", ON_DEMAND), matchedApk(feature2Apk, /* moduleName=*/
    "feature2", ON_DEMAND), matchedApk(feature3Apk, /* moduleName=*/
    "feature3", ON_DEMAND), matchedApk(feature4Apk, /* moduleName=*/
    "feature4", ON_DEMAND));
    Optional<ImmutableSet<String>> feature2ModuleOnly = Optional.of(ImmutableSet.of("feature2"));
    assertThat(createMatcher(device, feature2ModuleOnly).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk), matchedApk(feature1Apk, /* moduleName=*/
    "feature1", ON_DEMAND), matchedApk(feature2Apk, /* moduleName=*/
    "feature2", ON_DEMAND));
}
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)

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