Search in sources :

Example 1 with ApkOptimizations

use of com.android.tools.build.bundletool.optimizations.ApkOptimizations in project bundletool by google.

the class SystemApksGeneratorTest method uncompressedDexFiles_enabled.

@Test
public void uncompressedDexFiles_enabled() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("dex/classes.dex").setManifest(androidManifestForFeature("com.test.app")).build();
    ApkOptimizations apkOptimizations = splitOptimizations().toBuilder().setUncompressDexFiles(true).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
    assertThat(shards).hasSize(1);
    ModuleSplit fatApk = shards.get(0);
    assertThat(fatApk.findEntry("dex/classes.dex").map(ModuleEntry::getForceUncompressed)).hasValue(true);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 2 with ApkOptimizations

use of com.android.tools.build.bundletool.optimizations.ApkOptimizations in project bundletool by google.

the class SystemApksGeneratorTest method uncompressedNativeLibraries_enabled_singleApk.

@Test
public void uncompressedNativeLibraries_enabled_singleApk() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("assets/images/img.png").addFile("res/layout/default.xml").addFile("lib/x86_64/libtest1.so").addFile("lib/x86/libtest1.so").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addFileResource("layout", "default", "res/layout/default.xml").build()).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app")).build();
    BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/x86_64/libtest2.so").addFile("lib/x86/libtest2.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app.feature")).build();
    ApkOptimizations apkOptimizations = splitOptimizations(OptimizationDimension.ABI).toBuilder().setUncompressNativeLibraries(true).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule, featureModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME, FEATURE_MODULE_NAME), apkOptimizations);
    assertThat(shards).hasSize(1);
    ModuleSplit fatApk = shards.get(0);
    assertThat(fatApk.getAndroidManifest().getExtractNativeLibsValue()).hasValue(false);
    assertThat(fatApk.findEntry("lib/x86/libtest1.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
    assertThat(fatApk.findEntry("lib/x86/libtest2.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
    assertThat(fatApk.findEntry("res/layout/default.xml").map(ModuleEntry::getForceUncompressed)).hasValue(false);
    assertThat(fatApk.findEntry("assets/images/img.png").map(ModuleEntry::getForceUncompressed)).hasValue(false);
    assertThat(fatApk.findEntry("lib/x86_64/libtest1.so")).isEmpty();
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 3 with ApkOptimizations

use of com.android.tools.build.bundletool.optimizations.ApkOptimizations in project bundletool by google.

the class SystemApksGeneratorTest method uncompressedNativeLibraries_enabled_multiApks.

@Test
public void uncompressedNativeLibraries_enabled_multiApks() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("lib/x86_64/libtest1.so").addFile("lib/x86/libtest1.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app")).build();
    BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/x86_64/libtest2.so").addFile("lib/x86/libtest2.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app.feature")).build();
    ApkOptimizations apkOptimizations = splitOptimizations(OptimizationDimension.ABI).toBuilder().setUncompressNativeLibraries(true).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule, featureModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
    assertThat(shards).hasSize(3);
    ModuleSplit systemApk = getSystemImageSplit(shards);
    assertThat(systemApk.getAndroidManifest().getExtractNativeLibsValue()).hasValue(false);
    assertThat(systemApk.findEntry("lib/x86/libtest1.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
    ModuleSplit additionalNativeSplit = getAdditionalSplits(shards).stream().filter(split -> split.getApkTargeting().hasAbiTargeting()).collect(onlyElement());
    assertThat(additionalNativeSplit.findEntry("lib/x86/libtest2.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
}
Also used : TEST_LABEL_RESOURCE_ID(com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) TargetingUtils.alternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) DeviceSpec(com.android.bundle.Devices.DeviceSpec) TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) DeviceFactory.abis(com.android.tools.build.bundletool.testing.DeviceFactory.abis) TargetingUtils.abiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.abiTargeting) LDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.LDPI_VALUE) Predicates.not(com.google.common.base.Predicates.not) ARMEABI(com.android.bundle.Targeting.Abi.AbiAlias.ARMEABI) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) TargetingUtils.targetedAssetsDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedAssetsDirectory) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) TargetingUtils.toScreenDensity(com.android.tools.build.bundletool.testing.TargetingUtils.toScreenDensity) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) ResourcesTableFactory.resourceTableWithTestLabel(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTableWithTestLabel) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) ManifestProtoUtils.withTitle(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withTitle) ImmutableSet(com.google.common.collect.ImmutableSet) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) DeviceFactory.sdkVersion(com.android.tools.build.bundletool.testing.DeviceFactory.sdkVersion) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) DeviceFactory.density(com.android.tools.build.bundletool.testing.DeviceFactory.density) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) TargetingUtils.variantAbiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantAbiTargeting) ManifestProtoUtils.androidManifestForFeature(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForFeature) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) DeviceFactory.locales(com.android.tools.build.bundletool.testing.DeviceFactory.locales) TestModule(com.android.tools.build.bundletool.testing.TestModule) Iterables(com.google.common.collect.Iterables) DEFAULT_DENSITY_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.DEFAULT_DENSITY_VALUE) TargetingUtils.apkAbiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkAbiTargeting) TargetingUtils.variantMinSdkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantMinSdkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) OptimizationDimension(com.android.tools.build.bundletool.model.OptimizationDimension) RunWith(org.junit.runner.RunWith) MDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.MDPI_VALUE) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) Component(dagger.Component) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) DeviceFactory.mergeSpecs(com.android.tools.build.bundletool.testing.DeviceFactory.mergeSpecs) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) Inject(javax.inject.Inject) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) CommandScoped(com.android.tools.build.bundletool.commands.CommandScoped) ByteSource(com.google.common.io.ByteSource) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Before(org.junit.Before) X86(com.android.bundle.Targeting.Abi.AbiAlias.X86) LDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.LDPI) HDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.HDPI_VALUE) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) ManifestProtoUtils.withFusingAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withFusingAttribute) HDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI) TargetingUtils.targetedNativeDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedNativeDirectory) Test(org.junit.Test) X86_64(com.android.bundle.Targeting.Abi.AbiAlias.X86_64) BundleMetadata(com.android.tools.build.bundletool.model.BundleMetadata) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BuildApksModule(com.android.tools.build.bundletool.commands.BuildApksModule) Maps(com.google.common.collect.Maps) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) TargetingUtils.assets(com.android.tools.build.bundletool.testing.TargetingUtils.assets) TargetingUtils.nativeLibraries(com.android.tools.build.bundletool.testing.TargetingUtils.nativeLibraries) TargetingUtils.apkAlternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkAlternativeLanguageTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 4 with ApkOptimizations

