Search in sources :

Example 51 with BundleModuleBuilder

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

the class ModuleSplitterTest method pinSpecIsCopied.

@Test
public void pinSpecIsCopied() {
    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").addFile("assets/com.android.hints.pins.txt").build();
    ImmutableList<ModuleSplit> splits = createAbiAndDensitySplitter(testModule).splitModule();
    assertThat(splits).hasSize(2);
    assertThat(splits.stream().map((s) -> s.getEntries().stream().filter((e) -> e.getPath().endsWith(PinSpecInjector.PIN_SPEC_NAME)).count()).distinct()).containsExactly(1L);
}
Also used : ManifestProtoUtils.withSplitNameActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameActivity) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ResourcesTableFactory.locale(com.android.tools.build.bundletool.testing.ResourcesTableFactory.locale) TargetingUtils.textureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionTargeting) TargetingUtils.alternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting) SCREEN_DENSITY(com.android.tools.build.bundletool.model.OptimizationDimension.SCREEN_DENSITY) Predicates.not(com.google.common.base.Predicates.not) ResourceId(com.android.tools.build.bundletool.model.ResourceId) Map(java.util.Map) DEVICE_TIER(com.android.tools.build.bundletool.model.OptimizationDimension.DEVICE_TIER) TargetingUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting) ManifestMutator.withExtractNativeLibs(com.android.tools.build.bundletool.model.ManifestMutator.withExtractNativeLibs) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) Version(com.android.tools.build.bundletool.model.version.Version) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) ResourceTable(com.android.aapt.Resources.ResourceTable) SPLIT_NAME_RESOURCE_ID(com.android.tools.build.bundletool.model.AndroidManifest.SPLIT_NAME_RESOURCE_ID) ModuleSplitUtils.applyManifestMutators(com.android.tools.build.bundletool.testing.ModuleSplitUtils.applyManifestMutators) BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) ConfigValue(com.android.aapt.Resources.ConfigValue) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StampType(com.android.tools.build.bundletool.model.SourceStamp.StampType) ManifestProtoUtils.withMinSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMinSdkVersion) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) Assets(com.android.bundle.Files.Assets) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) STAMP_TYPE_METADATA_KEY(com.android.tools.build.bundletool.model.SourceStamp.STAMP_TYPE_METADATA_KEY) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Iterables(com.google.common.collect.Iterables) STAMP_SOURCE_METADATA_KEY(com.android.tools.build.bundletool.model.SourceStamp.STAMP_SOURCE_METADATA_KEY) TargetingUtils.variantMinSdkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantMinSdkTargeting) ZipPath(com.android.tools.build.bundletool.model.ZipPath) OptimizationDimension(com.android.tools.build.bundletool.model.OptimizationDimension) ATC(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ATC) RunWith(org.junit.runner.RunWith) TargetingUtils.apkMinSdkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkMinSdkTargeting) TEXTURE_COMPRESSION_FORMAT(com.android.tools.build.bundletool.model.OptimizationDimension.TEXTURE_COMPRESSION_FORMAT) TargetingUtils.getSplitsWithTargetingEqualTo(com.android.tools.build.bundletool.testing.TargetingUtils.getSplitsWithTargetingEqualTo) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) ANDROID_R_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_R_API_VERSION) LANGUAGE(com.android.tools.build.bundletool.model.OptimizationDimension.LANGUAGE) ManifestProtoUtils.withMetadataResource(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataResource) ResourcesTableFactory.mergeConfigs(com.android.tools.build.bundletool.testing.ResourcesTableFactory.mergeConfigs) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) XmlProtoElement(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElement) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) ANDROID_Q_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_Q_API_VERSION) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) SuffixStripping(com.android.bundle.Config.SuffixStripping) ManifestProtoUtils.clearApplication(com.android.tools.build.bundletool.testing.ManifestProtoUtils.clearApplication) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) HDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI) TargetingUtils.targetedNativeDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedNativeDirectory) TestCase.fail(junit.framework.TestCase.fail) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Test(org.junit.Test) ANDROID_L_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_L_API_VERSION) ANDROID_M_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_M_API_VERSION) TargetingUtils.assets(com.android.tools.build.bundletool.testing.TargetingUtils.assets) TargetingUtils.apkDensityTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDensityTargeting) XmlNode(com.android.aapt.Resources.XmlNode) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) ManifestProtoUtils.withMainActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMainActivity) ModuleSplitUtils.createModuleSplitBuilder(com.android.tools.build.bundletool.testing.ModuleSplitUtils.createModuleSplitBuilder) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModule(com.android.tools.build.bundletool.model.BundleModule) TargetingUtils.apkDeviceTierTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDeviceTierTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ManifestProtoUtils.xmlAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.xmlAttribute) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) ANDROID_NAMESPACE_URI(com.android.tools.build.bundletool.model.AndroidManifest.ANDROID_NAMESPACE_URI) TargetingUtils.deviceTierTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.deviceTierTargeting) TargetingUtils.targetedAssetsDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedAssetsDirectory) NAME_RESOURCE_ID(com.android.tools.build.bundletool.model.AndroidManifest.NAME_RESOURCE_ID) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) ImmutableSet(com.google.common.collect.ImmutableSet) ResourcesTableFactory.value(com.android.tools.build.bundletool.testing.ResourcesTableFactory.value) TargetingUtils.apkTextureTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkTextureTargeting) ImmutableMap(com.google.common.collect.ImmutableMap) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) NativeLibraries(com.android.bundle.Files.NativeLibraries) List(java.util.List) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Optional(java.util.Optional) ABI(com.android.tools.build.bundletool.model.OptimizationDimension.ABI) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) ManifestProtoUtils.withMaxSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMaxSdkVersion) TargetingUtils.apkAbiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkAbiTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) TargetingUtils.toAbi(com.android.tools.build.bundletool.testing.TargetingUtils.toAbi) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ACTIVITY_ELEMENT_NAME(com.android.tools.build.bundletool.model.AndroidManifest.ACTIVITY_ELEMENT_NAME) S3TC(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.S3TC) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ManifestProtoUtils.withInstant(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstant) APPLICATION_ELEMENT_NAME(com.android.tools.build.bundletool.model.AndroidManifest.APPLICATION_ELEMENT_NAME) JUnit4(org.junit.runners.JUnit4) XHDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.XHDPI) Truth.assertThat(com.google.common.truth.Truth.assertThat) ETC1_RGB8(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ETC1_RGB8) Maps(com.google.common.collect.Maps) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) TargetingUtils.nativeLibraries(com.android.tools.build.bundletool.testing.TargetingUtils.nativeLibraries) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Ignore(org.junit.Ignore) TargetingUtils.apkAlternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkAlternativeLanguageTargeting) XmlElement(com.android.aapt.Resources.XmlElement) Versions(com.android.tools.build.bundletool.model.utils.Versions) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) 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 52 with BundleModuleBuilder

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

