Search in sources :

Example 11 with ApexImages

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");
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 12 with ApexImages

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'.");
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 13 with ApexImages

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);
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) Test(org.junit.Test)

Example 14 with ApexImages

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());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AbiName(com.android.tools.build.bundletool.model.AbiName) Arrays(java.util.Arrays) ZipPath(com.android.tools.build.bundletool.model.ZipPath) TargetingUtils.textureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionTargeting) RunWith(org.junit.runner.RunWith) TargetingUtils.alternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting) TargetingUtils.deviceTierTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.deviceTierTargeting) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) ImmutableList(com.google.common.collect.ImmutableList) AssetsDirectoryTargeting(com.android.bundle.Targeting.AssetsDirectoryTargeting) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) TargetingUtils.mergeAssetsTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeAssetsTargeting) ImmutableSet(com.google.common.collect.ImmutableSet) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) NativeLibraries(com.android.bundle.Files.NativeLibraries) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) ApexImages(com.android.bundle.Files.ApexImages) List(java.util.List) SanitizerAlias(com.android.bundle.Targeting.Sanitizer.SanitizerAlias) TargetedAssetsDirectory(com.android.bundle.Files.TargetedAssetsDirectory) Assets(com.android.bundle.Files.Assets) TargetedNativeDirectory(com.android.bundle.Files.TargetedNativeDirectory) TextureCompressionFormatAlias(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) Joiner(com.google.common.base.Joiner) ApexImages(com.android.bundle.Files.ApexImages) ZipPath(com.android.tools.build.bundletool.model.ZipPath) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) Test(org.junit.Test)

Example 15 with ApexImages

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());
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlNode(com.android.aapt.Resources.XmlNode) ApexImages(com.android.bundle.Files.ApexImages) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Test(org.junit.Test)

Aggregations

ApexImages (com.android.bundle.Files.ApexImages)24 Test (org.junit.Test)20 BundleModule (com.android.tools.build.bundletool.model.BundleModule)13 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)12 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)11 ZipPath (com.android.tools.build.bundletool.model.ZipPath)8 AbiAlias (com.android.bundle.Targeting.Abi.AbiAlias)7 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)7 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableSet (com.google.common.collect.ImmutableSet)7 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)6 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)6 IOException (java.io.IOException)6 Path (java.nio.file.Path)5 ZipFile (java.util.zip.ZipFile)5 BundleConfig (com.android.bundle.Config.BundleConfig)4 AppBundle (com.android.tools.build.bundletool.model.AppBundle)4 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 NativeLibraries (com.android.bundle.Files.NativeLibraries)3 AssetsDirectoryTargeting (com.android.bundle.Targeting.AssetsDirectoryTargeting)3