use of com.android.tools.build.bundletool.androidtools.Aapt2Command in project bundletool by google.
the class InstallMultiApksCommandTest method execute_packageNameMissing_aapt2Failure.
@Test
public void execute_packageNameMissing_aapt2Failure() throws Exception {
// GIVEN fake .apks files, one of which will fail on the aapt2 command...
BuildApksResult tableOfContents1 = fakeTableOfContents(PKG_NAME_1);
Path apksPath1 = createApksArchiveFile(tableOfContents1, tmpDir.resolve("package1.apks"));
BuildApksResult tableOfContents2 = fakeTableOfContents(PKG_NAME_2);
Path apksPath2 = createApksArchiveFile(tableOfContents2, tmpDir.resolve("package2.apks"));
// GIVEN a fake aapt2 command that will fail with an IncompatibleDeviceException.
Aapt2Command aapt2Command = createFakeAapt2CommandFromSupplier(ImmutableMap.of(PKG_NAME_1, () -> {
throw IncompatibleDeviceException.builder().withUserMessage("incompatible device").build();
}, PKG_NAME_2, () -> ImmutableList.of(String.format("package: name='%s' versionCode='%d' ", PKG_NAME_2, 2))));
InstallMultiApksCommand command = InstallMultiApksCommand.builder().setAdbServer(fakeServerOneDevice(device)).setAdbPath(adbPath).setApksArchivePaths(ImmutableList.of(apksPath1, apksPath2)).setAapt2Command(aapt2Command).setAdbCommand(createFakeAdbCommand(expectedInstallApks(PKG_NAME_2, tableOfContents2), /* expectedStaged= */
false, /* expectedEnableRollback= */
false, Optional.empty())).build();
// EXPECT the command to skip the incompatible package.
givenEmptyListPackages(device);
command.execute();
assertAdbCommandExecuted();
}
use of com.android.tools.build.bundletool.androidtools.Aapt2Command in project bundletool by google.
the class InstallMultiApksCommand method execute.
public void execute() throws TimeoutException, IOException {
validateInput();
AdbServer adbServer = getAdbServer();
adbServer.init(getAdbPath());
try (TempDirectory tempDirectory = new TempDirectory()) {
DeviceAnalyzer deviceAnalyzer = new DeviceAnalyzer(adbServer);
DeviceSpec deviceSpec = deviceAnalyzer.getDeviceSpec(getDeviceId());
Device device = deviceAnalyzer.getAndValidateDevice(getDeviceId());
if (getTimeout().isPresent() && !device.getVersion().isGreaterOrEqualThan(Versions.ANDROID_S_API_VERSION)) {
throw InvalidCommandException.builder().withInternalMessage("'%s' flag is supported for Android 12+ devices.", TIMEOUT_MILLIS_FLAG.getName()).build();
}
Path aapt2Dir = tempDirectory.getPath().resolve("aapt2");
Files.createDirectory(aapt2Dir);
Supplier<Aapt2Command> aapt2CommandSupplier = Suppliers.memoize(() -> getOrExtractAapt2Command(aapt2Dir));
ImmutableMap<String, InstalledPackageInfo> existingPackages = getPackagesInstalledOnDevice(device);
ImmutableList<PackagePathVersion> installableApksFilesWithBadgingInfo = getActualApksPaths(tempDirectory).stream().flatMap(apksArchivePath -> stream(apksWithPackageName(apksArchivePath, deviceSpec, aapt2CommandSupplier))).filter(apks -> shouldInstall(apks, existingPackages)).collect(toImmutableList());
ImmutableList<PackagePathVersion> apkFilesToInstall = uniqueApksByPackageName(installableApksFilesWithBadgingInfo).stream().flatMap(apks -> extractApkListFromApks(deviceSpec, apks, Optional.ofNullable(existingPackages.get(apks.getPackageName())), tempDirectory).stream()).collect(toImmutableList());
ImmutableListMultimap<String, String> apkToInstallByPackage = apkFilesToInstall.stream().collect(toImmutableListMultimap(PackagePathVersion::getPackageName, packagePathVersion -> packagePathVersion.getPath().toAbsolutePath().toString()));
if (apkFilesToInstall.isEmpty()) {
logger.warning("No packages found to install! Exiting...");
return;
}
AdbCommand adbCommand = getOrCreateAdbCommand();
ImmutableList<String> commandResults = adbCommand.installMultiPackage(apkToInstallByPackage, getStaged(), getEnableRollback(), getTimeout(), getDeviceId());
logger.info(String.format("Output:\n%s", String.join("\n", commandResults)));
logger.info("Please reboot device to complete installation.");
}
}
Aggregations