Search in sources :

Example 91 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class SanitizerNativeLibrariesSplitterTest method splittingNoSanitizerLib.

@Test
public void splittingNoSanitizerLib() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A)), targetedNativeDirectory("lib/arm64-v8a-hwasan", nativeDirectoryTargeting(ARM64_V8A, HWADDRESS)));
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setNativeConfig(nativeConfig).addFile("lib/arm64-v8a/libtest.so").setManifest(androidManifest("com.test.app")).build();
    SanitizerNativeLibrariesSplitter sanitizerNativeLibrariesSplitter = new SanitizerNativeLibrariesSplitter();
    ModuleSplit mainSplit = ModuleSplit.forNativeLibraries(bundleModule).toBuilder().setApkTargeting(apkAbiTargeting(ARM64_V8A)).setMasterSplit(false).build();
    ImmutableCollection<ModuleSplit> splits = sanitizerNativeLibrariesSplitter.split(mainSplit);
    assertThat(splits).hasSize(1);
    ModuleSplit nonHwasanSplit = splits.asList().get(0);
    assertThat(nonHwasanSplit.getApkTargeting()).isEqualTo(apkAbiTargeting(ARM64_V8A));
    assertThat(extractPaths(nonHwasanSplit.getEntries())).containsExactly("lib/arm64-v8a/libtest.so");
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 92 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class SanitizerNativeLibrariesSplitterTest method splittingBySanitizer.

@Test
public void splittingBySanitizer() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A)), targetedNativeDirectory("lib/arm64-v8a-hwasan", nativeDirectoryTargeting(ARM64_V8A, HWADDRESS)));
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setNativeConfig(nativeConfig).addFile("lib/arm64-v8a/libtest.so").addFile("lib/arm64-v8a-hwasan/libtest.so").setManifest(androidManifest("com.test.app")).build();
    SanitizerNativeLibrariesSplitter sanitizerNativeLibrariesSplitter = new SanitizerNativeLibrariesSplitter();
    ModuleSplit mainSplit = ModuleSplit.forNativeLibraries(bundleModule).toBuilder().setApkTargeting(apkAbiTargeting(ARM64_V8A)).setMasterSplit(false).build();
    ImmutableCollection<ModuleSplit> splits = sanitizerNativeLibrariesSplitter.split(mainSplit);
    assertThat(splits).hasSize(2);
    ModuleSplit nonHwasanSplit = splits.asList().get(1);
    assertThat(nonHwasanSplit.getApkTargeting()).isEqualTo(apkAbiTargeting(ARM64_V8A));
    assertThat(extractPaths(nonHwasanSplit.getEntries())).containsExactly("lib/arm64-v8a/libtest.so");
    ModuleSplit hwasanSplit = splits.asList().get(0);
    assertThat(hwasanSplit.getApkTargeting()).isEqualTo(mergeApkTargeting(apkAbiTargeting(ARM64_V8A), apkSanitizerTargeting(HWADDRESS)));
    assertThat(extractPaths(hwasanSplit.getEntries())).containsExactly("lib/arm64-v8a-hwasan/libtest.so");
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 93 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class ScreenDensityResourcesSplitterTest method complexDensitySplit.

