use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksValidationTest method splits_textureDefaultSuffixNotPresentInAssetPacks.
@Test
public void splits_textureDefaultSuffixNotPresentInAssetPacks() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_tcf_assets", builder -> builder.addFile("assets/textures/untargeted_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", assetsDirectoryTargeting(alternativeTextureCompressionTargeting(ETC1_RGB8))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false, /* stripSuffix= */
false, /* defaultSuffix= */
"astc").build()).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
// ASTC format is not present in one module with TCF targeting, so we'll
// consider the bundle invalid as the configuration specified that this is the default
// format to use for generating standalone or universal APKs.
InvalidBundleException exception = assertThrows(InvalidBundleException.class, command::execute);
assertThat(exception).hasMessageThat().contains("the texture folders for format 'ASTC' will be used, but module 'feature_tcf_assets'" + " has no such folders");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksValidationTest method buildApksCommand_appTargetingPreL_failsGeneratingInstant.
@Test
public void buildApksCommand_appTargetingPreL_failsGeneratingInstant() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.app", withInstant(true), withMaxSdkVersion(20)))).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
Throwable exception = assertThrows(InvalidBundleException.class, command::execute);
assertThat(exception).hasMessageThat().contains("maxSdkVersion (20) is less than minimum sdk allowed for instant apps (21).");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class CheckTransparencyCommandTest method bundleMode_verificationFailed_transparencyKeyCertificateNotProvidedByUser.
@Test
public void bundleMode_verificationFailed_transparencyKeyCertificateNotProvidedByUser() throws Exception {
// The public key transparencyKeyCertificate used to create JWS does not match the private key,
// and will result
// in signature verification failure later.
String serializedJws = createJwsToken(CodeTransparency.getDefaultInstance(), CertificateFactory.buildSelfSignedCertificate(kpg.generateKeyPair(), "CN=CheckTransparencyCommandTest_BadCertificate"), transparencyPrivateKey);
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app"))).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(serializedJws).asByteSource(Charset.defaultCharset()));
new AppBundleSerializer().writeToDisk(appBundle.build(), bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
CheckTransparencyCommand.builder().setMode(Mode.BUNDLE).setBundlePath(bundlePath).build().checkTransparency(new PrintStream(outputStream));
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).contains("No APK present. APK signature was not checked.");
assertThat(output).contains("Verification failed because code transparency signature is invalid.");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class DumpManagerTest method dumpManifest_moduleNotBase.
@Test
public void dumpManifest_moduleNotBase() throws Exception {
XmlNode manifestBase = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").addAttribute(XmlAttribute.newBuilder().setName("package").setValue("base"))).build();
XmlNode manifestModule = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").addAttribute(XmlAttribute.newBuilder().setName("package").setValue("module"))).build();
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifestBase)).addModule("module", module -> module.setManifest(manifestModule)).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setModuleName("module").setOutputStream(new PrintStream(outputStream)).build().execute();
assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("<manifest package=\"module\" split=\"module\"/>%n"));
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class DumpManagerTest method dumpManifest_withXPath_predicate.
@Test
public void dumpManifest_withXPath_predicate() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app", withMetadataValue("key1", "value1"), withMetadataValue("key2", "value2")))).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setXPathExpression("/manifest/application/meta-data[@android:name = \"key2\"]/@android:value").setOutputStream(new PrintStream(outputStream)).build().execute();
assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("value2%n"));
}
Aggregations