use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class BuildApksModule method provideDeviceSpec.
@CommandScoped
@Provides
static Optional<DeviceSpec> provideDeviceSpec(BuildApksCommand command) {
Optional<DeviceSpec> deviceSpec = command.getDeviceSpec();
if (command.getGenerateOnlyForConnectedDevice()) {
AdbServer adbServer = command.getAdbServer().get();
adbServer.init(command.getAdbPath().get());
deviceSpec = Optional.of(new DeviceAnalyzer(adbServer).getDeviceSpec(command.getDeviceId()));
}
if (command.getDeviceTier().isPresent()) {
// --device-tier can only be specified along with --device-spec or --connected-device, so
// deviceSpec should always be present in this case.
checkState(deviceSpec.isPresent(), "Device tier specified but no device was provided.");
deviceSpec = deviceSpec.map(spec -> spec.toBuilder().setDeviceTier(Int32Value.of(command.getDeviceTier().get())).build());
}
return deviceSpec;
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class GetDeviceSpecCommand method execute.
public DeviceSpec execute() {
if (!getOverwriteOutput()) {
FilePreconditions.checkFileDoesNotExist(getOutputPath());
}
Path pathToAdb = getAdbPath();
FilePreconditions.checkFileExistsAndExecutable(pathToAdb);
AdbServer adb = getAdbServer();
adb.init(getAdbPath());
DeviceSpec deviceSpec = new DeviceAnalyzer(adb).getDeviceSpec(getDeviceId());
if (getDeviceTier().isPresent()) {
deviceSpec = deviceSpec.toBuilder().setDeviceTier(Int32Value.of(getDeviceTier().get())).build();
}
if (getDeviceGroups().isPresent()) {
deviceSpec = deviceSpec.toBuilder().addAllDeviceGroups(getDeviceGroups().get()).build();
}
writeDeviceSpecToFile(deviceSpec, getOutputPath());
return deviceSpec;
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class InstallApksCommand method execute.
public void execute() {
BuildApksResult toc = readBuildApksResult();
validateInput(toc);
AdbServer adbServer = getAdbServer();
adbServer.init(getAdbPath());
try (TempDirectory tempDirectory = new TempDirectory()) {
DeviceSpec deviceSpec = new DeviceAnalyzer(adbServer).getDeviceSpec(getDeviceId());
if (getDeviceTier().isPresent()) {
deviceSpec = deviceSpec.toBuilder().setDeviceTier(Int32Value.of(getDeviceTier().get())).build();
}
if (getDeviceGroups().isPresent()) {
deviceSpec = deviceSpec.toBuilder().addAllDeviceGroups(getDeviceGroups().get()).build();
}
final ImmutableList<Path> apksToInstall = getApksToInstall(toc, deviceSpec, tempDirectory.getPath());
final ImmutableList<Path> filesToPush = ImmutableList.<Path>builder().addAll(getApksToPushToStorage(toc, deviceSpec, tempDirectory.getPath())).addAll(getAdditionalLocalTestingFiles().orElse(ImmutableList.of())).build();
AdbRunner adbRunner = new AdbRunner(adbServer);
InstallOptions installOptions = InstallOptions.builder().setAllowDowngrade(getAllowDowngrade()).setAllowTestOnly(getAllowTestOnly()).setTimeout(getTimeout()).build();
if (getDeviceId().isPresent()) {
adbRunner.run(device -> device.installApks(apksToInstall, installOptions), getDeviceId().get());
} else {
adbRunner.run(device -> device.installApks(apksToInstall, installOptions));
}
if (!filesToPush.isEmpty()) {
pushFiles(filesToPush, toc, adbRunner);
}
if (toc.getLocalTestingInfo().getEnabled()) {
cleanUpEmulatedSplits(adbRunner, toc);
}
}
}
use of com.android.bundle.Devices.DeviceSpec 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);
}
}
use of com.android.bundle.Devices.DeviceSpec in project bundletool by google.
the class BuildApksDeviceSpecTest method deviceSpecL_bundleTargetsMPlus_throws.
@Test
public void deviceSpecL_bundleTargetsMPlus_throws() throws Exception {
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(/* Lollipop */
21), abis("x86"), locales("en-US"), density(XHDPI));
bundleSerializer.writeToDisk(createMinSdkBundle(/* Marshmallow */
23), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).build();
Throwable exception = assertThrows(IncompatibleDeviceException.class, command::execute);
assertThat(exception).hasMessageThat().contains("");
}
Aggregations