Search in sources :

Example 1 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class ArchivedApksGenerator method generateArchivedApk.

public ModuleSplit generateArchivedApk(AppBundle appBundle) throws IOException {
    validateRequest(appBundle);
    BundleModule baseModule = appBundle.getBaseModule();
    AndroidManifest archivedManifest = ArchivedAndroidManifestUtils.createArchivedManifest(baseModule.getAndroidManifest());
    Optional<ResourceTable> archivedResourceTable = getArchivedResourceTable(appBundle, baseModule, archivedManifest);
    Path archivedClassesDexFile = getArchivedClassesDexFile();
    return ModuleSplit.forArchive(baseModule, archivedManifest, archivedResourceTable, archivedClassesDexFile);
}
Also used : Path(java.nio.file.Path) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) BundleModule(com.android.tools.build.bundletool.model.BundleModule) ResourceTable(com.android.aapt.Resources.ResourceTable)

Example 2 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class BuildApksManager method execute.

public void execute() throws IOException {
    ImmutableSet<BundleModuleName> permanentlyFusedModules = ImmutableSet.of();
    ImmutableSet<BundleModule> requestedModules = command.getModules().isEmpty() ? ImmutableSet.of() : ModuleDependenciesUtils.getModulesIncludingDependencies(appBundle, getBundleModules(appBundle, command.getModules()));
    GeneratedApks.Builder generatedApksBuilder = GeneratedApks.builder();
    GeneratedAssetSlices.Builder generatedAssetSlices = GeneratedAssetSlices.builder();
    boolean enableUniversalAsFallbackForSplits = false;
    boolean enableInstallTimeNonRemovableModules = false;
    ApksToGenerate apksToGenerate = new ApksToGenerate(appBundle, command.getApkBuildMode(), enableUniversalAsFallbackForSplits, deviceSpec);
    // Split APKs
    if (apksToGenerate.generateSplitApks()) {
        AppBundle mergedAppBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(appBundle, enableInstallTimeNonRemovableModules);
        AppBundleValidator bundleValidator = AppBundleValidator.create(command.getExtraValidators());
        bundleValidator.validate(mergedAppBundle);
        generatedApksBuilder.setSplitApks(generateSplitApks(mergedAppBundle));
        permanentlyFusedModules = Sets.difference(appBundle.getModules().keySet(), mergedAppBundle.getModules().keySet()).immutableCopy();
    }
    // Instant APKs
    if (apksToGenerate.generateInstantApks()) {
        generatedApksBuilder.setInstantApks(generateInstantApks(appBundle));
    }
    // Standalone APKs
    if (apksToGenerate.generateStandaloneApks()) {
        generatedApksBuilder.setStandaloneApks(generateStandaloneApks(appBundle));
    }
    // Universal APK
    if (apksToGenerate.generateUniversalApk()) {
        // Note: Universal APK is a special type of standalone, with no optimization dimensions.
        ImmutableList<BundleModule> modulesToFuse = requestedModules.isEmpty() ? modulesToFuse(getModulesForStandaloneApks(appBundle)) : requestedModules.asList();
        generatedApksBuilder.setStandaloneApks(shardedApksFacade.generateSplits(modulesToFuse, ApkOptimizations.getOptimizationsForUniversalApk()));
    }
    // System APKs
    if (apksToGenerate.generateSystemApks()) {
        generatedApksBuilder.setSystemApks(generateSystemApks(appBundle, requestedModules));
    }
    // Archived APKs
    if (apksToGenerate.generateArchivedApks()) {
        generatedApksBuilder.setArchivedApks(generateArchivedApks(appBundle));
    }
    // Asset Slices
    if (apksToGenerate.generateAssetSlices()) {
        generatedAssetSlices.setAssetSlices(generateAssetSlices(appBundle));
    }
    // Populate alternative targeting based on variant targeting of all APKs.
    GeneratedApks generatedApks = AlternativeVariantTargetingPopulator.populateAlternativeVariantTargeting(generatedApksBuilder.build(), appBundle.isAssetOnly() ? Optional.empty() : appBundle.getBaseModule().getAndroidManifest().getMaxSdkVersion());
    // A variant is a set of APKs. One device is guaranteed to receive only APKs from the same. This
    // is why we are processing new entries like split.xml for each variant separately.
    generatedApks = GeneratedApks.fromModuleSplits(generatedApks.getAllApksGroupedByOrderedVariants().asMap().entrySet().stream().map(keySplit -> {
        SplitsXmlInjector splitsXmlInjector = new SplitsXmlInjector();
        ImmutableList<ModuleSplit> moduleSplits = splitsXmlInjector.process(keySplit.getKey(), keySplit.getValue());
        LocaleConfigXmlInjector localeConfigXmlInjector = new LocaleConfigXmlInjector();
        moduleSplits = localeConfigXmlInjector.process(keySplit.getKey(), moduleSplits);
        return moduleSplits;
    }).flatMap(Collection::stream).collect(toImmutableList()));
    if (deviceSpec.isPresent()) {
        // It is easier to fully check device compatibility once the splits have been generated (in
        // memory). Note that no costly I/O happened up until this point, so it's not too late for
        // this check.
        checkDeviceCompatibilityWithBundle(generatedApks, deviceSpec.get());
    }
    if (command.getOverwriteOutput() && Files.exists(command.getOutputFile())) {
        MoreFiles.deleteRecursively(command.getOutputFile(), RecursiveDeleteOption.ALLOW_INSECURE);
    }
    // Create variants and serialize APKs.
    apkSerializerManager.serializeApkSet(createApkSetWriter(tempDir.getPath()), generatedApks, generatedAssetSlices.build(), deviceSpec, getLocalTestingInfo(appBundle), permanentlyFusedModules);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleValidator(com.android.tools.build.bundletool.validation.AppBundleValidator) GeneratedApks(com.android.tools.build.bundletool.model.GeneratedApks) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) SplitsXmlInjector(com.android.tools.build.bundletool.model.utils.SplitsXmlInjector) GeneratedAssetSlices(com.android.tools.build.bundletool.model.GeneratedAssetSlices) LocaleConfigXmlInjector(com.android.tools.build.bundletool.model.utils.LocaleConfigXmlInjector)

