Search in sources :

Example 31 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class VariantTotalSizeAggregator method getSizeStandaloneVariant.

private ConfigurationSizes getSizeStandaloneVariant() {
    checkState(!getSizeRequest.getInstant(), "Standalone Variants can't be selected when instant flag is set");
    // When modules are specified we ignore standalone variants.
    if (getSizeRequest.getModules().isPresent()) {
        return ConfigurationSizes.create(ImmutableMap.of(), ImmutableMap.of());
    }
    VariantTargeting variantTargeting = variant.getTargeting();
    SizeConfiguration sizeConfiguration = mergeWithDeviceSpec(getSizeConfiguration(variantTargeting.getSdkVersionTargeting(), variantTargeting.getAbiTargeting(), variantTargeting.getScreenDensityTargeting(), LanguageTargeting.getDefaultInstance(), variantTargeting.getTextureCompressionFormatTargeting(), DeviceTierTargeting.getDefaultInstance()), getSizeRequest.getDeviceSpec());
    // Variants of standalone APKs have only one APK each.
    long compressedSize = sizeByApkPaths.get(Iterables.getOnlyElement(Iterables.getOnlyElement(variant.getApkSetList()).getApkDescriptionList()).getPath());
    ImmutableMap<SizeConfiguration, Long> sizeConfigurationMap = ImmutableMap.of(sizeConfiguration, compressedSize);
    return ConfigurationSizes.create(sizeConfigurationMap, sizeConfigurationMap);
}
Also used : VariantTargeting(com.android.bundle.Targeting.VariantTargeting) SizeConfiguration(com.android.tools.build.bundletool.model.SizeConfiguration)

Example 32 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class DexCompressionVariantGeneratorTest method variantsGeneration_withoutDexFile_generatesNoVariant.

