Search in sources :

Example 1 with IncompatibleDeviceException

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

the class InstallMultiApksCommand method extractApkListFromApks.

/**
 * Extracts the apk/apex files that will be installed from a given .apks.
 */
private static ImmutableList<PackagePathVersion> extractApkListFromApks(DeviceSpec deviceSpec, PackagePathVersion apksArchive, Optional<InstalledPackageInfo> installedPackage, TempDirectory tempDirectory) {
    logger.info(String.format("Extracting package '%s'", apksArchive.getPackageName()));
    try {
        Path output = tempDirectory.getPath().resolve(apksArchive.getPackageName());
        Files.createDirectory(output);
        ExtractApksCommand.Builder extractApksCommand = ExtractApksCommand.builder().setApksArchivePath(apksArchive.getPath()).setDeviceSpec(deviceSpec).setOutputDirectory(output);
        ImmutableList<Path> extractedPaths = fixExtension(extractApksCommand.build().execute(), installedPackage.map(InstalledPackageInfo::isApex).orElse(false));
        return extractedPaths.stream().map(path -> PackagePathVersion.create(path, apksArchive.getPackageName(), apksArchive.getVersionCode())).collect(toImmutableList());
    } catch (IncompatibleDeviceException e) {
        logger.warning(String.format("Package '%s' is not supported by the attached device (SDK version %d). Skipping.", apksArchive.getPackageName(), deviceSpec.getSdkVersion()));
        return ImmutableList.of();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) TimeoutException(java.util.concurrent.TimeoutException) SYSTEM_PATH_VARIABLE(com.android.tools.build.bundletool.model.utils.SdkToolsLocator.SYSTEM_PATH_VARIABLE) DeviceSpec(com.android.bundle.Devices.DeviceSpec) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) ImmutableListMultimap.toImmutableListMultimap(com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap) Locale(java.util.Locale) Flag(com.android.tools.build.bundletool.flags.Flag) Duration(java.time.Duration) AdbShellCommandTask(com.android.tools.build.bundletool.device.AdbShellCommandTask) ZipFile(java.util.zip.ZipFile) FilePreconditions.checkFileHasExtension(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileHasExtension) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) InstalledPackageInfo(com.android.tools.build.bundletool.device.PackagesParser.InstalledPackageInfo) ImmutableSet(com.google.common.collect.ImmutableSet) BadgingInfo(com.android.tools.build.bundletool.device.BadgingInfoParser.BadgingInfo) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Aapt2Command(com.android.tools.build.bundletool.androidtools.Aapt2Command) Device(com.android.tools.build.bundletool.device.Device) ParsedFlags(com.android.tools.build.bundletool.flags.ParsedFlags) CanIgnoreReturnValue(com.google.errorprone.annotations.CanIgnoreReturnValue) Streams(com.google.common.collect.Streams) Logger(java.util.logging.Logger) UncheckedIOException(java.io.UncheckedIOException) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) AutoValue(com.google.auto.value.AutoValue) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) FilePreconditions.checkFileExistsAndReadable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Supplier(java.util.function.Supplier) ImmutableList(com.google.common.collect.ImmutableList) DefaultSystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider) BadgingInfoParser(com.android.tools.build.bundletool.device.BadgingInfoParser) Suppliers(com.google.common.base.Suppliers) Comparator.comparing(java.util.Comparator.comparing) AdbServer(com.android.tools.build.bundletool.device.AdbServer) OutputStream(java.io.OutputStream) ANDROID_HOME_VARIABLE(com.android.tools.build.bundletool.model.utils.SdkToolsLocator.ANDROID_HOME_VARIABLE) FilePreconditions.checkFileExistsAndExecutable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndExecutable) AdbCommand(com.android.tools.build.bundletool.androidtools.AdbCommand) Files(java.nio.file.Files) ANDROID_SERIAL_VARIABLE(com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE) Collectors.maxBy(java.util.stream.Collectors.maxBy) IOException(java.io.IOException) PackagesParser(com.android.tools.build.bundletool.device.PackagesParser) Streams.stream(com.google.common.collect.Streams.stream) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagDescription(com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription) Versions(com.android.tools.build.bundletool.model.utils.Versions) CommandDescription(com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription) InputStream(java.io.InputStream) InstalledPackageInfo(com.android.tools.build.bundletool.device.PackagesParser.InstalledPackageInfo) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)