use of com.android.tools.build.bundletool.optimizations.ApkOptimizations in project bundletool by google.

the class SystemApksGeneratorTest method uncompressedNativeLibraries_disabled.

@Test
public void uncompressedNativeLibraries_disabled() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("lib/x86_64/libtest1.so").addFile("lib/x86/libtest1.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app")).build();
    ApkOptimizations apkOptimizations = splitOptimizations(OptimizationDimension.ABI).toBuilder().setUncompressNativeLibraries(false).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
    assertThat(shards).hasSize(1);
    ModuleSplit fatApk = shards.get(0);
    assertThat(fatApk.getAndroidManifest().getExtractNativeLibsValue()).isEmpty();
    assertThat(fatApk.findEntry("lib/x86/libtest1.so").map(ModuleEntry::getForceUncompressed)).hasValue(false);
    assertThat(fatApk.findEntry("lib/x86_64/libtest1.so")).isEmpty();
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 5 with ApkOptimizations

use of com.android.tools.build.bundletool.optimizations.ApkOptimizations in project bundletool by google.

the class SystemApksGeneratorTest method uncompressedDexFiles_disabled.

@Test
public void uncompressedDexFiles_disabled() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("dex/classes.dex").setManifest(androidManifestForFeature("com.test.app")).build();
    ApkOptimizations apkOptimizations = splitOptimizations().toBuilder().setUncompressDexFiles(false).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
    assertThat(shards).hasSize(1);
    ModuleSplit fatApk = shards.get(0);
    assertThat(fatApk.findEntry("dex/classes.dex").map(ModuleEntry::getForceUncompressed)).hasValue(false);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

BundleModule (com.android.tools.build.bundletool.model.BundleModule)5 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)5 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)5 ApkOptimizations (com.android.tools.build.bundletool.optimizations.ApkOptimizations)5 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)5 Test (org.junit.Test)5 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)2 DeviceSpec (com.android.bundle.Devices.DeviceSpec)1 ARMEABI (com.android.bundle.Targeting.Abi.AbiAlias.ARMEABI)1 X86 (com.android.bundle.Targeting.Abi.AbiAlias.X86)1 X86_64 (com.android.bundle.Targeting.Abi.AbiAlias.X86_64)1 LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)1 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)1 BuildApksModule (com.android.tools.build.bundletool.commands.BuildApksModule)1 CommandScoped (com.android.tools.build.bundletool.commands.CommandScoped)1 BundleMetadata (com.android.tools.build.bundletool.model.BundleMetadata)1 BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)1 BASE_MODULE_NAME (com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME)1 SplitType (com.android.tools.build.bundletool.model.ModuleSplit.SplitType)1 OptimizationDimension (com.android.tools.build.bundletool.model.OptimizationDimension)1