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");
}
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");
}
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");
}
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");
}
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()));
}
}
}
}
}
Aggregations