Example 2 with IncompatibleDeviceException

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

the class InstallMultiApksCommand method apksWithPackageName.

private static Optional<PackagePathVersion> apksWithPackageName(Path apksArchivePath, DeviceSpec deviceSpec, Supplier<Aapt2Command> aapt2CommandSupplier) {
    try (TempDirectory tempDirectory = new TempDirectory()) {
        // Any of the extracted .apk/.apex files will work.
        Path extractedFile = ExtractApksCommand.builder().setApksArchivePath(apksArchivePath).setDeviceSpec(deviceSpec).setOutputDirectory(tempDirectory.getPath()).build().execute().get(0);
        BadgingInfo badgingInfo = BadgingInfoParser.parse(aapt2CommandSupplier.get().dumpBadging(extractedFile));
        return Optional.of(PackagePathVersion.create(apksArchivePath, badgingInfo.getPackageName(), badgingInfo.getVersionCode()));
    } catch (IncompatibleDeviceException e) {
        logger.warning(String.format("Unable to determine package name of %s, as it is not compatible with the attached" + " device. Skipping.", apksArchivePath));
        return Optional.empty();
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) BadgingInfo(com.android.tools.build.bundletool.device.BadgingInfoParser.BadgingInfo)

Example 3 with IncompatibleDeviceException

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

the class ApkMatcherTest method ensureDensityAndAbiSplitIsMatchedPerEachModule_split.

@Test
public void ensureDensityAndAbiSplitIsMatchedPerEachModule_split() {
    ZipPath baseMasterSplitApk = ZipPath.create("base-master.apk");
    ZipPath baseX86SplitApk = ZipPath.create("base-x86.apk");
    ZipPath baseMdpiSplitApk = ZipPath.create("base-mdpi.apk");
    ZipPath baseHdpiSplitApk = ZipPath.create("base-hdpi.apk");
    ZipPath screenMdpiApk = ZipPath.create("screen-mdpi.apk");
    BuildApksResult buildApksResult = buildApksResult(splitApkVariant(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(1))), splitApkSet(/* moduleName= */
    "base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseMasterSplitApk), splitApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), baseX86SplitApk), splitApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(HDPI, XHDPI)), baseMdpiSplitApk), splitApkDescription(apkDensityTargeting(HDPI, ImmutableSet.of(MDPI, XHDPI)), baseHdpiSplitApk)), splitApkSet(/* moduleName= */
    "screen", splitApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(HDPI)), screenMdpiApk))));
    Optional<ImmutableSet<String>> allModules = Optional.of(ImmutableSet.of("base", "screen"));
    assertThat(createSafeMatcher(mergeSpecs(density(MDPI), abis("x86")), allModules).getMatchingApks(buildApksResult)).containsExactly(matchedApk(baseMasterSplitApk, "base", INSTALL_TIME), matchedApk(baseX86SplitApk, "base", INSTALL_TIME), matchedApk(baseMdpiSplitApk, "base", INSTALL_TIME), matchedApk(screenMdpiApk, "screen", INSTALL_TIME));
    IncompatibleDeviceException baseException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(MDPI), abis("x86_64")), allModules).getMatchingApks(buildApksResult));
    assertThat(baseException).hasMessageThat().isEqualTo("Missing APKs for [ABI] dimensions in the module 'base' for the provided device.");
    IncompatibleDeviceException screenException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(HDPI), abis("x86")), allModules).getMatchingApks(buildApksResult));
    assertThat(screenException).hasMessageThat().isEqualTo("Missing APKs for [SCREEN_DENSITY] dimensions in the module 'screen' for the provided" + " device.");
    IncompatibleDeviceException multipleDimensionsException = assertThrows(IncompatibleDeviceException.class, () -> createSafeMatcher(mergeSpecs(density(XHDPI), abis("x86_64")), allModules).getMatchingApks(buildApksResult));
    assertThat(multipleDimensionsException).hasMessageThat().isEqualTo("Missing APKs for [ABI, SCREEN_DENSITY] dimensions in the module 'base' for the" + " provided device.");
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) Test(org.junit.Test)

