use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method mergeInstallTimeDisabled.
@Test
public void mergeInstallTimeDisabled() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app"))).addModule("abi_feature", builder -> builder.addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setManifest(androidManifest("com.test.app", withInstallTimeDelivery(), withFusingAttribute(true), withInstallTimeRemovableElement(true)))).setBundleConfig(BundleConfigBuilder.create().setVersion("1.0.0").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
assertThat(splitApkVariants).isNotEmpty();
assertThat(result.getPermanentlyFusedModulesList()).isEmpty();
for (Variant splitApkVariant : splitApkVariants(result)) {
assertThat(splitApkVariant.getApkSetList()).comparingElementsUsing(Correspondence.from((ApkSet apkSet, String moduleName) -> apkSet != null && apkSet.getModuleMetadata().getName().equals(moduleName), "equals")).containsExactly("base", "abi_feature");
}
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_oneModuleOneVariant.
@Test
public void buildApksCommand_standalone_oneModuleOneVariant() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant standaloneApkVariant = standaloneApkVariants(result).get(0);
assertThat(standaloneApkVariant.getApkSetList()).hasSize(1);
ApkSet shards = standaloneApkVariant.getApkSet(0);
assertThat(shards.getModuleMetadata().getName()).isEqualTo("base");
assertThat(shards.getApkDescriptionList()).hasSize(1);
assertThat(ZipPath.create(shards.getApkDescription(0).getPath()).getFileName()).isEqualTo(ZipPath.create("standalone.apk"));
assertThat(apkSetFile).hasFile(shards.getApkDescription(0).getPath());
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_mergeApplicationElementsFromFeatureManifest.
@Test
public void buildApksCommand_universal_mergeApplicationElementsFromFeatureManifest() throws Exception {
final int baseThemeRefId = 123;
final int featureThemeRefId = 4456;
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app", withCustomThemeActivity("activity1", baseThemeRefId), withCustomThemeActivity("activity2", baseThemeRefId))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature", builder -> builder.setManifest(androidManifestForFeature("com.test.app.feature1", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withCustomThemeActivity("activity1", featureThemeRefId), withSplitNameService("service1", "feature")))).addModule("not_fused", builder -> builder.setManifest(androidManifestForFeature("com.test.app.feature2", withFusingAttribute(false), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withCustomThemeActivity("activity2", featureThemeRefId), withSplitNameService("service2", "not_fused")))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Correct modules selected for merging.
assertThat(universalApk.getStandaloneApkMetadata().getFusedModuleNameList()).containsExactly("base", "feature");
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
AndroidManifest manifest = extractAndroidManifest(universalApkFile, tmpDir);
Map<String, Integer> refIdByActivity = transformValues(manifest.getActivitiesByName(), activity -> activity.getAndroidAttribute(AndroidManifest.THEME_RESOURCE_ID).get().getValueAsRefId());
assertThat(refIdByActivity).containsExactly("activity1", featureThemeRefId, "activity2", baseThemeRefId);
assertThat(getServicesFromManifest(manifest)).containsExactly("service1");
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_correctStandaloneGenerated.
@Test
public void connectedDevice_correctStandaloneGenerated() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(19), abis("x86"), locales("en-US"), density(DensityAlias.HDPI)))));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "standalones/standalone-hdpi.apk");
result = extractTocFromApkSetFile(apksZipFile, outputDir);
}
assertThat(result.getVariantList()).hasSize(1);
Variant variant = result.getVariant(0);
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
// One standalone APK.
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-hdpi.apk");
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksConnectedDeviceTest method connectedDevice_withDeviceId_correctStandaloneGenerated.
@Test
public void connectedDevice_withDeviceId_correctStandaloneGenerated() throws Exception {
fakeAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(FakeDevice.fromDeviceSpec("id1", DeviceState.ONLINE, mergeSpecs(sdkVersion(19), abis("x86"), locales("en-US"), density(DensityAlias.XHDPI))), FakeDevice.fromDeviceSpec("id2", DeviceState.ONLINE, lDeviceWithDensity(DensityAlias.XXHDPI))));
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
// Selecting "id1" device - KitKat, XHDPI.
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setGenerateOnlyForConnectedDevice(true).setAdbPath(sdkDirPath.resolve("platform-tools").resolve("adb")).setAdbServer(fakeAdbServer).setDeviceId("id1").build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "standalones/standalone-xhdpi.apk");
result = extractTocFromApkSetFile(apksZipFile, outputDir);
}
assertThat(result.getVariantList()).hasSize(1);
Variant variant = result.getVariant(0);
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
// One standalone APK.
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkNamesInSet(apkSet)).containsExactly("standalones/standalone-xhdpi.apk");
}
Aggregations