the class ModuleSplitterTest method nativeSplits_lPlusTargeting_withAbiAndUncompressNativeLibsSplitter.

@Test
public void nativeSplits_lPlusTargeting_withAbiAndUncompressNativeLibsSplitter() 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();
    ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp(testModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(ABI)).setEnableUncompressedNativeLibraries(true).build(), lPlusVariantTargeting(), ImmutableSet.of("testModule"));
    List<ModuleSplit> splits = moduleSplitter.splitModule();
    // Base + X86 Split
    assertThat(splits).hasSize(2);
    assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
    assertThat(splits.stream().map(split -> split.getVariantTargeting()).collect(toImmutableSet())).containsExactly(variantMinSdkTargeting(ANDROID_L_API_VERSION));
    ModuleSplit master = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
    ModuleSplit abi = splits.stream().filter(not(ModuleSplit::isMasterSplit)).collect(onlyElement());
    assertThat(master.getAndroidManifest().getExtractNativeLibsValue()).hasValue(true);
    assertThat(abi.findEntry("lib/x86/liba.so").get().getForceUncompressed()).isFalse();
}
Also used : ManifestProtoUtils.withSplitNameActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameActivity) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ResourcesTableFactory.locale(com.android.tools.build.bundletool.testing.ResourcesTableFactory.locale) TargetingUtils.textureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionTargeting) TargetingUtils.alternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting) SCREEN_DENSITY(com.android.tools.build.bundletool.model.OptimizationDimension.SCREEN_DENSITY) Predicates.not(com.google.common.base.Predicates.not) ResourceId(com.android.tools.build.bundletool.model.ResourceId) Map(java.util.Map) DEVICE_TIER(com.android.tools.build.bundletool.model.OptimizationDimension.DEVICE_TIER) TargetingUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting) ManifestMutator.withExtractNativeLibs(com.android.tools.build.bundletool.model.ManifestMutator.withExtractNativeLibs) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) Version(com.android.tools.build.bundletool.model.version.Version) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) ResourceTable(com.android.aapt.Resources.ResourceTable) SPLIT_NAME_RESOURCE_ID(com.android.tools.build.bundletool.model.AndroidManifest.SPLIT_NAME_RESOURCE_ID) ModuleSplitUtils.applyManifestMutators(com.android.tools.build.bundletool.testing.ModuleSplitUtils.applyManifestMutators) BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) ConfigValue(com.android.aapt.Resources.ConfigValue) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) StampType(com.android.tools.build.bundletool.model.SourceStamp.StampType) ManifestProtoUtils.withMinSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMinSdkVersion) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) Assets(com.android.bundle.Files.Assets) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) STAMP_TYPE_METADATA_KEY(com.android.tools.build.bundletool.model.SourceStamp.STAMP_TYPE_METADATA_KEY) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Iterables(com.google.common.collect.Iterables) STAMP_SOURCE_METADATA_KEY(com.android.tools.build.bundletool.model.SourceStamp.STAMP_SOURCE_METADATA_KEY) TargetingUtils.variantMinSdkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantMinSdkTargeting) ZipPath(com.android.tools.build.bundletool.model.ZipPath) OptimizationDimension(com.android.tools.build.bundletool.model.OptimizationDimension) ATC(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ATC) RunWith(org.junit.runner.RunWith) TargetingUtils.apkMinSdkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkMinSdkTargeting) TEXTURE_COMPRESSION_FORMAT(com.android.tools.build.bundletool.model.OptimizationDimension.TEXTURE_COMPRESSION_FORMAT) TargetingUtils.getSplitsWithTargetingEqualTo(com.android.tools.build.bundletool.testing.TargetingUtils.getSplitsWithTargetingEqualTo) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) ANDROID_R_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_R_API_VERSION) LANGUAGE(com.android.tools.build.bundletool.model.OptimizationDimension.LANGUAGE) ManifestProtoUtils.withMetadataResource(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataResource) ResourcesTableFactory.mergeConfigs(com.android.tools.build.bundletool.testing.ResourcesTableFactory.mergeConfigs) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) XmlProtoElement(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElement) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) ANDROID_Q_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_Q_API_VERSION) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) SuffixStripping(com.android.bundle.Config.SuffixStripping) ManifestProtoUtils.clearApplication(com.android.tools.build.bundletool.testing.ManifestProtoUtils.clearApplication) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) HDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI) TargetingUtils.targetedNativeDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedNativeDirectory) TestCase.fail(junit.framework.TestCase.fail) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Test(org.junit.Test) ANDROID_L_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_L_API_VERSION) ANDROID_M_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_M_API_VERSION) TargetingUtils.assets(com.android.tools.build.bundletool.testing.TargetingUtils.assets) TargetingUtils.apkDensityTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDensityTargeting) XmlNode(com.android.aapt.Resources.XmlNode) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) ManifestProtoUtils.withMainActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMainActivity) ModuleSplitUtils.createModuleSplitBuilder(com.android.tools.build.bundletool.testing.ModuleSplitUtils.createModuleSplitBuilder) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModule(com.android.tools.build.bundletool.model.BundleModule) TargetingUtils.apkDeviceTierTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDeviceTierTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ManifestProtoUtils.xmlAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.xmlAttribute) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) ANDROID_NAMESPACE_URI(com.android.tools.build.bundletool.model.AndroidManifest.ANDROID_NAMESPACE_URI) TargetingUtils.deviceTierTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.deviceTierTargeting) TargetingUtils.targetedAssetsDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedAssetsDirectory) NAME_RESOURCE_ID(com.android.tools.build.bundletool.model.AndroidManifest.NAME_RESOURCE_ID) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) ImmutableSet(com.google.common.collect.ImmutableSet) ResourcesTableFactory.value(com.android.tools.build.bundletool.testing.ResourcesTableFactory.value) TargetingUtils.apkTextureTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkTextureTargeting) ImmutableMap(com.google.common.collect.ImmutableMap) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) NativeLibraries(com.android.bundle.Files.NativeLibraries) List(java.util.List) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Optional(java.util.Optional) ABI(com.android.tools.build.bundletool.model.OptimizationDimension.ABI) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) ManifestProtoUtils.withMaxSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMaxSdkVersion) TargetingUtils.apkAbiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkAbiTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) TargetingUtils.toAbi(com.android.tools.build.bundletool.testing.TargetingUtils.toAbi) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ACTIVITY_ELEMENT_NAME(com.android.tools.build.bundletool.model.AndroidManifest.ACTIVITY_ELEMENT_NAME) S3TC(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.S3TC) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ManifestProtoUtils.withInstant(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstant) APPLICATION_ELEMENT_NAME(com.android.tools.build.bundletool.model.AndroidManifest.APPLICATION_ELEMENT_NAME) JUnit4(org.junit.runners.JUnit4) XHDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.XHDPI) Truth.assertThat(com.google.common.truth.Truth.assertThat) ETC1_RGB8(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ETC1_RGB8) Maps(com.google.common.collect.Maps) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) TargetingUtils.nativeLibraries(com.android.tools.build.bundletool.testing.TargetingUtils.nativeLibraries) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Ignore(org.junit.Ignore) TargetingUtils.apkAlternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkAlternativeLanguageTargeting) XmlElement(com.android.aapt.Resources.XmlElement) Versions(com.android.tools.build.bundletool.model.utils.Versions) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) 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 53 with BundleModuleBuilder

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