@Test
public void variantsGeneration_withoutDexFile_generatesNoVariant() throws Exception {
    DexCompressionVariantGenerator dexCompressionVariantGenerator = new DexCompressionVariantGenerator(ApkGenerationConfiguration.builder().setEnableDexCompressionSplitter(true).build());
    BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("assets/leftover.txt").setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<VariantTargeting> splits = dexCompressionVariantGenerator.generate(bundleModule).collect(toImmutableList());
    assertThat(splits).isEmpty();
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 33 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class SplitApksGeneratorTest method multipleModules_withOnlyBaseModuleWithNativeLibrariesOtherModuleWithDexFiles.

@Test
public void multipleModules_withOnlyBaseModuleWithNativeLibrariesOtherModuleWithDexFiles() throws Exception {
    ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("assets/leftover.txt").addFile("lib/x86_64/libsome.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).build(), new BundleModuleBuilder("test").addFile("assets/test.txt").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).build());
    ImmutableList<ModuleSplit> moduleSplits = splitApksGenerator.generateSplits(bundleModule, ApkGenerationConfiguration.builder().setEnableUncompressedNativeLibraries(true).setEnableDexCompressionSplitter(true).build());
    VariantTargeting lVariantTargeting = variantMinSdkTargeting(/* minSdkVersion= */
    ANDROID_L_API_VERSION, /* alternativeSdkVersions...= */
    ANDROID_M_API_VERSION, ANDROID_Q_API_VERSION);
    VariantTargeting mVariantTargeting = variantMinSdkTargeting(/* minSdkVersion= */
    ANDROID_M_API_VERSION, /* alternativeSdkVersions...= */
    ANDROID_L_API_VERSION, ANDROID_Q_API_VERSION);
    VariantTargeting qVariantTargeting = variantMinSdkTargeting(/* minSdkVersion= */
    ANDROID_Q_API_VERSION, /* alternativeSdkVersions...= */
    ANDROID_L_API_VERSION, ANDROID_M_API_VERSION);
    // 2 splits for L, M, P variants.
    assertThat(moduleSplits).hasSize(6);
    assertThat(moduleSplits.stream().map(ModuleSplit::getVariantTargeting).collect(toImmutableSet())).containsExactly(lVariantTargeting, mVariantTargeting, qVariantTargeting);
    ModuleSplit baseLModule = getModuleSplit(moduleSplits, lVariantTargeting, "base");
    assertThat(baseLModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(baseLModule.getEntries())).containsExactly("assets/leftover.txt", "lib/x86_64/libsome.so");
    assertThat(getForceUncompressed(baseLModule, "lib/x86_64/libsome.so")).isFalse();
    ModuleSplit testLModule = getModuleSplit(moduleSplits, lVariantTargeting, "test");
    assertThat(testLModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(testLModule.getEntries())).containsExactly("assets/test.txt", "dex/classes.dex");
    assertThat(getForceUncompressed(testLModule, "dex/classes.dex")).isFalse();
    ModuleSplit baseMModule = getModuleSplit(moduleSplits, mVariantTargeting, "base");
    assertThat(baseMModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(baseMModule.getEntries())).containsExactly("assets/leftover.txt", "lib/x86_64/libsome.so");
    assertThat(getForceUncompressed(baseMModule, "lib/x86_64/libsome.so")).isTrue();
    ModuleSplit testMModule = getModuleSplit(moduleSplits, mVariantTargeting, "test");
    assertThat(testMModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(testMModule.getEntries())).containsExactly("assets/test.txt", "dex/classes.dex");
    assertThat(getForceUncompressed(testMModule, "dex/classes.dex")).isFalse();
    ModuleSplit basePModule = getModuleSplit(moduleSplits, qVariantTargeting, "base");
    assertThat(basePModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(basePModule.getEntries())).containsExactly("assets/leftover.txt", "lib/x86_64/libsome.so");
    assertThat(getForceUncompressed(basePModule, "lib/x86_64/libsome.so")).isTrue();
    ModuleSplit testPModule = getModuleSplit(moduleSplits, qVariantTargeting, "test");
    assertThat(testPModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(testPModule.getEntries())).containsExactly("assets/test.txt", "dex/classes.dex");
    assertThat(getForceUncompressed(testPModule, "dex/classes.dex")).isTrue();
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetingUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 34 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class VariantGeneratorTest method variantsWithV3SigningRestrictedToRPlus_minSdkAffectsRPlusVariant.

@Test
public void variantsWithV3SigningRestrictedToRPlus_minSdkAffectsRPlusVariant() throws Exception {
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app", withMinSdkVersion(ANDROID_R_API_VERSION + 1))).build();
    VariantGenerator variantGenerator = new VariantGenerator();
    ImmutableCollection<VariantTargeting> splits = variantGenerator.generateVariants(bundleModule, ApkGenerationConfiguration.builder().setMinSdkForAdditionalVariantWithV3Rotation(ANDROID_R_API_VERSION).build());
    assertThat(splits).containsExactly(variantMinSdkTargeting(ANDROID_R_API_VERSION + 1));
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) TargetingUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 35 with VariantTargeting

use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.

the class VariantGeneratorTest method variantsWithV3SigningRestrictedToRPlus_maxSdkRemovesRPlusVariant.

@Test
public void variantsWithV3SigningRestrictedToRPlus_maxSdkRemovesRPlusVariant() throws Exception {
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app", withMaxSdkVersion(ANDROID_R_API_VERSION - 1))).build();
    VariantGenerator variantGenerator = new VariantGenerator();
    ImmutableCollection<VariantTargeting> splits = variantGenerator.generateVariants(bundleModule, ApkGenerationConfiguration.builder().setMinSdkForAdditionalVariantWithV3Rotation(ANDROID_R_API_VERSION).build());
    assertThat(splits).containsExactly(lPlusVariantTargeting());
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) TargetingUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

VariantTargeting (com.android.bundle.Targeting.VariantTargeting)37 Test (org.junit.Test)31 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)16 TargetingUtils.mergeVariantTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting)16 BundleModule (com.android.tools.build.bundletool.model.BundleModule)12 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)9 SdkVersion (com.android.bundle.Targeting.SdkVersion)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)5 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)5 GeneratedApks (com.android.tools.build.bundletool.model.GeneratedApks)5 TargetingUtils.lPlusVariantTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting)5 ImmutableList (com.google.common.collect.ImmutableList)5 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)4 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)3 BundleConfig (com.android.bundle.Config.BundleConfig)3 ApexImages (com.android.bundle.Files.ApexImages)3 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 ApexManifest (com.android.apex.ApexManifestProto.ApexManifest)2