Search in sources :

Example 66 with AppBundle

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

the class AssetSlicesGeneratorTest method onDemandAssetModule_addsVersionName.

@Test
public void onDemandAssetModule_addsVersionName() throws Exception {
    AppBundle appBundle = createAppBundle(new BundleModuleBuilder("asset_module").setManifest(androidManifestForAssetModule(PACKAGE_NAME, withOnDemandDelivery())).build());
    ImmutableList<ModuleSplit> assetSlices = new AssetSlicesGenerator(appBundle, ApkGenerationConfiguration.getDefaultInstance(), Optional.empty()).generateAssetSlices();
    assertThat(assetSlices).hasSize(1);
    ModuleSplit assetSlice = assetSlices.get(0);
    assertThat(assetSlice.getAndroidManifest().getVersionName()).hasValue(VERSION_NAME);
}
Also used : AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Test(org.junit.Test)

Example 67 with AppBundle

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

the class BuildExtractApksTest method forLDeviceUniversalApk.

@Test
public void forLDeviceUniversalApk() throws Exception {
    AppBundle appBundle = createAppBundle();
    bundleSerializer.writeToDisk(appBundle, bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setAapt2Command(aapt2Command).setApkBuildMode(UNIVERSAL).build();
    Path apkSetFilePath = command.execute();
    ExtractApksCommand extractApksCommand = ExtractApksCommand.builder().setOutputDirectory(outputDir).setApksArchivePath(apkSetFilePath).setDeviceSpec(L_X86_64_ES_DEVICE).build();
    ImmutableList<Path> extractedApks = extractApksCommand.execute();
    assertThat(extractedApks.stream().map(Path::getFileName).map(Path::toString).collect(toImmutableList())).containsExactly("universal.apk");
}
Also used : Path(java.nio.file.Path) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ExtractApksCommand(com.android.tools.build.bundletool.commands.ExtractApksCommand) BuildApksCommand(com.android.tools.build.bundletool.commands.BuildApksCommand) Test(org.junit.Test)

Example 68 with AppBundle

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

the class BuildExtractApksTest method forPreLDeviceUniversalApk.

@Test
public void forPreLDeviceUniversalApk() throws Exception {
    AppBundle appBundle = createAppBundle();
    bundleSerializer.writeToDisk(appBundle, bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setAapt2Command(aapt2Command).setApkBuildMode(UNIVERSAL).build();
    Path apkSetFilePath = command.execute();
    ExtractApksCommand extractApksCommand = ExtractApksCommand.builder().setOutputDirectory(outputDir).setApksArchivePath(apkSetFilePath).setDeviceSpec(PRE_L_X86_ES_DEVICE).build();
    ImmutableList<Path> extractedApks = extractApksCommand.execute();
    assertThat(extractedApks.stream().map(Path::getFileName).map(Path::toString).collect(toImmutableList())).containsExactly("universal.apk");
}
Also used : Path(java.nio.file.Path) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ExtractApksCommand(com.android.tools.build.bundletool.commands.ExtractApksCommand) BuildApksCommand(com.android.tools.build.bundletool.commands.BuildApksCommand) Test(org.junit.Test)

Example 69 with AppBundle

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

the class BuildExtractApksTest method forLDevice.

@Test
public void forLDevice() throws Exception {
    AppBundle appBundle = createAppBundle();
    bundleSerializer.writeToDisk(appBundle, bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setAapt2Command(aapt2Command).build();
    Path apkSetFilePath = command.execute();
    ExtractApksCommand extractApksCommand = ExtractApksCommand.builder().setOutputDirectory(outputDir).setApksArchivePath(apkSetFilePath).setDeviceSpec(L_X86_64_ES_DEVICE).build();
    ImmutableList<String> extractedApks = extractApksCommand.execute().stream().map(Path::getFileName).map(Path::toString).collect(toImmutableList());
    assertThat(extractedApks).hasSize(4);
    assertThat(extractedApks).containsAtLeast("base-xhdpi.apk", "base-es.apk");
    assertThat(extractedApks).containsAnyOf("base-master.apk", "base-master_2.apk");
    assertThat(extractedApks).containsAnyOf("base-x86_64.apk", "base-x86_64_2.apk");
}
Also used : Path(java.nio.file.Path) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ExtractApksCommand(com.android.tools.build.bundletool.commands.ExtractApksCommand) BuildApksCommand(com.android.tools.build.bundletool.commands.BuildApksCommand) Test(org.junit.Test)

Example 70 with AppBundle

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

the class BundleModuleMergerTest method fuseApplicationElementsInManifest_1_8_0.

@Test
public void fuseApplicationElementsInManifest_1_8_0() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery(), withSplitNameActivity("activity1", "detail"), withSplitNameService("service", "detail"));
    createBasicZipBuilder(BUNDLE_CONFIG_1_8_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundle = BundleModuleMerger.mergeNonRemovableInstallTimeModules(AppBundle.buildFromZip(appBundleZip), /* overrideBundleToolVersion = */
        false);
        XmlNode fusedManifest = androidManifest("com.test.app.detail", withSplitNameActivity("activity1", "detail"), withSplitNameService("service", "detail"), withMetadataValue("com.android.dynamic.apk.fused.modules", "base,detail"));
        assertThat(appBundle.getBaseModule().getAndroidManifest().getManifestRoot().getProto()).isEqualTo(fusedManifest);
    }
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Aggregations

AppBundle (com.android.tools.build.bundletool.model.AppBundle)205 Test (org.junit.Test)193 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)137 ZipFile (java.util.zip.ZipFile)136 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)112 Truth.assertThat (com.google.common.truth.Truth.assertThat)112 Path (java.nio.file.Path)112 RunWith (org.junit.runner.RunWith)112 BuildApksResult (com.android.bundle.Commands.BuildApksResult)106 AppBundleSerializer (com.android.tools.build.bundletool.io.AppBundleSerializer)104 ImmutableList (com.google.common.collect.ImmutableList)102 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)101 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)100 Before (org.junit.Before)100 Rule (org.junit.Rule)100 TemporaryFolder (org.junit.rules.TemporaryFolder)100 Variant (com.android.bundle.Commands.Variant)98 IOException (java.io.IOException)94 ApkDescription (com.android.bundle.Commands.ApkDescription)90 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)87