com.android.tools.build.bundletool.model.BundleModule Java Examples
The following examples show how to use
com.android.tools.build.bundletool.model.BundleModule.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BundleModuleMerger.java From bundletool with Apache License 2.0 | 6 votes |
private static void mergeAndroidManifest( ImmutableSet<BundleModule> bundleModulesToFuse, BundleModule.Builder mergedBaseModule) { HashMultimap<BundleModuleName, AndroidManifest> manifests = bundleModulesToFuse.stream() .collect( toMultimap( BundleModule::getName, BundleModule::getAndroidManifest, HashMultimap::create)); AndroidManifest mergedManifest = new FusingAndroidManifestMerger().merge(manifests); mergedManifest = mergedManifest .toEditor() .setFusedModuleNames( bundleModulesToFuse.stream() .map(module -> module.getName().getName()) .collect(toImmutableList())) .save(); mergedBaseModule.setAndroidManifest(mergedManifest); }
Example #2
Source File: ModuleDependencyValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateAllModules_assetModuleHasDependency_throws() throws Exception { ImmutableList<BundleModule> allModules = ImmutableList.of( module("base", androidManifest(PKG_NAME)), module( "asset", androidManifestForAssetModule( PKG_NAME, withOnDemandDelivery(), withUsesSplit("feature"))), module("feature", androidManifest(PKG_NAME, withOnDemandDelivery()))); InvalidBundleException exception = assertThrows( InvalidBundleException.class, () -> new ModuleDependencyValidator().validateAllModules(allModules)); assertThat(exception) .hasMessageThat() .contains( "Module 'asset' cannot depend on module 'feature' because one of them is an asset" + " pack."); }
Example #3
Source File: TextureCompressionFormatParityValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void sameTCFsAndNoTCF_ok() throws Exception { BundleModule moduleA = new BundleModuleBuilder("a") .addFile("assets/textures#tcf_astc/level1.assets") .addFile("assets/textures#tcf_etc2/level1.assets") .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleB = new BundleModuleBuilder("b") .addFile("assets/other_textures#tcf_astc/astc_file.assets") .addFile("assets/other_textures#tcf_etc2/etc2_file.assets") .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleC = new BundleModuleBuilder("c") .addFile("assets/untargeted_textures/level3.assets") .setManifest(androidManifest("com.test.app")) .build(); new TextureCompressionFormatParityValidator() .validateAllModules(ImmutableList.of(moduleA, moduleB, moduleC)); }
Example #4
Source File: GraphicsApiAssetsSplitterTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void manifestMutatorToRequireSplits_notRegistered_whenNoGraphicsApiSpecificAssets() throws Exception { BundleModule testModule = new BundleModuleBuilder("testModule") .addFile("assets/other/file.dat") .setAssetsConfig( assets( targetedAssetsDirectory( "assets/other", AssetsDirectoryTargeting.getDefaultInstance()))) .setManifest(androidManifest("com.test.app")) .build(); ModuleSplit baseSplit = ModuleSplit.forAssets(testModule); ImmutableCollection<ModuleSplit> assetsSplits = GraphicsApiAssetsSplitter.create().split(baseSplit); assertThat(assetsSplits).hasSize(1); assertThat(assetsSplits.asList().get(0).getMasterManifestMutators()).isEmpty(); }
Example #5
Source File: AndroidManifestValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void withMaxSdkLessThanInstantSdk_throws() throws Exception { BundleModule module = new BundleModuleBuilder(FEATURE_MODULE_NAME) .setManifest( androidManifest( PKG_NAME, withInstant(true), withOnDemandAttribute(false), withFusingAttribute(false), withMaxSdkVersion(18))) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new AndroidManifestValidator().validateModule(module)); assertThat(e) .hasMessageThat() .isEqualTo("maxSdkVersion (18) is less than minimum sdk allowed for instant apps (21)."); }
Example #6
Source File: AssetModuleFilesValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void moduleWithNativeConfig_throws() throws Exception { NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(DXT1))); BundleModule module = new BundleModuleBuilder(MODULE_NAME) .setManifest(androidManifestForAssetModule(PKG_NAME)) .setNativeConfig(config) .build(); InvalidBundleException exception = assertThrows( InvalidBundleException.class, () -> new AssetModuleFilesValidator().validateModule(module)); assertThat(exception) .hasMessageThat() .matches("Native libraries config not allowed in asset packs, but found in 'assetmodule'."); }
Example #7
Source File: AssetsTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_defaultInstanceOfLanguageTargeting_throws() throws Exception { Assets config = assets( targetedAssetsDirectory( "assets/dir", AssetsDirectoryTargeting.newBuilder() .setLanguage(LanguageTargeting.getDefaultInstance()) .build())); BundleModule module = new BundleModuleBuilder("testModule") .addFile("assets/dir/raw.dat") .setAssetsConfig(config) .setManifest(androidManifestForAssetModule("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new AssetsTargetingValidator().validateModule(module)); assertThat(e).hasMessageThat().contains("set but empty language targeting"); }
Example #8
Source File: BundleModuleMerger.java From bundletool with Apache License 2.0 | 6 votes |
private static ImmutableSet<ModuleEntry> getAllEntriesExceptDexAndSpecial( Set<BundleModule> bundleModulesToFuse) { Map<ZipPath, ModuleEntry> mergedEntriesByPath = new HashMap<>(); bundleModulesToFuse.stream() .flatMap(module -> module.getEntries().stream()) .filter( moduleEntry -> !moduleEntry.getPath().startsWith(DEX_DIRECTORY) && !moduleEntry.isSpecialEntry()) .forEach( moduleEntry -> { ModuleEntry existingModuleEntry = mergedEntriesByPath.putIfAbsent(moduleEntry.getPath(), moduleEntry); if (existingModuleEntry != null && !existingModuleEntry.equals(moduleEntry)) { throw InvalidBundleException.builder() .withUserMessage( "Existing module entry '%s' with different contents.", moduleEntry.getPath()) .build(); } }); return ImmutableSet.copyOf(mergedEntriesByPath.values()); }
Example #9
Source File: AppBundle64BitNativeLibrariesPreprocessor.java From bundletool with Apache License 2.0 | 6 votes |
private static BundleModule processModule(BundleModule module) { Optional<NativeLibraries> nativeConfig = module.getNativeConfig(); if (!nativeConfig.isPresent()) { return module; } ImmutableSet<TargetedNativeDirectory> dirsToRemove = get64BitTargetedNativeDirectories(nativeConfig.get()); if (dirsToRemove.isEmpty()) { return module; } if (dirsToRemove.size() == nativeConfig.get().getDirectoryCount()) { throw InvalidBundleException.builder() .withUserMessage( "Usage of 64-bit native libraries is disabled by the presence of a " + "renderscript file, but App Bundle contains only 64-bit native libraries.") .build(); } return module.toBuilder() .setRawEntries(processEntries(module.getEntries(), dirsToRemove)) .setNativeConfig(processTargeting(nativeConfig.get(), dirsToRemove)) .build(); }
Example #10
Source File: NativeTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_pointDirectlyToLib_throws() throws Exception { NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/", nativeDirectoryTargeting(X86_64))); BundleModule module = new BundleModuleBuilder("testModule") .setNativeConfig(config) .setManifest(androidManifest("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module)); assertThat(e).hasMessageThat().contains("directory must be in format 'lib/<directory>'"); }
Example #11
Source File: TargetingGenerator.java From bundletool with Apache License 2.0 | 6 votes |
/** * Generates APEX targeting based on the names of the APEX image files. * * @param apexImageFiles names of all files under apex/, including the "apex/" prefix. * @param hasBuildInfo if true then each APEX image file has a corresponding build info file. * @return Targeting for all APEX image files. */ public ApexImages generateTargetingForApexImages( Collection<ZipPath> apexImageFiles, boolean hasBuildInfo) { ImmutableMap<ZipPath, MultiAbi> targetingByPath = Maps.toMap(apexImageFiles, path -> buildMultiAbi(path.getFileName().toString())); ApexImages.Builder apexImages = ApexImages.newBuilder(); ImmutableSet<MultiAbi> allTargeting = ImmutableSet.copyOf(targetingByPath.values()); targetingByPath.forEach( (imagePath, targeting) -> apexImages.addImage( TargetedApexImage.newBuilder() .setPath(imagePath.toString()) .setBuildInfoPath( hasBuildInfo ? imagePath .toString() .replace( BundleModule.APEX_IMAGE_SUFFIX, BundleModule.BUILD_INFO_SUFFIX) : "") .setTargeting(buildApexTargetingWithAlternatives(targeting, allTargeting)))); return apexImages.build(); }
Example #12
Source File: ModuleNamesValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void splitIdSetOnBaseModule() { BundleModule base = buildBundleModule("base") .setAndroidManifestProto(androidManifest("com.app", withSplitId("base"))) .build(); InvalidBundleException expected = assertThrows( InvalidBundleException.class, () -> new ModuleNamesValidator().validateAllModules(ImmutableList.of(base))); assertThat(expected) .hasMessageThat() .contains( "The base module should not have the 'split' attribute set in the AndroidManifest.xml"); }
Example #13
Source File: ModuleSplitterTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void testModuleSplitter_baseSplit_addsStamp() throws Exception { String stampSource = "https://www.validsource.com"; StampType stampType = StampType.STAMP_TYPE_DISTRIBUTION_APK; BundleModule bundleModule = new BundleModuleBuilder("base").setManifest(androidManifest("com.test.app")).build(); ModuleSplitter moduleSplitter = ModuleSplitter.create( bundleModule, BUNDLETOOL_VERSION, ApkGenerationConfiguration.getDefaultInstance(), lPlusVariantTargeting(), ImmutableSet.of("base"), Optional.of(stampSource), stampType); List<ModuleSplit> splits = moduleSplitter.splitModule(); // Base split assertThat(splits).hasSize(1); ModuleSplit baseSplit = getOnlyElement(splits); assertThat(baseSplit.getAndroidManifest().getMetadataValue(STAMP_TYPE_METADATA_KEY)) .hasValue(stampType.toString()); assertThat(baseSplit.getAndroidManifest().getMetadataValue(STAMP_SOURCE_METADATA_KEY)) .hasValue(stampSource); }
Example #14
Source File: AndroidManifestValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void installTimeAndOnDemandDeliveryAndInstantAttributeSetToTrue_ok() throws Exception { // On-demand delivery element does not make a module on-demand if install-time element is // present. BundleModule module = new BundleModuleBuilder(FEATURE_MODULE_NAME) .setManifest( androidManifest( PKG_NAME, withInstallTimeDelivery(), withOnDemandDelivery(), withInstant(true), withFusingAttribute(true))) .build(); new AndroidManifestValidator().validateModule(module); }
Example #15
Source File: AbiParityValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void sameAbisAndNoAbi_ok() throws Exception { BundleModule moduleA = new BundleModuleBuilder("a") .addFile("lib/x86/lib1.so") .addFile("lib/mips/lib2.so") .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleB = new BundleModuleBuilder("b") .addFile("lib/x86/lib3.so") .addFile("lib/mips/lib4.so") .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleC = new BundleModuleBuilder("c").setManifest(androidManifest("com.test.app")).build(); new AbiParityValidator().validateAllModules(ImmutableList.of(moduleA, moduleB, moduleC)); }
Example #16
Source File: ModuleDependencyValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateAllModules_instantModuleToInstallTimeDependency_throws() throws Exception { ImmutableList<BundleModule> allModules = ImmutableList.of( module("base", androidManifest(PKG_NAME, withInstant(true))), module("feature1", androidManifest(PKG_NAME, withInstant(false))), module( "feature2", androidManifest(PKG_NAME, withUsesSplit("feature1"), withInstant(true)))); InvalidBundleException exception = assertThrows( InvalidBundleException.class, () -> new ModuleDependencyValidator().validateAllModules(allModules)); assertThat(exception) .hasMessageThat() .contains( "Instant module 'feature2' cannot depend on a module 'feature1' that is not instant."); }
Example #17
Source File: LanguageResourcesSplitterTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void resourcesPinnedToMasterSplit_emptySplitsNotCreated() throws Exception { ResourceTable resourceTable = getStringResourceTable( "welcome_label", ImmutableList.of(value("hello", locale("en")), value("bienvenue", locale("fr"))), "text2", ImmutableList.of(value("no worries", locale("en")), value("de rien", locale("fr")))); BundleModule module = new BundleModuleBuilder("testModule") .setResourceTable(resourceTable) .setManifest(androidManifest("com.test.app")) .build(); ModuleSplit baseSplit = ModuleSplit.forResources(module); LanguageResourcesSplitter languageSplitter = new LanguageResourcesSplitter(resource -> true); Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit); assertThat(languageSplits).hasSize(1); assertThat(Iterables.getOnlyElement(languageSplits).getResourceTable().get()) .isEqualTo(resourceTable); }
Example #18
Source File: NativeTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_abiTargetingDimensionNotSet_throws() throws Exception { NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(DXT1))); BundleModule module = new BundleModuleBuilder("testModule") .addFile("lib/x86/libX.so") .setNativeConfig(config) .setManifest(androidManifest("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module)); assertThat(e) .hasMessageThat() .contains("Targeted native directory 'lib/x86' does not have the ABI dimension set"); }
Example #19
Source File: AndroidManifestValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void withMinSdkLowerThanBase_throws() throws Exception { BundleModule base = baseModule(withMinSdkVersion(20)); BundleModule module = new BundleModuleBuilder(FEATURE_MODULE_NAME) .setManifest(androidManifest(PKG_NAME, withMinSdkVersion(19))) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new AndroidManifestValidator().validateAllModules(ImmutableList.of(base, module))); assertThat(e) .hasMessageThat() .contains( "cannot have a minSdkVersion attribute with a value lower than the one from the base" + " module"); }
Example #20
Source File: ApexBundleValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_missingPackageFromApexManifest_throws() throws Exception { BundleModule apexModule = new BundleModuleBuilder("apexTestModule") .setManifest(androidManifest(PKG_NAME)) .setApexConfig(APEX_CONFIG) .addFile(APEX_MANIFEST_PATH, ApexManifest.getDefaultInstance().toByteArray()) .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("APEX manifest must have a package name"); }
Example #21
Source File: AssetsTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_assetModuleLanguageTargeting_throws() throws Exception { Assets config = assets( targetedAssetsDirectory( "assets/dir#lang_en", assetsDirectoryTargeting(languageTargeting("en")))); BundleModule module = new BundleModuleBuilder("testModule") .addFile("assets/dir#lang_en/raw.dat") .setAssetsConfig(config) .setManifest(androidManifestForAssetModule("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new AssetsTargetingValidator().validateModule(module)); assertThat(e) .hasMessageThat() .contains( "Language targeting for asset packs is not supported, but found in module testModule."); }
Example #22
Source File: TextureCompressionFormatParityValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void sameTCFs_ok() throws Exception { BundleModule moduleA = new BundleModuleBuilder("a") .addFile("assets/textures#tcf_astc/level1.assets") .addFile("assets/textures#tcf_etc2/level1.assets") .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleB = new BundleModuleBuilder("b") .addFile("assets/other_textures#tcf_astc/astc_file.assets") .addFile("assets/other_textures#tcf_etc2/etc2_file.assets") .setManifest(androidManifest("com.test.app")) .build(); new TextureCompressionFormatParityValidator() .validateAllModules(ImmutableList.of(moduleA, moduleB)); }
Example #23
Source File: AndroidManifestValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void installTimeModuleNonRemovable_ok() throws Exception { ImmutableList<BundleModule> bundleModules = ImmutableList.of( new BundleModuleBuilder(BASE_MODULE_NAME) .addFile("assets/textures#tcf_astc/level1.assets") .setManifest(androidManifest("com.test")) .build(), new BundleModuleBuilder("asset_module") .addFile("assets/other_textures#tcf_astc/astc_file.assets") .setManifest( androidManifestForAssetModule( "com.test.app", withInstallTimeRemovableElement(false))) .build()); new AndroidManifestValidator().validateAllModules(bundleModules); }
Example #24
Source File: AndroidManifestValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void nonBase_withoutFusingConfig_throws() throws Exception { BundleModule module = new BundleModuleBuilder(FEATURE_MODULE_NAME) .setManifest(androidManifest(PKG_NAME, withOnDemandAttribute(true))) .build(); InvalidBundleException exception = assertThrows( InvalidBundleException.class, () -> new AndroidManifestValidator().validateModule(module)); assertThat(exception) .hasMessageThat() .contains("Module 'feature' must specify its fusing configuration in AndroidManifest.xml"); }
Example #25
Source File: ModuleDependencyValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateAllModules_conditionalModule_dependsOnSomething_throws() throws Exception { ImmutableList<BundleModule> allModules = ImmutableList.of( module("base", androidManifest(PKG_NAME)), module( "conditional", androidManifest( PKG_NAME, withFeatureCondition("android.feature"), withUsesSplit("conditional2"))), module( "conditional2", androidManifest(PKG_NAME, withFeatureCondition("android.feature2")))); InvalidBundleException exception = assertThrows( InvalidBundleException.class, () -> new ModuleDependencyValidator().validateAllModules(allModules)); assertThat(exception) .hasMessageThat() .contains( "Conditional module 'conditional' cannot have dependencies but uses module " + "'conditional2'"); }
Example #26
Source File: ScreenDensityResourcesSplitterTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void lowestDensityStylesPinnedToMaster_enabled() 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= */ true); ImmutableCollection<ModuleSplit> splits = splitter.split(ModuleSplit.forResources(testModule)); ModuleSplit masterSplit = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement()); assertThat(extractStyleValues(masterSplit, "title_text_size")).containsExactly("default"); ModuleSplit xhdpiSplit = extractDensityTargetingModule(splits, DensityAlias.XXHDPI).get(); assertThat(extractStyleValues(xhdpiSplit, "title_text_size")).containsExactly("320dens"); Optional<ModuleSplit> mdpiSplit = extractDensityTargetingModule(splits, DensityAlias.MDPI); assertThat(mdpiSplit).isEmpty(); }
Example #27
Source File: AbiNativeLibrariesSplitterTest.java From bundletool with Apache License 2.0 | 5 votes |
/** Creates a minimal module with one native library targeted at the given cpu architecture. */ private static BundleModule createSingleLibraryModule( String moduleName, String architecture, String relativeFilePath) throws Exception { NativeLibraries nativeConfig = nativeLibraries( targetedNativeDirectory("lib/" + architecture, nativeDirectoryTargeting(architecture))); return new BundleModuleBuilder(moduleName) .addFile(relativeFilePath) .setNativeConfig(nativeConfig) .setManifest(androidManifest("com.test.app")) .build(); }
Example #28
Source File: AssetBundleValidatorTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void validateAllModules_validAssetOnly_succeeds() throws Exception { ImmutableList<BundleModule> allModules = ImmutableList.of(assetOnlyModule("asset", androidManifestForAssetModule(PKG_NAME))); new AssetBundleValidator().validateAllModules(allModules); }
Example #29
Source File: ModuleDependencyValidatorTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void validateAllModules_onDemandToOnDemandModulesDependency_succeeds() throws Exception { ImmutableList<BundleModule> allModules = ImmutableList.of( module("base", androidManifest(PKG_NAME)), module("feature1", androidManifest(PKG_NAME, withOnDemandAttribute(true))), module( "feature2", androidManifest(PKG_NAME, withOnDemandAttribute(true), withUsesSplit("feature1")))); new ModuleDependencyValidator().validateAllModules(allModules); }
Example #30
Source File: AssetSlicesGeneratorTest.java From bundletool with Apache License 2.0 | 5 votes |
private static AppBundle createAppBundle(BundleModule... assetModules) throws Exception { AppBundleBuilder appBundleBuilder = new AppBundleBuilder() .addModule( new BundleModuleBuilder("base") .setManifest(androidManifest(PACKAGE_NAME, withVersionCode(VERSION_CODE))) .build()); for (BundleModule assetModule : assetModules) { appBundleBuilder.addModule(assetModule); } return appBundleBuilder.build(); }