Search in sources :

Example 91 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method wholeResourcePinning_langResourcePinnedByName.

@Test
public void wholeResourcePinning_langResourcePinnedByName() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "string", entry(0x0001, "welcome_label", value("Welcome", Configuration.getDefaultInstance()), value("Willkommen", locale("de")), value("Здравствуйте", locale("ru"))), entry(0x0002, "goodbye_label", value("Goodbye", Configuration.getDefaultInstance()), value("Auf Wiedersehen", locale("de")), value("До свидания", locale("ru"))))))).setManifest(androidManifest("com.test.app")).build();
    ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp(baseModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(LANGUAGE)).setMasterPinnedResourceNames(ImmutableSet.of("welcome_label")).build(), lPlusVariantTargeting(), ImmutableSet.of("base"));
    ImmutableList<ModuleSplit> splits = moduleSplitter.splitModule();
    Map<String, ModuleSplit> splitsBySuffix = Maps.uniqueIndex(splits, ModuleSplit::getSuffix);
    assertThat(splitsBySuffix.keySet()).containsExactly("", "de", "ru");
    assertThat(splitsBySuffix.get("").getResourceTable().get()).containsResource("com.test.app:string/welcome_label").onlyWithConfigs(Configuration.getDefaultInstance(), locale("de"), locale("ru"));
    assertThat(splitsBySuffix.get("de").getResourceTable().get()).doesNotContainResource("com.test.app:string/welcome_label");
    assertThat(splitsBySuffix.get("ru").getResourceTable().get()).doesNotContainResource("com.test.app:string/welcome_label");
    assertThat(splitsBySuffix.get("").getResourceTable().get()).containsResource("com.test.app:string/goodbye_label").onlyWithConfigs(Configuration.getDefaultInstance());
    assertThat(splitsBySuffix.get("de").getResourceTable().get()).containsResource("com.test.app:string/goodbye_label").onlyWithConfigs(locale("de"));
    assertThat(splitsBySuffix.get("ru").getResourceTable().get()).containsResource("com.test.app:string/goodbye_label").onlyWithConfigs(locale("ru"));
}
Also used : 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 BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method testSplittingOnDensityAndLanguage_inSeparateDirectories.

