use of com.android.tools.build.bundletool.model.version.Version in project bundletool by google.
the class BuildApksManager method getCommonSplitApkGenerationConfiguration.
private ApkGenerationConfiguration.Builder getCommonSplitApkGenerationConfiguration(AppBundle appBundle) {
BundleConfig bundleConfig = appBundle.getBundleConfig();
Version bundleToolVersion = Version.of(bundleConfig.getBundletool().getVersion());
ApkGenerationConfiguration.Builder apkGenerationConfiguration = ApkGenerationConfiguration.builder().setOptimizationDimensions(apkOptimizations.getSplitDimensions());
apkGenerationConfiguration.setEnableUncompressedNativeLibraries(apkOptimizations.getUncompressNativeLibraries());
apkGenerationConfiguration.setEnableDexCompressionSplitter(apkOptimizations.getUncompressDexFiles());
apkGenerationConfiguration.setInstallableOnExternalStorage(appBundle.getBaseModule().getAndroidManifest().getInstallLocationValue().map(installLocation -> installLocation.equals("auto") || installLocation.equals("preferExternal")).orElse(false));
apkGenerationConfiguration.setMasterPinnedResourceIds(appBundle.getMasterPinnedResourceIds());
apkGenerationConfiguration.setMasterPinnedResourceNames(appBundle.getMasterPinnedResourceNames());
apkGenerationConfiguration.setSuffixStrippings(apkOptimizations.getSuffixStrippings());
command.getMinSdkForAdditionalVariantWithV3Rotation().ifPresent(apkGenerationConfiguration::setMinSdkForAdditionalVariantWithV3Rotation);
return apkGenerationConfiguration;
}
use of com.android.tools.build.bundletool.model.version.Version in project bundletool by google.
the class ModuleTitleValidator method checkModuleTitles.
private static void checkModuleTitles(ImmutableList<BundleModule> modules) {
if (BundleValidationUtils.isAssetOnlyBundle(modules)) {
return;
}
BundleModule baseModule = BundleValidationUtils.expectBaseModule(modules);
boolean isolatedSplits = baseModule.getAndroidManifest().getIsolatedSplits().orElse(false);
// For bundles built using older versions we haven't strictly enforced module Title Validation.
Version bundleVersion = BundleToolVersion.getVersionFromBundleConfig(baseModule.getBundleConfig());
if (!MODULE_TITLE_VALIDATION_ENFORCED.enabledForVersion(bundleVersion)) {
return;
}
ResourceTable table = baseModule.getResourceTable().orElse(ResourceTable.getDefaultInstance());
ImmutableSet<Integer> stringResourceIds = entries(table).filter(entry -> entry.getType().getName().equals("string")).map(entry -> entry.getResourceId().getFullResourceId()).collect(toImmutableSet());
for (BundleModule module : modules) {
if (module.getModuleType().equals(ModuleType.ASSET_MODULE)) {
if (module.getAndroidManifest().getTitleRefId().isPresent()) {
throw InvalidBundleException.builder().withUserMessage("Module titles not supported in asset packs, but found in '%s'.", module.getName()).build();
}
} else if (!module.getDeliveryType().equals(ModuleDeliveryType.ALWAYS_INITIAL_INSTALL)) {
Optional<Integer> titleRefId = module.getAndroidManifest().getTitleRefId();
if (isolatedSplits) {
// references into the base split resource table.
return;
}
if (!titleRefId.isPresent()) {
throw InvalidBundleException.builder().withUserMessage("Mandatory title is missing in manifest for module '%s'.", module.getName()).build();
}
if (!stringResourceIds.contains(titleRefId.get())) {
throw InvalidBundleException.builder().withUserMessage("Title for module '%s' is missing in the base resource table.", module.getName()).build();
}
}
}
}
use of com.android.tools.build.bundletool.model.version.Version in project bundletool by google.
the class OptimizationsMerger method mergeWithDefaults.
/**
* Merges the optimizations instructions supplied by the developer (in the BundleConfig), the
* defaults set by BundleTool and the values provided in the command.
*
* <p>If {@code optimizationsOverride} is not empty, we only apply these optimizations. Otherwise,
* we use the default optimizations merged with the overrides specified in the BundleConfig.
*/
// Optimization flags will go away soon!
@Deprecated
public ApkOptimizations mergeWithDefaults(BundleConfig bundleConfig, ImmutableSet<OptimizationDimension> optimizationsOverride) {
// Default optimizations performed on APKs if the developer doesn't specify any preferences.
String buildVersionString = bundleConfig.getBundletool().getVersion();
Version bundleToolBuildVersion = buildVersionString.isEmpty() ? BundleToolVersion.getCurrentVersion() : Version.of(buildVersionString);
ApkOptimizations defaultOptimizations = ApkOptimizations.getDefaultOptimizationsForVersion(bundleToolBuildVersion);
// Preferences specified by the developer.
Optimizations requestedOptimizations = bundleConfig.getOptimizations();
// Until we get rid of OptimizationsOverride flag, it takes precedence over anything else.
ImmutableSet<OptimizationDimension> splitDimensions = getEffectiveSplitDimensions(defaultOptimizations, requestedOptimizations, optimizationsOverride);
ImmutableSet<OptimizationDimension> standaloneDimensions = getEffectiveStandaloneDimensions(defaultOptimizations, requestedOptimizations, optimizationsOverride);
// If developer sets UncompressNativeLibraries use that, otherwise use the default value.
boolean uncompressNativeLibraries = requestedOptimizations.hasUncompressNativeLibraries() ? requestedOptimizations.getUncompressNativeLibraries().getEnabled() : defaultOptimizations.getUncompressNativeLibraries();
boolean uncompressDexFiles = requestedOptimizations.hasUncompressDexFiles() ? requestedOptimizations.getUncompressDexFiles().getEnabled() : defaultOptimizations.getUncompressDexFiles();
ImmutableMap<OptimizationDimension, SuffixStripping> suffixStrippings = getSuffixStrippings(bundleConfig.getOptimizations().getSplitsConfig().getSplitDimensionList());
return ApkOptimizations.builder().setSplitDimensions(splitDimensions).setUncompressNativeLibraries(uncompressNativeLibraries).setUncompressDexFiles(uncompressDexFiles).setStandaloneDimensions(standaloneDimensions).setSuffixStrippings(suffixStrippings).build();
}
use of com.android.tools.build.bundletool.model.version.Version in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_assetOnly.
@Test
@Theory
public void buildApksCommand_assetOnly(@FromDataPoints("bundleVersion") Version bundleVersion) throws Exception {
AssetModulesConfig assetModulesConfig = AssetModulesConfig.newBuilder().setAssetVersionTag("qwe").addAppVersion(11).build();
AssetModulesInfo assetModulesInfo = AssetModulesInfo.newBuilder().setAssetVersionTag("qwe").addAppVersion(11).build();
AppBundle appBundle = new AppBundleBuilder().addModule("asset_module1", builder -> builder.setManifest(androidManifestForAssetModule("com.test.app", withOnDemandDelivery())).addFile("assets/images/image.jpg")).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withBundleConfig(BundleConfig.newBuilder().setAssetModulesConfig(assetModulesConfig).setType(BundleType.ASSET_ONLY)).withBundletoolVersion(bundleVersion.toString()).withOutputPath(outputFilePath).withCustomBuildApksCommandSetter(command -> command.setAssetModulesVersionOverride(123L)).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Variants
assertThat(splitApkVariants(result)).isEmpty();
// Asset Slices
List<AssetSliceSet> sliceSets = result.getAssetSliceSetList();
assertThat(sliceSets).hasSize(1);
AssetSliceSet assetSliceSet = sliceSets.get(0);
assertThat(assetSliceSet.getAssetModuleMetadata().hasInstantMetadata()).isTrue();
assertThat(assetSliceSet.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(assetSliceSet.getApkDescription(0).getPath());
ApkDescription apkDescription = assetSliceSet.getApkDescription(0);
assertThat(apkDescription.getPath()).isEqualTo(String.format("asset-slices/%s-master.apk", assetSliceSet.getAssetModuleMetadata().getName()));
assertThat(apkDescription.hasAssetSliceMetadata()).isTrue();
assertThat(apkDescription.getAssetSliceMetadata().getIsMasterSplit()).isTrue();
assertThat(result.getAssetModulesInfo()).isEqualTo(assetModulesInfo);
}
use of com.android.tools.build.bundletool.model.version.Version in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_featureAndAssetModules_generatesAssetSlices.
@Test
@Theory
public void buildApksCommand_featureAndAssetModules_generatesAssetSlices(@FromDataPoints("bundleVersion") Version bundleVersion) throws Exception {
AppBundle appBundle = createAppBundleBuilder(bundleVersion).addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app", withMinSdkVersion(15), withMaxSdkVersion(27), withInstant(true))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("asset_module1", builder -> builder.setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery())).addFile("assets/images/image.jpg")).addModule("asset_module2", builder -> builder.setManifest(androidManifestForAssetModule("com.test.app", withOnDemandDelivery(), withInstantOnDemandDelivery())).addFile("assets/images/image2.jpg")).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Variants
ImmutableList<Variant> variants = splitApkVariants(result);
assertThat(variants).hasSize(1);
Variant splitApkVariant = variants.get(0);
List<ApkSet> apks = splitApkVariant.getApkSetList();
assertThat(apks).hasSize(1);
ApkSet baseSplits = apks.get(0);
assertThat(baseSplits.getModuleMetadata().getName()).isEqualTo("base");
assertThat(baseSplits.getModuleMetadata().getDeliveryType()).isEqualTo(DeliveryType.INSTALL_TIME);
assertThat(baseSplits.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(baseSplits.getApkDescription(0).getPath());
// Asset Slices
List<AssetSliceSet> sliceSets = result.getAssetSliceSetList();
assertThat(sliceSets).hasSize(2);
for (AssetSliceSet slice : sliceSets) {
assertThat(slice.getAssetModuleMetadata().hasInstantMetadata()).isTrue();
assertThat(slice.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(slice.getApkDescription(0).getPath());
ApkDescription apkDescription = slice.getApkDescription(0);
assertThat(apkDescription.getPath()).isEqualTo(String.format("asset-slices/%s-master.apk", slice.getAssetModuleMetadata().getName()));
assertThat(apkDescription.hasAssetSliceMetadata()).isTrue();
assertThat(apkDescription.getAssetSliceMetadata().getIsMasterSplit()).isTrue();
}
ImmutableMap<String, AssetSliceSet> sliceSetsByName = Maps.uniqueIndex(sliceSets, set -> set.getAssetModuleMetadata().getName());
assertThat(sliceSetsByName.get("asset_module1").getAssetModuleMetadata().getInstantMetadata().getIsInstant()).isFalse();
assertThat(sliceSetsByName.get("asset_module1").getApkDescription(0).getTargeting()).isEqualTo(ApkTargeting.newBuilder().setSdkVersionTargeting(SdkVersionTargeting.newBuilder().addValue(SdkVersion.newBuilder().setMin(Int32Value.newBuilder().setValue(ANDROID_L_API_VERSION)))).build());
assertThat(sliceSetsByName.get("asset_module2").getApkDescription(0).getTargeting()).isEqualToDefaultInstance();
InstantMetadata.Builder instantMetadata = InstantMetadata.newBuilder().setIsInstant(true);
instantMetadata.setDeliveryType(DeliveryType.ON_DEMAND);
assertThat(sliceSetsByName.get("asset_module2").getAssetModuleMetadata().getInstantMetadata()).isEqualTo(instantMetadata.build());
}
Aggregations