Search in sources :

Example 1 with SdkBundleBuilder

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

the class BuildSdkApksManagerTest method manifestIsMutated.

@Test
public void manifestIsMutated() throws Exception {
    Integer versionCode = 1253;
    execute(new SdkBundleBuilder().setVersionCode(versionCode).build());
    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.getMinSdkVersion()).hasValue(SDK_SANDBOX_MIN_VERSION);
    assertThat(manifest.getManifestRoot().getElement().getAndroidAttribute(VERSION_NAME_RESOURCE_ID).get().getValueAsString()).isEqualTo("15.0.5");
    assertThat(manifest.getManifestRoot().getElement().getAndroidAttribute(VERSION_CODE_RESOURCE_ID).get().getValueAsDecimalInteger()).isEqualTo(versionCode);
}
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) 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 2 with SdkBundleBuilder

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

the class BuildSdkApksManagerTest method sdkVersionInformationIsSet.

@Test
public void sdkVersionInformationIsSet() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withSdkLibraryElement("100"), withMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME, "132"))).build()).setVersionCode(99).build();
    execute(sdkBundle);
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    SdkVersionInformation version = result.getVersion();
    assertThat(version.getVersionCode()).isEqualTo(99);
    assertThat(version.getMajor()).isEqualTo(100);
    assertThat(version.getPatch()).isEqualTo(132);
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) SdkVersionInformation(com.android.bundle.Commands.SdkVersionInformation) ZipFile(java.util.zip.ZipFile) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) Test(org.junit.Test)

Example 3 with SdkBundleBuilder

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

the class BuildSdkApksManagerTest method apksSigned.

@Test
public void apksSigned() throws Exception {
    execute(new SdkBundleBuilder().build());
    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);
    ApkVerifier.Result verifierResult = new ApkVerifier.Builder(apkFile).build().verify();
    assertThat(verifierResult.isVerified()).isTrue();
    assertThat(verifierResult.getSignerCertificates()).containsExactly(certificate);
}
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) ApkVerifier(com.android.apksig.ApkVerifier) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) 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 4 with SdkBundleBuilder

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

the class BuildSdkApksManagerTest method sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged.

@Test
public void sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withMinSdkVersion(SDK_SANDBOX_MIN_VERSION + 5), withSdkLibraryElement("20"), withMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME, "12"))).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.getMinSdkVersion()).hasValue(SDK_SANDBOX_MIN_VERSION + 5);
}
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 5 with SdkBundleBuilder

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

the class BuildSdkApksManagerTest method sdkPatchVersionIsSetToDefaultValue.

@Test
public void sdkPatchVersionIsSetToDefaultValue() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withSdkLibraryElement("1181894"))).build()).build();
    execute(sdkBundle);
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    SdkVersionInformation version = result.getVersion();
    assertThat(version.getPatch()).isEqualTo(Long.parseLong(DEFAULT_SDK_PATCH_VERSION));
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) SdkVersionInformation(com.android.bundle.Commands.SdkVersionInformation) ZipFile(java.util.zip.ZipFile) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) 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