Example 4 with IncompatibleDeviceException

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

the class ApkMatcherTest method textureVariant_preL_incompatibleDevice.

@Test
public void textureVariant_preL_incompatibleDevice() {
    ZipPath apk = ZipPath.create("master-etc1_rgb8.apk");
    BuildApksResult buildApksResult = buildApksResult(standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantTextureTargeting(ATC)), ApkTargeting.getDefaultInstance(), apk));
    IncompatibleDeviceException exception = assertThrows(IncompatibleDeviceException.class, () -> new ApkMatcher(preLDeviceWithGlExtensions("GL_OES_compressed_ETC1_RGB8_texture")).getMatchingApks(buildApksResult));
    assertThat(exception).hasMessageThat().contains("The app doesn't support texture compression formats of the device. Device formats:" + " [ETC1_RGB8], app formats: [ATC]");
}
Also used : BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) Test(org.junit.Test)

Example 5 with IncompatibleDeviceException

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

the class VariantMatcherTest method getAllMatchingVariants_apexVariants_noMatch_throws.

@Test
public void getAllMatchingVariants_apexVariants_noMatch_throws() {
    ZipPath x86Apk = ZipPath.create("standalone-x86.apk");
    ZipPath x64X86Apk = ZipPath.create("standalone-x86_64.x86.apk");
    ImmutableSet<ImmutableSet<AbiAlias>> x86Set = ImmutableSet.of(ImmutableSet.of(X86));
    ImmutableSet<ImmutableSet<AbiAlias>> x64X86Set = ImmutableSet.of(ImmutableSet.of(X86_64, X86));
    MultiAbiTargeting x86Targeting = multiAbiTargeting(x86Set, x64X86Set);
    MultiAbiTargeting x64X86Targeting = multiAbiTargeting(x64X86Set, x86Set);
    Variant x86Variant = multiAbiTargetingApexVariant(x86Targeting, x86Apk);
    Variant x64X86Variant = multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(ImmutableList.of(x86Variant, x64X86Variant)).build();
    IncompatibleDeviceException e = assertThrows(IncompatibleDeviceException.class, () -> new VariantMatcher(abis("x86_64", "armeabi-v7a")).getAllMatchingVariants(buildApksResult));
    assertThat(e).hasMessageThat().contains("No set of ABI architectures that the app supports is contained in the ABI " + "architecture set of the device");
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) Test(org.junit.Test)

Aggregations

IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)12 ZipPath (com.android.tools.build.bundletool.model.ZipPath)10 Test (org.junit.Test)10 BuildApksResult (com.android.bundle.Commands.BuildApksResult)8 DeviceSpec (com.android.bundle.Devices.DeviceSpec)5 Path (java.nio.file.Path)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 MultiAbiTargeting (com.android.bundle.Targeting.MultiAbiTargeting)2 BadgingInfo (com.android.tools.build.bundletool.device.BadgingInfoParser.BadgingInfo)2 TempDirectory (com.android.tools.build.bundletool.io.TempDirectory)2 Variant (com.android.bundle.Commands.Variant)1 Aapt2Command (com.android.tools.build.bundletool.androidtools.Aapt2Command)1 AdbCommand (com.android.tools.build.bundletool.androidtools.AdbCommand)1 CommandDescription (com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription)1 FlagDescription (com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription)1 ANDROID_SERIAL_VARIABLE (com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE)1 AdbServer (com.android.tools.build.bundletool.device.AdbServer)1 AdbShellCommandTask (com.android.tools.build.bundletool.device.AdbShellCommandTask)1 BadgingInfoParser (com.android.tools.build.bundletool.device.BadgingInfoParser)1 Device (com.android.tools.build.bundletool.device.Device)1