Search in sources :

Example 6 with SdkBundleBuilder

use of com.android.tools.build.bundletool.testing.SdkBundleBuilder in project bundletool by google.

the class BuildSdkApksManagerTest method sdkManifestMutation_patchVersionNotSet_defaultPatchVersionAdded.

@Test
public void sdkManifestMutation_patchVersionNotSet_defaultPatchVersionAdded() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withSdkLibraryElement("20"))).build()).build();
    execute(sdkBundle);
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    Variant variant = result.getVariant(0);
    ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
    File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
    AndroidManifest manifest = extractAndroidManifest(apkFile, tmpDir);
    assertThat(manifest.getMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME)).hasValue(DEFAULT_SDK_PATCH_VERSION);
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) Variant(com.android.bundle.Commands.Variant) ApkDescription(com.android.bundle.Commands.ApkDescription) ZipFile(java.util.zip.ZipFile) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) TestUtils.extractAndroidManifest(com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) ApkSetUtils.extractTocFromSdkApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromSdkApkSetFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) Test(org.junit.Test)

Example 7 with SdkBundleBuilder

use of com.android.tools.build.bundletool.testing.SdkBundleBuilder in project bundletool by google.

the class BuildSdkApksManagerTest method tocIsCorrect.

@Test
public void tocIsCorrect() throws Exception {
    execute(new SdkBundleBuilder().build());
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    assertThat(result.getVariantCount()).isEqualTo(1);
    assertThat(result.getPackageName()).isEqualTo(PACKAGE_NAME);
    assertThat(result.getBundletool().getVersion()).isEqualTo(DEFAULT_BUNDLE_CONFIG.getBundletool().getVersion());
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) ZipFile(java.util.zip.ZipFile) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) Test(org.junit.Test)

Example 8 with SdkBundleBuilder

use of com.android.tools.build.bundletool.testing.SdkBundleBuilder in project bundletool by google.

the class BuildApksCommandTest method sdkBundleHasInvalidManifestEntry_sdkBundleValidationFails.

@Test
public void sdkBundleHasInvalidManifestEntry_sdkBundleValidationFails() throws Exception {
    new SdkBundleSerializer().writeToDisk(new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest("package.name", withMinSdkVersion(32), // Major version must be a long.
    withSdkLibraryElement("MajorVersionNotLong"))).build()).build(), sdkBundlePath1);
    createAppBundle(bundlePath);
    BuildApksCommand command = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--sdk-bundles=" + sdkBundlePath1), fakeAdbServer);
    Exception e = assertThrows(InvalidBundleException.class, command::execute);
    assertThat(e).hasMessageThat().contains("SDK Major version in <" + SDK_LIBRARY_ELEMENT_NAME + "> cannot be parsed to a Long.");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) FlagParseException(com.android.tools.build.bundletool.flags.FlagParser.FlagParseException) IOException(java.io.IOException) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) JoseException(org.jose4j.lang.JoseException) TestUtils.expectMissingRequiredBuilderPropertyException(com.android.tools.build.bundletool.testing.TestUtils.expectMissingRequiredBuilderPropertyException) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) TestUtils.expectMissingRequiredFlagException(com.android.tools.build.bundletool.testing.TestUtils.expectMissingRequiredFlagException) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) SdkBundleSerializer(com.android.tools.build.bundletool.io.SdkBundleSerializer) Test(org.junit.Test)

Aggregations

SdkBundleBuilder (com.android.tools.build.bundletool.testing.SdkBundleBuilder)8 Test (org.junit.Test)8 BuildSdkApksResult (com.android.bundle.Commands.BuildSdkApksResult)7 ZipFile (java.util.zip.ZipFile)7 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)6 ApkDescription (com.android.bundle.Commands.ApkDescription)4 Variant (com.android.bundle.Commands.Variant)4 SdkBundle (com.android.tools.build.bundletool.model.SdkBundle)4 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)4 ApkSetUtils.extractTocFromSdkApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromSdkApkSetFile)4 File (java.io.File)4 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)3 TestUtils.extractAndroidManifest (com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest)3 SdkVersionInformation (com.android.bundle.Commands.SdkVersionInformation)2 ApkVerifier (com.android.apksig.ApkVerifier)1 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)1 FlagParseException (com.android.tools.build.bundletool.flags.FlagParser.FlagParseException)1 SdkBundleSerializer (com.android.tools.build.bundletool.io.SdkBundleSerializer)1 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)1 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)1