use of com.android.bundle.Files.ApexImages in project bundletool by google.
the class ApexBundleValidatorTest method validateModule_missingTargetedImageFile_throws.
@Test
public void validateModule_missingTargetedImageFile_throws() throws Exception {
ApexImages apexConfig = APEX_CONFIG.toBuilder().addImage(TargetedApexImage.newBuilder().setPath("apex/x86_64.x86.img")).build();
BundleModule apexModule = new BundleModuleBuilder("apexTestModule").setManifest(androidManifest(PKG_NAME)).setApexConfig(apexConfig).addFile(APEX_MANIFEST_PATH, APEX_MANIFEST).addFile("apex/x86_64.img").addFile("apex/x86.img").addFile("apex/armeabi-v7a.img").addFile("apex/arm64-v8a.img").build();
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ApexBundleValidator().validateModule(apexModule));
assertThat(exception).hasMessageThat().contains("Targeted APEX image files are missing");
}
use of com.android.bundle.Files.ApexImages in project bundletool by google.
the class AssetModuleFilesValidatorTest method moduleWithApexConfig_throws.
@Test
public void moduleWithApexConfig_throws() throws Exception {
ApexImages apexConfig = ApexImages.newBuilder().addImage(TargetedApexImage.newBuilder().setPath("apex/x86_64.img")).build();
BundleModule module = new BundleModuleBuilder(MODULE_NAME).setManifest(androidManifestForAssetModule(PKG_NAME)).setApexConfig(apexConfig).build();
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new AssetModuleFilesValidator().validateModule(module));
assertThat(exception).hasMessageThat().matches("Apex config not allowed in asset packs, but found in 'assetmodule'.");
}
use of com.android.bundle.Files.ApexImages in project bundletool by google.
the class TargetingUtilsTest method apexImages.
@Test
public void apexImages() {
TargetedApexImage firstTargeting = TargetedApexImage.newBuilder().setPath("path1").build();
TargetedApexImage secondTargeting = TargetedApexImage.newBuilder().setPath("path2").build();
ApexImages apexImages = TargetingUtils.apexImages(firstTargeting, secondTargeting);
assertThat(apexImages.getImageList()).containsExactly(firstTargeting, secondTargeting);
}
use of com.android.bundle.Files.ApexImages in project bundletool by google.
the class TargetingGeneratorTest method generateTargetingForApexImages_createsAllTargeting.
@Test
public void generateTargetingForApexImages_createsAllTargeting() throws Exception {
ImmutableSet<String> abis = Arrays.stream(AbiName.values()).map(AbiName::getPlatformName).collect(toImmutableSet());
Set<String> abiPairs = Sets.cartesianProduct(abis, abis).stream().map(pair -> Joiner.on('.').join(pair)).collect(toImmutableSet());
Collection<ZipPath> allAbiFiles = Sets.union(abis, abiPairs).stream().map(abi -> ZipPath.create(abi + ".img")).collect(toImmutableList());
// Otherwise this test is useless.
checkState(allAbiFiles.size() > 1);
ApexImages apexImages = generator.generateTargetingForApexImages(allAbiFiles, /*hasBuildInfo=*/
true);
List<TargetedApexImage> images = apexImages.getImageList();
assertThat(images).hasSize(allAbiFiles.size());
}
use of com.android.bundle.Files.ApexImages in project bundletool by google.
the class BuildBundleCommandTest method validApexModule.
@Test
public void validApexModule() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
ApexImages apexConfig = apexImages(targetedImageWithAlternatives("apex/x86_64.img", X86_64, targetedAbis), targetedImageWithAlternatives("apex/x86.img", X86, targetedAbis), targetedImageWithAlternatives("apex/arm64-v8a.img", ARM64_V8A, targetedAbis), targetedImageWithAlternatives("apex/armeabi-v7a.img", ARMEABI_V7A, targetedAbis));
byte[] apexManifest = "{\"name\": \"com.test.app\"}".getBytes(UTF_8);
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("apex/x86_64.img"), "x86_64".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("root/apex_manifest.json"), apexManifest).writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/apex/x86_64.img").withContent("x86_64".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.img").withContent("x86".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/root/apex_manifest.json").withContent(apexManifest);
assertThat(bundle).hasFile("base/apex.pb").withContent(apexConfig.toByteArray());
}
}
Aggregations