use of com.android.bundle.Targeting.Abi in project bundletool by google.
the class TargetingUtilsTest method toAbi_validAbi_succeeds.
@Test
public void toAbi_validAbi_succeeds() {
Abi expectedAbi = Abi.newBuilder().setAlias(X86).build();
assertThat(TargetingUtils.toAbi("x86")).isEqualTo(expectedAbi);
}
use of com.android.bundle.Targeting.Abi in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTargeting.
@Test
public void buildApksCommand_standalone_mixedTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_abi_lib", builder -> builder.addFile("lib/x86/libfeature.so").addFile("lib/x86_64/libfeature.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("feature_lang_assets", builder -> builder.addFile("assets/strings#lang_en/trans.txt").addFile("assets/strings#lang_fr/trans.txt").setAssetsConfig(assets(targetedAssetsDirectory("assets/strings#lang_en", assetsDirectoryTargeting(languageTargeting("en"))), targetedAssetsDirectory("assets/strings#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("feature_tcf_assets", builder -> builder.addFile("assets/textures#tcf_atc/texture.dat").addFile("assets/textures#tcf_etc1/texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_atc", assetsDirectoryTargeting(textureCompressionTargeting(ATC))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(ABI).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<Abi, ApkDescription> standaloneApksByAbi = Maps.uniqueIndex(apkDescriptions(standaloneApkVariants(result)), apkDesc -> getOnlyElement(apkDesc.getTargeting().getAbiTargeting().getValueList()));
assertThat(standaloneApksByAbi.keySet()).containsExactly(toAbi(X86), toAbi(X86_64));
File x86ApkFile = extractFromApkSetFile(apkSetFile, standaloneApksByAbi.get(toAbi(X86)).getPath(), outputDir);
try (ZipFile x86Zip = new ZipFile(x86ApkFile)) {
// ABI-specific files.
assertThat(x86Zip).hasFile("lib/x86/libfeature.so");
assertThat(x86Zip).doesNotHaveFile("lib/x86_64/libfeature.so");
// Included in each standalone APK.
assertThat(x86Zip).hasFile("assets/strings#lang_en/trans.txt");
assertThat(x86Zip).hasFile("assets/strings#lang_fr/trans.txt");
assertThat(x86Zip).hasFile("assets/textures#tcf_atc/texture.dat");
assertThat(x86Zip).hasFile("assets/textures#tcf_etc1/texture.dat");
}
File x64ApkFile = extractFromApkSetFile(apkSetFile, standaloneApksByAbi.get(toAbi(X86_64)).getPath(), outputDir);
try (ZipFile x64Zip = new ZipFile(x64ApkFile)) {
// ABI-specific files.
assertThat(x64Zip).hasFile("lib/x86_64/libfeature.so");
assertThat(x64Zip).doesNotHaveFile("lib/x86/libfeature.so");
// Included in each standalone APK.
assertThat(x64Zip).hasFile("assets/strings#lang_en/trans.txt");
assertThat(x64Zip).hasFile("assets/strings#lang_fr/trans.txt");
assertThat(x64Zip).hasFile("assets/textures#tcf_atc/texture.dat");
assertThat(x64Zip).hasFile("assets/textures#tcf_etc1/texture.dat");
}
}
use of com.android.bundle.Targeting.Abi in project bundletool by google.
the class AbiNativeLibrariesSplitter method split.
/**
* Generates {@link ModuleSplit} objects dividing the native libraries by ABI.
*/
@Override
public ImmutableCollection<ModuleSplit> split(ModuleSplit moduleSplit) {
if (!moduleSplit.getNativeConfig().isPresent()) {
return ImmutableList.of(moduleSplit);
}
ImmutableList.Builder<ModuleSplit> splits = new ImmutableList.Builder<>();
// Flatten all targeted directories.
List<TargetedNativeDirectory> allTargetedDirectories = moduleSplit.getNativeConfig().get().getDirectoryList();
// Currently we only support targeting via ABI, so grouping it by Targeting.equals() should be
// enough.
ImmutableMultimap<NativeDirectoryTargeting, TargetedNativeDirectory> targetingMap = Multimaps.index(allTargetedDirectories, TargetedNativeDirectory::getTargeting);
// We need to know the exact set of ABIs that we will generate, to set alternatives correctly.
ImmutableSet<Abi> abisToGenerate = targetingMap.keySet().stream().map(NativeDirectoryTargeting::getAbi).collect(toImmutableSet());
// Any entries not claimed by the ABI splits will be returned in a separate split using the
// original targeting.
HashSet<ModuleEntry> leftOverEntries = new HashSet<>(moduleSplit.getEntries());
for (NativeDirectoryTargeting targeting : targetingMap.keySet()) {
ImmutableList<ModuleEntry> entriesList = targetingMap.get(targeting).stream().flatMap(directory -> moduleSplit.findEntriesUnderPath(directory.getPath())).collect(toImmutableList());
ModuleSplit.Builder splitBuilder = moduleSplit.toBuilder().setApkTargeting(moduleSplit.getApkTargeting().toBuilder().setAbiTargeting(AbiTargeting.newBuilder().addValue(targeting.getAbi()).addAllAlternatives(Sets.difference(abisToGenerate, ImmutableSet.of(targeting.getAbi())))).build()).setMasterSplit(false).addMasterManifestMutator(withSplitsRequired(true)).setEntries(entriesList);
splits.add(splitBuilder.build());
leftOverEntries.removeAll(entriesList);
}
if (!leftOverEntries.isEmpty()) {
splits.add(moduleSplit.toBuilder().setEntries(ImmutableList.copyOf(leftOverEntries)).build());
}
return splits.build();
}
use of com.android.bundle.Targeting.Abi in project bundletool by google.
the class BuildApksManagerTest method extractApkSet_outputApksWithoutArchive.
@Test
public void extractApkSet_outputApksWithoutArchive() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("assets/file.txt").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("test_label"))).addModule("abi_feature", builder -> builder.addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("language_feature", builder -> builder.addFile("res/drawable/image.jpg").addFile("res/drawable-cz/image.jpg").addFile("res/drawable-fr/image.jpg").addFile("res/drawable-pl/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app", USER_PACKAGE_OFFSET - 1).addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.of(Configuration.getDefaultInstance(), "res/drawable/image.jpg", locale("cz"), "res/drawable-cz/image.jpg", locale("fr"), "res/drawable-fr/image.jpg", locale("pl"), "res/drawable-pl/image.jpg")).build()).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputDir).withOptimizationDimensions(ABI, LANGUAGE).withCustomBuildApksCommandSetter(command -> command.setOutputFormat(DIRECTORY)).build());
buildApksManager.execute();
assertThat(command.getOutputFile()).isEqualTo(outputDir);
BuildApksResult result = parseTocFromFile(outputDir.resolve("toc.pb").toFile());
// Validate all APKs were created.
verifyApksExist(apkDescriptions(result.getVariantList()), outputDir);
}
use of com.android.bundle.Targeting.Abi in project bundletool by google.
the class TargetingGenerator method generateTargetingForNativeLibraries.
/**
* Processes given native library directories, generating targeting based on their names.
*
* @param libDirectories Names of directories under lib/, including the "lib/" prefix.
* @return Targeting for the given native libraries directories.
*/
public NativeLibraries generateTargetingForNativeLibraries(Collection<String> libDirectories) {
NativeLibraries.Builder nativeLibraries = NativeLibraries.newBuilder();
for (String directory : libDirectories) {
checkRootDirectoryName(LIB_DIR, directory);
// Split the directory under lib/ into tokens.
String subDirName = directory.substring(LIB_DIR.length());
Abi abi = checkAbiName(subDirName, directory);
NativeDirectoryTargeting.Builder nativeBuilder = NativeDirectoryTargeting.newBuilder().setAbi(abi);
if (subDirName.equals("arm64-v8a-hwasan")) {
nativeBuilder.setSanitizer(Sanitizer.newBuilder().setAlias(SanitizerAlias.HWADDRESS));
}
nativeLibraries.addDirectory(TargetedNativeDirectory.newBuilder().setPath(directory).setTargeting(nativeBuilder).build());
}
return nativeLibraries.build();
}
Aggregations