@Test
public void complexDensitySplit() throws Exception {
    ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "mipmap", entry(0x01, "launcher_icon", fileReference("res/mipmap-hdpi/launcher_icon.png", HDPI), fileReference("res/mipmap/launcher_icon.png", Configuration.getDefaultInstance()))), type(0x02, "drawable", entry(0x01, "title_image", fileReference("res/drawable-hdpi/title_image.jpg", HDPI), fileReference("res/drawable-xhdpi/title_image.jpg", XHDPI)))));
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/mipmap/launcher_icon.png").addFile("res/mipmap-hdpi/launcher_icon.png").addFile("res/drawable-hdpi/title_image.jpg").addFile("res/drawable-xhdpi/title_image.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<ModuleSplit> allSplits = splitter.split(ModuleSplit.forResources(testModule));
    assertThat(allSplits).hasSize(DEFAULT_DENSITY_BUCKETS.size() + 1);
    assertForSingleDefaultSplit(allSplits, defaultSplit -> {
        assertThat(defaultSplit.getResourceTable()).isPresent();
        ResourceTable resourceTable = defaultSplit.getResourceTable().get();
        assertThat(resourceTable).containsResource("com.test.app:mipmap/launcher_icon").withConfigSize(2).withDensity(HDPI_VALUE).withDensity(DEFAULT_DENSITY_VALUE);
        assertThat(resourceTable).doesNotContainResource("com.test.app:drawable/title_image");
    });
    assertForNonDefaultSplits(allSplits, densitySplit -> {
        assertThat(densitySplit.getResourceTable()).isPresent();
        ResourceTable resourceTable = densitySplit.getResourceTable().get();
        assertThat(resourceTable).hasPackage("com.test.app").withNoType("mipmap");
        assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").withConfigSize(1);
        assertThat(densitySplit.getApkTargeting().hasScreenDensityTargeting()).isTrue();
        switch(densitySplit.getApkTargeting().getScreenDensityTargeting().getValue(0).getDensityAlias()) {
            case LDPI:
            case MDPI:
            case TVDPI:
            case HDPI:
                assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").onlyWithConfigs(HDPI);
                break;
            case XHDPI:
            case XXHDPI:
            case XXXHDPI:
                assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").onlyWithConfigs(XHDPI);
                break;
            default:
                fail(String.format("Unexpected targeting: %s", densitySplit.getApkTargeting()));
                break;
        }
    });
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 94 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class ScreenDensityResourcesSplitterTest method lowestDensityStylesPinnedToMaster_disabled.

@Test
public void lowestDensityStylesPinnedToMaster_disabled() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addResource("style", "title_text_size", configValueWithDensity("320dens", Optional.of(XHDPI)), configValueWithDensity("default", Optional.empty())).build()).setManifest(androidManifest("com.test.app")).build();
    ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, NO_LOW_DENSITY_CONFIG_PINNED_TO_MASTER, /* pinLowestBucketOfStylesToMaster= */
    false);
    ImmutableCollection<ModuleSplit> splits = splitter.split(ModuleSplit.forResources(testModule));
    ModuleSplit masterSplit = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
    assertThat(extractStyleValues(masterSplit, "title_text_size")).isEmpty();
    ModuleSplit xhdpiSplit = extractDensityTargetingModule(splits, DensityAlias.XXHDPI).get();
    assertThat(extractStyleValues(xhdpiSplit, "title_text_size")).containsExactly("320dens");
    ModuleSplit mdpiSplit = extractDensityTargetingModule(splits, DensityAlias.MDPI).get();
    assertThat(extractStyleValues(mdpiSplit, "title_text_size")).containsExactly("default");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 95 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class ScreenDensityResourcesSplitterTest method twoDensitiesInSameBucket.

@Test
public void twoDensitiesInSameBucket() throws Exception {
    ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-xxhdpi/image.png", XXHDPI), fileReference("res/drawable-560dpi/image.png", _560DPI), fileReference("res/drawable-xxxhdpi/image.png", XXXHDPI)))));
    BundleModule module = new BundleModuleBuilder("base").addFile("res/drawable-xxhdpi/image.png").addFile("res/drawable-560dpi/image.png").addFile("res/drawable-xxxhdpi/image.png").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(module));
    ModuleSplit xxxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXXHDPI).build());
    assertThat(xxxhdpiSplit.getResourceTable()).isPresent();
    ResourceTable resourceTable = xxxhdpiSplit.getResourceTable().get();
    assertThat(resourceTable).containsResource("com.test.app:drawable/image").withConfigSize(2).withDensity(XXXHDPI_VALUE).withDensity(560);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

BundleModule (com.android.tools.build.bundletool.model.BundleModule)404 Test (org.junit.Test)370 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)158 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)112 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)42 ResourceTable (com.android.aapt.Resources.ResourceTable)40 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)29 ImmutableList (com.google.common.collect.ImmutableList)27 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)24 ImmutableSet (com.google.common.collect.ImmutableSet)22 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)21 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 AppBundle (com.android.tools.build.bundletool.model.AppBundle)15 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)15 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 Truth.assertThat (com.google.common.truth.Truth.assertThat)15 RunWith (org.junit.runner.RunWith)15 Assets (com.android.bundle.Files.Assets)14 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)14