Search in sources :

Example 26 with Variant

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

the class BuildApksConnectedDeviceTest method connectedDevice_correctSplitsGenerated.

@Test
public void connectedDevice_correctSplitsGenerated() throws Exception {
    fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XHDPI))));
    bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).build();
    Path apksArchive = command.execute();
    BuildApksResult result;
    try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
        assertThat(apksZipFile).containsExactlyEntries("toc.pb", "splits/base-master.apk", "splits/base-xhdpi.apk");
        result = extractTocFromApkSetFile(apksZipFile, outputDir);
    }
    assertThat(result.getVariantList()).hasSize(1);
    Variant variant = result.getVariant(0);
    assertThat(variant.getApkSetList()).hasSize(1);
    ApkSet apkSet = variant.getApkSet(0);
    // One master and one density split.
    assertThat(apkSet.getApkDescriptionList()).hasSize(2);
    assertThat(apkNamesInSet(apkSet)).containsExactly("splits/base-master.apk", "splits/base-xhdpi.apk");
}
Also used : Path(java.nio.file.Path) Variant(com.android.bundle.Commands.Variant) ApkSet(com.android.bundle.Commands.ApkSet) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 27 with Variant

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

the class BuildApksDeviceSpecTest method deviceSpec_correctStandaloneGenerated.

@Test
public void deviceSpec_correctStandaloneGenerated() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(19), abis("x86"), locales("en-US"), density(HDPI));
    bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).build();
    Path apksArchive = command.execute();
    BuildApksResult result;
    try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
        assertThat(apksZipFile).containsExactlyEntries("toc.pb", "standalones/standalone-hdpi.apk");
        result = extractTocFromApkSetFile(apksZipFile, outputDir);
    }
    assertThat(result.getVariantList()).hasSize(1);
    Variant variant = result.getVariant(0);
    assertThat(variant.getApkSetList()).hasSize(1);
    ApkSet apkSet = variant.getApkSet(0);
    // One standalone APK.
    assertThat(apkSet.getApkDescriptionList()).hasSize(1);
    assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-hdpi.apk");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) Variant(com.android.bundle.Commands.Variant) ApkSet(com.android.bundle.Commands.ApkSet) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) Test(org.junit.Test)

Example 28 with Variant

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

the class BuildApksConnectedDeviceTest method connectedDevice_withDeviceId_correctSplitsGenerated.

@Test
public void connectedDevice_withDeviceId_correctSplitsGenerated() throws Exception {
    fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XHDPI)), FakeDevice.fromDeviceSpec("id2", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.MDPI))));
    bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
    // We are picking the "id2" - MDPI device.
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).setDeviceId("id2").build();
    Path apksArchive = command.execute();
    BuildApksResult result;
    try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
        assertThat(apksZipFile).containsExactlyEntries("toc.pb", "splits/base-master.apk", "splits/base-mdpi.apk");
        result = extractTocFromApkSetFile(apksZipFile, outputDir);
    }
    assertThat(result.getVariantList()).hasSize(1);
    Variant variant = result.getVariant(0);
    assertThat(variant.getApkSetList()).hasSize(1);
    ApkSet apkSet = variant.getApkSet(0);
    // One master and one density split.
    assertThat(apkSet.getApkDescriptionList()).hasSize(2);
    assertThat(apkNamesInSet(apkSet)).containsExactly("splits/base-master.apk", "splits/base-mdpi.apk");
}
Also used : Path(java.nio.file.Path) Variant(com.android.bundle.Commands.Variant) ApkSet(com.android.bundle.Commands.ApkSet) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 29 with Variant

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

the class GetSizeCommandTest method getSizeTotal_withSelectModules.

@Test
public void getSizeTotal_withSelectModules() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))), createSplitApkSet(/* moduleName= */
    "feature1", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-feature1.apk"))), createSplitApkSet(/* moduleName= */
    "feature2", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of("feature3"), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-feature2.apk"))), createSplitApkSet(/* moduleName= */
    "feature3", DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-feature3.apk"))));
    Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(15), ImmutableSet.of(sdkVersionFrom(21)))), ApkTargeting.getDefaultInstance(), ZipPath.create("preL.apk"));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addVariant(preLVariant).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setModules(ImmutableSet.of("base", "feature2")).build().getSizeTotal(new PrintStream(outputStream));
    // base, feature2, feature 3 modules are selected and standalone variants are skipped.
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo("MIN,MAX" + CRLF + String.format("%d,%d", 3 * compressedApkSize, 3 * compressedApkSize) + CRLF);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) PrintStream(java.io.PrintStream) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 30 with Variant

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

the class VariantMatcherTest method getAllMatchingVariants_apexVariants_noMatch_throws.

@Test
public void getAllMatchingVariants_apexVariants_noMatch_throws() {
    ZipPath x86Apk = ZipPath.create("standalone-x86.apk");
    ZipPath x64X86Apk = ZipPath.create("standalone-x86_64.x86.apk");
    ImmutableSet<ImmutableSet<AbiAlias>> x86Set = ImmutableSet.of(ImmutableSet.of(X86));
    ImmutableSet<ImmutableSet<AbiAlias>> x64X86Set = ImmutableSet.of(ImmutableSet.of(X86_64, X86));
    MultiAbiTargeting x86Targeting = multiAbiTargeting(x86Set, x64X86Set);
    MultiAbiTargeting x64X86Targeting = multiAbiTargeting(x64X86Set, x86Set);
    Variant x86Variant = multiAbiTargetingApexVariant(x86Targeting, x86Apk);
    Variant x64X86Variant = multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(ImmutableList.of(x86Variant, x64X86Variant)).build();
    IncompatibleDeviceException e = assertThrows(IncompatibleDeviceException.class, () -> new VariantMatcher(abis("x86_64", "armeabi-v7a")).getAllMatchingVariants(buildApksResult));
    assertThat(e).hasMessageThat().contains("No set of ABI architectures that the app supports is contained in the ABI " + "architecture set of the device");
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) 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) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) Test(org.junit.Test)

Aggregations

Variant (com.android.bundle.Commands.Variant)134 Test (org.junit.Test)130 BuildApksResult (com.android.bundle.Commands.BuildApksResult)100 ZipPath (com.android.tools.build.bundletool.model.ZipPath)82 Path (java.nio.file.Path)80 ZipFile (java.util.zip.ZipFile)79 AppBundle (com.android.tools.build.bundletool.model.AppBundle)66 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)66 ApkSet (com.android.bundle.Commands.ApkSet)63 ApkDescription (com.android.bundle.Commands.ApkDescription)60 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)59 File (java.io.File)59 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)56 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)55 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)55 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)54 ApkSetUtils.parseTocFromFile (com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile)54 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)54 ImmutableSet (com.google.common.collect.ImmutableSet)54 ApkVerifier (com.android.apksig.ApkVerifier)53