the class ModuleSplitterTest method nativeSplits_mPlusTargeting_disabledUncompressedSplitter.

@Test
public void nativeSplits_mPlusTargeting_disabledUncompressedSplitter() {
    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();
    ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp(testModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(ABI)).setEnableUncompressedNativeLibraries(false).build(), variantMinSdkTargeting(ANDROID_M_API_VERSION), ImmutableSet.of("testModule"));
    List<ModuleSplit> splits = moduleSplitter.splitModule();
    assertThat(splits).hasSize(2);
    ModuleSplit master = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
    ModuleSplit abi = splits.stream().filter(not(ModuleSplit::isMasterSplit)).collect(onlyElement());
    assertThat(master.getAndroidManifest().getExtractNativeLibsValue()).hasValue(true);
    assertThat(abi.findEntry("lib/x86/liba.so").get().getForceUncompressed()).isFalse();
}
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 54 with BundleModuleBuilder

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

the class ModuleSplitterTest method applicationElementAdded.

@Test
public void applicationElementAdded() throws Exception {
    XmlNode manifest = androidManifest("com.test.app", clearApplication());
    checkState(!AndroidManifest.create(manifest).hasApplicationElement(), "Expected manifest with no <application> element.");
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(manifest).build();
    ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createForTest(bundleModule, BUNDLETOOL_VERSION).splitModule();
    assertThat(moduleSplits).hasSize(1);
    ModuleSplit masterSplit = moduleSplits.get(0);
    assertThat(masterSplit.getAndroidManifest().getManifestRoot().getElement().getOptionalChildElement(APPLICATION_ELEMENT_NAME)).isPresent();
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) 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 55 with BundleModuleBuilder

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