@Test
public void testSplittingOnDensityAndLanguage_inSeparateDirectories() throws Exception {
    BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("res/drawable-xhdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable/image.jpg").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-xhdpi/image.jpg", XHDPI), fileReference("res/drawable-hdpi/image.jpg", HDPI), fileReference("res/drawable/image.jpg", Configuration.getDefaultInstance()))), type(0x02, "string", entry(0x01, "welcome_label", value("Welcome", Configuration.getDefaultInstance()), value("Willkommen", locale("de"))))))).setManifest(androidManifest("com.test.app")).build();
    List<ModuleSplit> splits = createAbiDensityAndLanguageSplitter(bundleModule).splitModule();
    assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
    assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
    Map<String, ModuleSplit> splitsBySuffix = Maps.uniqueIndex(splits, ModuleSplit::getSuffix);
    // 7 density splits (ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi, xxxhdpi) + 1 language split
    // (german)
    // + 1 master split = 9
    assertThat(splitsBySuffix.keySet()).containsExactly("ldpi", "mdpi", "tvdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi", "de", "");
    ImmutableSet<DensityAlias> densities = ImmutableSet.of(DensityAlias.LDPI, DensityAlias.MDPI, DensityAlias.TVDPI, DensityAlias.HDPI, DensityAlias.XHDPI, DensityAlias.XXHDPI, DensityAlias.XXXHDPI);
    assertThat(splitsBySuffix.get("ldpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI)))));
    assertThat(splitsBySuffix.get("mdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.MDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI)))));
    assertThat(splitsBySuffix.get("tvdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.TVDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI)))));
    assertThat(splitsBySuffix.get("hdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.HDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI)))));
    assertThat(splitsBySuffix.get("xhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI)))));
    assertThat(splitsBySuffix.get("xxhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XXHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI)))));
    assertThat(splitsBySuffix.get("xxxhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XXXHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI)))));
    assertThat(splitsBySuffix.get("de").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("de")));
    assertThat(splitsBySuffix.get("").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(DEFAULT_MASTER_SPLIT_SDK_TARGETING);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 93 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method nativeSplits_areGenerated.

@Test
public void nativeSplits_areGenerated() throws Exception {
    NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting("x86")));
    BundleModule testModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeConfig).addFile("lib/x86/liba.so").build();
    ImmutableList<ModuleSplit> splits = createAbiAndDensitySplitter(testModule).splitModule();
    assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
    assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
    assertThat(splits).hasSize(2);
    boolean hasMasterSplit = false;
    boolean hasX86Split = false;
    ApkTargeting x86SplitTargeting = mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkAbiTargeting(AbiAlias.X86));
    for (ModuleSplit split : splits) {
        if (split.getApkTargeting().equals(DEFAULT_MASTER_SPLIT_SDK_TARGETING)) {
            assertThat(split.isMasterSplit()).isTrue();
            hasMasterSplit = true;
        } else if (split.getApkTargeting().equals(x86SplitTargeting)) {
            assertThat(split.isMasterSplit()).isFalse();
            hasX86Split = true;
        } else {
            fail(String.format("Unexpected split targeting: %s", split.getApkTargeting()));
        }
    }
    assertThat(hasMasterSplit).isTrue();
    assertThat(hasX86Split).isTrue();
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) 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 94 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method resolvesSplitIdSuffixes_multipleVariants.

/**
 * Tests that modules belonging to different variants with potentially same splitId, aren't
 * resolved to different splitIds.
 */
@Test
public void resolvesSplitIdSuffixes_multipleVariants() throws Exception {
    ModuleSplit assetsSplit1 = ModuleSplit.builder().setModuleName(BundleModuleName.create("base")).setEntries(ImmutableList.of()).setApkTargeting(apkTextureTargeting(textureCompressionTargeting(ATC, ImmutableSet.of(S3TC)))).setMasterSplit(false).setAndroidManifest(AndroidManifest.create(androidManifest("com.test.app"))).setVariantTargeting(VariantTargeting.getDefaultInstance()).build();
    ModuleSplit assetsSplit2 = ModuleSplit.builder().setModuleName(BundleModuleName.create("base")).setEntries(ImmutableList.of()).setApkTargeting(apkTextureTargeting(textureCompressionTargeting(ATC, ImmutableSet.of(ETC1_RGB8)))).setMasterSplit(false).setAndroidManifest(AndroidManifest.create(androidManifest("com.test.app"))).setVariantTargeting(lPlusVariantTargeting()).build();
    BundleModule bundleModule = new BundleModuleBuilder("base").setManifest(androidManifest("com.test.app")).build();
    ModuleSplitter moduleSplitter = ModuleSplitter.createForTest(bundleModule, BUNDLETOOL_VERSION);
    assetsSplit1 = moduleSplitter.writeSplitIdInManifest(assetsSplit1);
    assetsSplit2 = moduleSplitter.writeSplitIdInManifest(assetsSplit2);
    assertThat(assetsSplit1.getAndroidManifest().getSplitId()).hasValue("config.atc");
    assertThat(assetsSplit2.getAndroidManifest().getSplitId()).hasValue("config.atc");
}
Also used : 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 95 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method nativeSplits_pPlusTargeting_withDexCompressionSplitter.

@Test
public void nativeSplits_pPlusTargeting_withDexCompressionSplitter() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).build();
    ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp(testModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setEnableDexCompressionSplitter(true).build(), variantMinSdkTargeting(ANDROID_Q_API_VERSION), ImmutableSet.of("testModule"));
    List<ModuleSplit> splits = moduleSplitter.splitModule();
    assertThat(splits).hasSize(1);
    ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);
    assertThat(moduleSplit.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(moduleSplit.getVariantTargeting()).isEqualTo(variantMinSdkTargeting(ANDROID_Q_API_VERSION));
    assertThat(moduleSplit.findEntry("dex/classes.dex").get().getForceUncompressed()).isTrue();
}
Also used : 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)

Aggregations

BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)349 Test (org.junit.Test)348 BundleModule (com.android.tools.build.bundletool.model.BundleModule)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)164 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)69 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)44 ResourceTable (com.android.aapt.Resources.ResourceTable)38 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)28 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)16 Truth.assertThat (com.google.common.truth.Truth.assertThat)16 RunWith (org.junit.runner.RunWith)16 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 ImmutableList (com.google.common.collect.ImmutableList)15 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)15 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)15 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)14 NativeLibraries (com.android.bundle.Files.NativeLibraries)13 HDPI (com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI)13 USER_PACKAGE_OFFSET (com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET)13