Example 3 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class AbiParityValidatorTest method differentAbis_throws.

@Test
public void differentAbis_throws() throws Exception {
    BundleModule moduleA = new BundleModuleBuilder("a").addFile("lib/x86/lib1.so").addFile("lib/mips/lib2.so").setManifest(androidManifest("com.test.app")).build();
    BundleModule moduleB = new BundleModuleBuilder("b").addFile("lib/x86/lib3.so").addFile("lib/x86_64/lib4.so").setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new AbiParityValidator().validateAllModules(ImmutableList.of(moduleA, moduleB)));
    assertThat(exception).hasMessageThat().contains("must support the same set of ABIs");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 4 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class AbiParityValidatorTest method sameAbis_ok.

@Test
public void sameAbis_ok() throws Exception {
    BundleModule moduleA = new BundleModuleBuilder("a").addFile("lib/x86/lib1.so").addFile("lib/mips/lib2.so").setManifest(androidManifest("com.test.app")).build();
    BundleModule moduleB = new BundleModuleBuilder("b").addFile("lib/x86/lib3.so").addFile("lib/mips/lib4.so").setManifest(androidManifest("com.test.app")).build();
    new AbiParityValidator().validateAllModules(ImmutableList.of(moduleA, moduleB));
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 5 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class AbiParityValidatorTest method sameAbisAndNoAbi_ok.

@Test
public void sameAbisAndNoAbi_ok() throws Exception {
    BundleModule moduleA = new BundleModuleBuilder("a").addFile("lib/x86/lib1.so").addFile("lib/mips/lib2.so").setManifest(androidManifest("com.test.app")).build();
    BundleModule moduleB = new BundleModuleBuilder("b").addFile("lib/x86/lib3.so").addFile("lib/mips/lib4.so").setManifest(androidManifest("com.test.app")).build();
    BundleModule moduleC = new BundleModuleBuilder("c").setManifest(androidManifest("com.test.app")).build();
    new AbiParityValidator().validateAllModules(ImmutableList.of(moduleA, moduleB, moduleC));
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

BundleModule (com.android.tools.build.bundletool.model.BundleModule)404 Test (org.junit.Test)370 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)158 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)112 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)42 ResourceTable (com.android.aapt.Resources.ResourceTable)40 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)29 ImmutableList (com.google.common.collect.ImmutableList)27 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)24 ImmutableSet (com.google.common.collect.ImmutableSet)22 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)21 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 AppBundle (com.android.tools.build.bundletool.model.AppBundle)15 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)15 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 Truth.assertThat (com.google.common.truth.Truth.assertThat)15 RunWith (org.junit.runner.RunWith)15 Assets (com.android.bundle.Files.Assets)14 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)14