the class ModuleSplitterTest method manifestResourcePinning_langResourceWithoutDefaultConfig_pinned.

@Test
public void manifestResourcePinning_langResourceWithoutDefaultConfig_pinned() 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", locale("en")), value("Willkommen", locale("de")), value("Здравствуйте", locale("ru"))), entry(0x0002, "goodbye_label", value("Goodbye", locale("en")), value("Auf Wiedersehen", locale("de")), value("До свидания", locale("ru"))))))).setManifest(androidManifest("com.test.app", withMetadataResource("reference-to-resource", 0x7f010001))).build();
    ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp(baseModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(LANGUAGE)).setBaseManifestReachableResources(ImmutableSet.of(ResourceId.create(0x7f010001))).build(), lPlusVariantTargeting(), ImmutableSet.of("base"));
    ImmutableList<ModuleSplit> splits = moduleSplitter.splitModule();
    Map<String, ModuleSplit> splitsBySuffix = Maps.uniqueIndex(splits, ModuleSplit::getSuffix);
    assertThat(splitsBySuffix.keySet()).containsExactly("en", "de", "ru", "");
    assertThat(splitsBySuffix.get("").getResourceTable().get()).containsResource("com.test.app:string/welcome_label").onlyWithConfigs(locale("en"), locale("de"), locale("ru"));
    assertThat(splitsBySuffix.get("en").getResourceTable().get()).doesNotContainResource("com.test.app:string/welcome_label");
    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");
}
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