use of com.android.bundle.Targeting.AbiTargeting in project bundletool by google.
the class ModuleSplit method getSuffix.
/**
* Returns the split suffix base name based on the targeting.
*
* <p>The split suffix cannot contain dashes as they are not allowed by the Android Framework. We
* replace them with underscores instead.
*/
public String getSuffix() {
if (isMasterSplit()) {
return "";
}
StringJoiner suffixJoiner = new StringJoiner("_");
// The dimensions below should be ordered by their priority.
AbiTargeting abiTargeting = getApkTargeting().getAbiTargeting();
if (!abiTargeting.getValueList().isEmpty()) {
abiTargeting.getValueList().forEach(value -> suffixJoiner.add(formatAbi(value)));
} else if (!abiTargeting.getAlternativesList().isEmpty()) {
suffixJoiner.add("other_abis");
}
MultiAbiTargeting multiAbiTargeting = getApkTargeting().getMultiAbiTargeting();
for (MultiAbi value : multiAbiTargeting.getValueList()) {
suffixJoiner.add(MULTI_ABI_SUFFIX_JOINER.join(value.getAbiList().stream().map(ModuleSplit::formatAbi).collect(toImmutableList())));
}
// Alternatives without values are not supported for MultiAbiTargeting.
SanitizerTargeting sanitizerTargeting = getApkTargeting().getSanitizerTargeting();
for (Sanitizer sanitizer : sanitizerTargeting.getValueList()) {
if (sanitizer.getAlias().equals(SanitizerAlias.HWADDRESS)) {
suffixJoiner.add("hwasan");
} else {
throw new IllegalArgumentException("Unknown sanitizer");
}
}
LanguageTargeting languageTargeting = getApkTargeting().getLanguageTargeting();
if (!languageTargeting.getValueList().isEmpty()) {
languageTargeting.getValueList().forEach(suffixJoiner::add);
} else if (!languageTargeting.getAlternativesList().isEmpty()) {
suffixJoiner.add("other_lang");
}
getApkTargeting().getScreenDensityTargeting().getValueList().forEach(value -> suffixJoiner.add(SCREEN_DENSITY_TO_PROTO_VALUE_MAP.inverse().get(value.getDensityAlias()).replace('-', '_')));
TextureCompressionFormatTargeting textureFormatTargeting = getApkTargeting().getTextureCompressionFormatTargeting();
if (!textureFormatTargeting.getValueList().isEmpty()) {
textureFormatTargeting.getValueList().forEach(value -> suffixJoiner.add(Ascii.toLowerCase(value.getAlias().name())));
} else if (!textureFormatTargeting.getAlternativesList().isEmpty()) {
suffixJoiner.add("other_tcf");
}
getApkTargeting().getDeviceTierTargeting().getValueList().forEach(value -> suffixJoiner.add("tier_" + value.getValue()));
return suffixJoiner.toString();
}
use of com.android.bundle.Targeting.AbiTargeting in project bundletool by google.
the class ShardedApksFacadeTest method singleModule_withNativeLibsAndDensity_strip64bitNativeLibs.
@Test
@Theory
public void singleModule_withNativeLibsAndDensity_strip64bitNativeLibs(@FromDataPoints("standaloneSplitTypes") SplitType standaloneSplitType) throws Exception {
Optimizations optimizations = Optimizations.newBuilder().setStandaloneConfig(StandaloneConfig.newBuilder().setStrip64BitLibraries(true)).build();
TestComponent.useTestModule(this, standaloneSplitType.equals(SplitType.SYSTEM) ? TestModule.builder().withDeviceSpec(DEVICE_SPEC).withBundleConfig(BundleConfig.newBuilder().setOptimizations(optimizations)).build() : TestModule.builder().withBundleConfig(BundleConfig.newBuilder().setOptimizations(optimizations)).build());
ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(LDPI_VALUE, "res/drawable-ldpi/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app")).build());
ImmutableList<ModuleSplit> moduleSplits;
if (standaloneSplitType.equals(SplitType.SYSTEM)) {
moduleSplits = shardedApksFacade.generateSystemSplits(bundleModule, ImmutableSet.of(BASE_MODULE_NAME), DEFAULT_APK_OPTIMIZATIONS);
// x86, mdpi split
assertThat(moduleSplits).hasSize(1);
} else {
moduleSplits = shardedApksFacade.generateSplits(bundleModule, DEFAULT_APK_OPTIMIZATIONS);
// 7 (density), 1 (abi) split
assertThat(moduleSplits).hasSize(7);
}
// Verify that the only ABI is x86.
ImmutableSet<Abi> abiTargetings = moduleSplits.stream().map(ModuleSplit::getApkTargeting).map(ApkTargeting::getAbiTargeting).map(AbiTargeting::getValueList).flatMap(List::stream).collect(toImmutableSet());
assertThat(abiTargetings).containsExactly(toAbi(X86));
// And ABI has no alternatives.
ImmutableSet<Abi> abiAlternatives = moduleSplits.stream().map(ModuleSplit::getApkTargeting).map(ApkTargeting::getAbiTargeting).map(AbiTargeting::getAlternativesList).flatMap(List::stream).collect(toImmutableSet());
assertThat(abiAlternatives).isEmpty();
assertThat(moduleSplits.stream().map(ModuleSplit::getSplitType).collect(toImmutableSet())).containsExactly(standaloneSplitType);
}
use of com.android.bundle.Targeting.AbiTargeting in project bundletool by google.
the class AbstractSizeAggregator method getSizesPerConfiguration.
protected ConfigurationSizes getSizesPerConfiguration(ImmutableSet<SdkVersionTargeting> sdkTargetingOptions, ImmutableSet<AbiTargeting> abiTargetingOptions, ImmutableSet<LanguageTargeting> languageTargetingOptions, ImmutableSet<ScreenDensityTargeting> screenDensityTargetingOptions, ImmutableSet<TextureCompressionFormatTargeting> textureCompressionFormatTargetingOptions, ImmutableSet<DeviceTierTargeting> deviceTierTargetingOptions) {
Map<SizeConfiguration, Long> minSizeByConfiguration = new HashMap<>();
Map<SizeConfiguration, Long> maxSizeByConfiguration = new HashMap<>();
for (SdkVersionTargeting sdkVersionTargeting : sdkTargetingOptions) {
for (AbiTargeting abiTargeting : abiTargetingOptions) {
for (ScreenDensityTargeting screenDensityTargeting : screenDensityTargetingOptions) {
for (LanguageTargeting languageTargeting : languageTargetingOptions) {
for (TextureCompressionFormatTargeting textureCompressionFormatTargeting : textureCompressionFormatTargetingOptions) {
for (DeviceTierTargeting deviceTierTargeting : deviceTierTargetingOptions) {
SizeConfiguration configuration = mergeWithDeviceSpec(getSizeConfiguration(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting), getSizeRequest.getDeviceSpec());
long compressedSize = getCompressedSize(getMatchingApks(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting));
minSizeByConfiguration.merge(configuration, compressedSize, Math::min);
maxSizeByConfiguration.merge(configuration, compressedSize, Math::max);
}
}
}
}
}
}
return ConfigurationSizes.create(/* minSizeConfigurationMap= */
ImmutableMap.copyOf(minSizeByConfiguration), /* maxSizeConfigurationMap= */
ImmutableMap.copyOf(maxSizeByConfiguration));
}
use of com.android.bundle.Targeting.AbiTargeting in project bundletool by google.
the class ProtoFuzzerTest method randomProtoMessage_repeatedMessageFieldPopulated.
@Test
public void randomProtoMessage_repeatedMessageFieldPopulated() {
AbiTargeting randomProto = ProtoFuzzer.randomProtoMessage(AbiTargeting.class);
// At least some values populated.
assertThat(randomProto).isNotEqualTo(AbiTargeting.getDefaultInstance());
// Not all random values are the same.
assertThat(ImmutableSet.copyOf(randomProto.getValueList()).size()).isGreaterThan(1);
assertThat(ImmutableSet.copyOf(randomProto.getAlternativesList()).size()).isGreaterThan(1);
}
use of com.android.bundle.Targeting.AbiTargeting in project bundletool by google.
the class BuildApksPreprocessingTest method renderscript32Bit_64BitStandaloneAndSplitApksFilteredOut.
@Test
public void renderscript32Bit_64BitStandaloneAndSplitApksFilteredOut() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("dex/classes.dex").addFile("assets/script.bc").addFile("lib/armeabi-v7a/libfoo.so").addFile("lib/arm64-v8a/libfoo.so").setManifest(androidManifest("com.test.app", withMinSdkVersion(14))).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi-v7a", nativeDirectoryTargeting(ARMEABI_V7A)), targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A))))).setBundleConfig(BundleConfigBuilder.create().setUncompressNativeLibraries(false).build()).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
command.execute();
BuildApksResult result;
try (ZipFile apkSetFile = new ZipFile(outputFilePath.toFile())) {
result = extractTocFromApkSetFile(apkSetFile, outputDir);
}
assertThat(standaloneApkVariants(result)).hasSize(1);
assertThat(standaloneApkVariants(result).get(0).getTargeting().getAbiTargeting()).isEqualTo(abiTargeting(ARMEABI_V7A));
assertThat(splitApkVariants(result)).hasSize(1);
ImmutableSet<AbiTargeting> abiTargetings = splitApkVariants(result).get(0).getApkSetList().stream().map(ApkSet::getApkDescriptionList).flatMap(list -> list.stream().map(ApkDescription::getTargeting)).map(ApkTargeting::getAbiTargeting).collect(toImmutableSet());
assertThat(abiTargetings).containsExactly(AbiTargeting.getDefaultInstance(), abiTargeting(ARMEABI_V7A));
}
Aggregations