use of com.android.bundle.Files.Assets in project bundletool by google.
the class AssetsTargetingValidatorTest method validateModule_valid_succeeds.
@Test
public void validateModule_valid_succeeds() throws Exception {
Assets config = assets(targetedAssetsDirectory("assets/dir_other#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ETC1_RGB8))));
BundleModule module = new BundleModuleBuilder("testModule").addFile("assets/dir_other#tcf_etc1/raw.dat").setAssetsConfig(config).setManifest(androidManifest("com.test.app")).build();
new AssetsTargetingValidator().validateModule(module);
}
use of com.android.bundle.Files.Assets in project bundletool by google.
the class AssetsTargetingValidatorTest method validateModule_emptyTargetedDirectory_throws.
@Test
public void validateModule_emptyTargetedDirectory_throws() throws Exception {
Assets config = assets(targetedAssetsDirectory("assets/dir#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ETC1_RGB8))));
BundleModule module = new BundleModuleBuilder("testModule").setAssetsConfig(config).setManifest(androidManifest("com.test.app")).build();
InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new AssetsTargetingValidator().validateModule(module));
assertThat(e).hasMessageThat().contains("Targeted directory 'assets/dir#tcf_etc1' is empty.");
}
use of com.android.bundle.Files.Assets in project bundletool by google.
the class AssetsTargetingValidatorTest method validateModule_pointDirectlyToAssets_succeeds.
@Test
public void validateModule_pointDirectlyToAssets_succeeds() throws Exception {
Assets config = assets(targetedAssetsDirectory("assets", AssetsDirectoryTargeting.getDefaultInstance()));
BundleModule module = new BundleModuleBuilder("testModule").addFile("assets/file.dat").setAssetsConfig(config).setManifest(androidManifest("com.test.app")).build();
new AssetsTargetingValidator().validateModule(module);
}
use of com.android.bundle.Files.Assets in project bundletool by google.
the class AssetsTargetingValidator method validateTargeting.
private void validateTargeting(BundleModule module, Assets assets) {
ImmutableSet<ZipPath> assetDirsWithFiles = getDirectoriesWithFiles(module);
for (TargetedAssetsDirectory targetedDirectory : assets.getDirectoryList()) {
ZipPath path = ZipPath.create(targetedDirectory.getPath());
if (!path.startsWith(ASSETS_DIRECTORY)) {
throw InvalidBundleException.builder().withUserMessage("Path of targeted assets directory must start with 'assets/' but found '%s'.", path).build();
}
if (!assetDirsWithFiles.contains(path)) {
throw InvalidBundleException.builder().withUserMessage("Targeted directory '%s' is empty.", path).build();
}
checkNoDimensionWithoutValuesAndAlternatives(targetedDirectory);
}
if (module.getModuleType().equals(ModuleType.ASSET_MODULE) && assets.getDirectoryList().stream().anyMatch(dir -> dir.getTargeting().hasLanguage())) {
throw InvalidBundleException.builder().withUserMessage("Language targeting for asset packs is not supported, but found in module %s.", module.getName().getName()).build();
}
}
use of com.android.bundle.Files.Assets in project bundletool by google.
the class SuffixStripper method removeAssetsTargeting.
/**
* Updates the module to remove the specified targeting from the assets - both the directories in
* assets config and the associated module entries having the specified targeting will be updated.
*/
public ModuleSplit removeAssetsTargeting(ModuleSplit moduleSplit) {
if (!moduleSplit.getAssetsConfig().isPresent()) {
return moduleSplit;
}
// Update the targeted assets directory and their associated entries.
Assets assetsConfig = moduleSplit.getAssetsConfig().get();
Assets.Builder updatedAssetsConfig = assetsConfig.toBuilder().clearDirectory();
ImmutableList<ModuleEntry> updatedEntries = moduleSplit.getEntries();
for (TargetedAssetsDirectory targetedAssetsDirectory : assetsConfig.getDirectoryList()) {
TargetedAssetsDirectory updatedTargetedAssetsDirectory = removeAssetsTargetingFromDirectory(targetedAssetsDirectory);
// Remove the targeting from the entries path.
if (!updatedTargetedAssetsDirectory.equals(targetedAssetsDirectory)) {
// Update the associated entries
ZipPath directoryPath = ZipPath.create(targetedAssetsDirectory.getPath());
updatedEntries = updatedEntries.stream().map(entry -> {
if (entry.getPath().startsWith(directoryPath)) {
return removeTargetingFromEntry(entry);
}
return entry;
}).collect(toImmutableList());
}
updatedAssetsConfig.addDirectory(updatedTargetedAssetsDirectory);
}
return moduleSplit.toBuilder().setEntries(updatedEntries).setAssetsConfig(updatedAssetsConfig.build()).build();
}
Aggregations