Search in sources :

Example 11 with ApkSet

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

the class BuildApksConnectedDeviceTest method connectedDevice_withDeviceId_correctStandaloneGenerated.

@Test
public void connectedDevice_withDeviceId_correctStandaloneGenerated() throws Exception {
    fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(19), abis("x86"), locales("en-US"), density(DensityAlias.XHDPI))), FakeDevice.fromDeviceSpec("id2", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XXHDPI))));
    bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
    // Selecting "id1" device - KitKat, XHDPI.
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).setDeviceId("id1").build();
    Path apksArchive = command.execute();
    BuildApksResult result;
    try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
        assertThat(apksZipFile).containsExactlyEntries("toc.pb", "standalones/standalone-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 standalone APK.
    assertThat(apkSet.getApkDescriptionList()).hasSize(1);
    assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-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 12 with ApkSet

use of com.android.bundle.Commands.ApkSet 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 13 with ApkSet

use of com.android.bundle.Commands.ApkSet 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 14 with ApkSet

use of com.android.bundle.Commands.ApkSet 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 15 with ApkSet

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

the class BuildApksManagerTest method apkWithSourceStamp.

@Test
public void apkWithSourceStamp() throws Exception {
    String stampSource = "https://www.example.com";
    SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
    TestComponent.useTestModule(this, createTestModuleBuilder().withOutputPath(outputFilePath).withSigningConfig(signingConfiguration).withSourceStamp(SourceStamp.builder().setSource(stampSource).setSigningConfiguration(signingConfiguration).build()).build());
    buildApksManager.execute();
    ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
    BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
    for (Variant variant : result.getVariantList()) {
        for (ApkSet apkSet : variant.getApkSetList()) {
            for (ApkDescription apkDescription : apkSet.getApkDescriptionList()) {
                File apk = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), outputDir);
                ApkVerifier.Result verifierResult = new ApkVerifier.Builder(apk).build().verify();
                assertThat(verifierResult.isSourceStampVerified()).isTrue();
                assertThat(verifierResult.getSourceStampInfo().getCertificate()).isEqualTo(certificate);
                AndroidManifest manifest = extractAndroidManifest(apk, tmpDir);
                assertThat(manifest.getMetadataValue(STAMP_SOURCE_METADATA_KEY)).hasValue(stampSource);
                try (ZipFile apkZip = new ZipFile(apk)) {
                    ZipEntry sourceStampCertEntry = apkZip.getEntry("stamp-cert-sha256");
                    assertNotNull(sourceStampCertEntry);
                    byte[] sourceStampCertHash = ByteStreams.toByteArray(apkZip.getInputStream(sourceStampCertEntry));
                    assertThat(sourceStampCertHash).isEqualTo(CertificateHelper.getSha256Bytes(certificate.getEncoded()));
                }
            }
        }
    }
}
Also used : ApkSet(com.android.bundle.Commands.ApkSet) ApkDescription(com.android.bundle.Commands.ApkDescription) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) ZipEntry(java.util.zip.ZipEntry) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) TestUtils.extractAndroidManifest(com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest) Variant(com.android.bundle.Commands.Variant) ZipFile(java.util.zip.ZipFile) ApkVerifier(com.android.apksig.ApkVerifier) ApkSetUtils.parseTocFromFile(com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile) CodeRelatedFile(com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile) ZipFile(java.util.zip.ZipFile) ApkSetUtils.extractTocFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) Test(org.junit.Test)

Aggregations

ApkSet (com.android.bundle.Commands.ApkSet)30 BuildApksResult (com.android.bundle.Commands.BuildApksResult)29 ZipFile (java.util.zip.ZipFile)29 Test (org.junit.Test)29 Variant (com.android.bundle.Commands.Variant)28 Path (java.nio.file.Path)25 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)22 ApkDescription (com.android.bundle.Commands.ApkDescription)20 AppBundle (com.android.tools.build.bundletool.model.AppBundle)20 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)20 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)20 BundleConfigBuilder (com.android.tools.build.bundletool.testing.BundleConfigBuilder)20 File (java.io.File)20 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)19 ApkVerifier (com.android.apksig.ApkVerifier)18 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)18 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)18 ZipPath (com.android.tools.build.bundletool.model.ZipPath)18 ResultUtils.splitApkVariants (com.android.tools.build.bundletool.model.utils.ResultUtils.splitApkVariants)18 ResultUtils.standaloneApkVariants (com.android.tools.build.bundletool.model.utils.ResultUtils.standaloneApkVariants)18