Search in sources :

Example 1 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer 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;
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) DefaultSigningConfigurationProvider(com.android.tools.build.bundletool.model.DefaultSigningConfigurationProvider) ApkModifier(com.android.tools.build.bundletool.model.ApkModifier) ApkListener(com.android.tools.build.bundletool.model.ApkListener) DeviceSpec(com.android.bundle.Devices.DeviceSpec) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) Retention(java.lang.annotation.Retention) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) Module(dagger.Module) Qualifier(javax.inject.Qualifier) ApkSerializerModule(com.android.tools.build.bundletool.io.ApkSerializerModule) OptimizationsMerger(com.android.tools.build.bundletool.optimizations.OptimizationsMerger) Version(com.android.tools.build.bundletool.model.version.Version) AdbServer(com.android.tools.build.bundletool.device.AdbServer) Provides(dagger.Provides) SourceStamp(com.android.tools.build.bundletool.model.SourceStamp) PrintStream(java.io.PrintStream) Int32Value(com.google.protobuf.Int32Value) SigningConfigurationProvider(com.android.tools.build.bundletool.model.SigningConfigurationProvider) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) RUNTIME(java.lang.annotation.RetentionPolicy.RUNTIME) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ApkBuildMode(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode) BundleConfig(com.android.bundle.Config.BundleConfig) Optional(java.util.Optional) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) AdbServer(com.android.tools.build.bundletool.device.AdbServer) Provides(dagger.Provides)

Example 2 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer 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;
}
Also used : Path(java.nio.file.Path) DeviceSpec(com.android.bundle.Devices.DeviceSpec) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) AdbServer(com.android.tools.build.bundletool.device.AdbServer)

Example 3 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer 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);
        }
    }
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) BuildApksResult(com.android.bundle.Commands.BuildApksResult) AdbRunner(com.android.tools.build.bundletool.device.AdbRunner) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) InstallOptions(com.android.tools.build.bundletool.device.Device.InstallOptions) AdbServer(com.android.tools.build.bundletool.device.AdbServer)

Example 4 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.

the class InstallApksCommandTest method badSdkVersionDevice_throws.

@Test
public void badSdkVersionDevice_throws() throws Exception {
    DeviceSpec deviceSpec = mergeSpecs(sdkVersion(1), density(480), abis("x86_64", "x86"), locales("en-US"));
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(simpleApksPath).setAdbPath(adbPath).setAdbServer(adbServer).build();
    Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
    assertThat(exception).hasMessageThat().contains("Error retrieving device SDK version");
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Example 5 with AdbServer

use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.

the class InstallApksCommandTest method localTestingMode_allModules.

@Test
@Theory
public void localTestingMode_allModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    String installTimeFeature = "installtime_feature";
    String onDemandFeature = "ondemand_feature";
    String installTimeAsset = "installtime_asset";
    String onDemandAsset = "ondemand_asset";
    ZipPath baseApk = ZipPath.create("base-master.apk");
    ZipPath baseEnApk = ZipPath.create("base-en.apk");
    ZipPath installTimeFeatureMasterApk = ZipPath.create(installTimeFeature + "-master.apk");
    ZipPath installTimeFeatureEnApk = ZipPath.create(installTimeFeature + "-en.apk");
    ZipPath installTimeFeaturePlApk = ZipPath.create(installTimeFeature + "-pl.apk");
    ZipPath onDemandFeatureMasterApk = ZipPath.create(onDemandFeature + "-master.apk");
    ZipPath installTimeAssetMasterApk = ZipPath.create(installTimeAsset + "-master.apk");
    ZipPath installTimeAssetEnApk = ZipPath.create(installTimeAsset + "-en.apk");
    ZipPath onDemandAssetMasterApk = ZipPath.create(onDemandAsset + "-master.apk");
    BuildApksResult tableOfContent = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk), createApkDescription(apkLanguageTargeting("en"), baseEnApk, /* isMasterSplit= */
    false)), createSplitApkSet(installTimeFeature, createMasterApkDescription(ApkTargeting.getDefaultInstance(), installTimeFeatureMasterApk), createApkDescription(apkLanguageTargeting("en"), installTimeFeatureEnApk, /* isMasterSplit= */
    false), createApkDescription(apkLanguageTargeting("pl"), installTimeFeaturePlApk, /* isMasterSplit= */
    false)), createSplitApkSet(onDemandFeature, DeliveryType.ON_DEMAND, /* moduleDependencies= */
    ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureMasterApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeAsset).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeAssetMasterApk)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeAssetEnApk))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandAsset).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandAssetMasterApk))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing").build()).build();
    Path apksFile = createApks(tableOfContent, apksInDirectory);
    List<Path> installedApks = new ArrayList<>();
    List<Path> pushedFiles = new ArrayList<>();
    FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
    AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(fakeDevice));
    fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
    fakeDevice.setPushSideEffect((files, installOptions) -> pushedFiles.addAll(files));
    InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of("_ALL_")).build().execute();
    // Base, install-time and on-demand features and install-time assets.
    assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), onDemandFeatureMasterApk.toString(), installTimeAssetMasterApk.toString(), installTimeAssetEnApk.toString());
    // Base config splits, install-time and on-demand features and on-demand assets. All languages.
    assertThat(getFileNames(pushedFiles)).containsExactly(baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), installTimeFeaturePlApk.toString(), onDemandFeatureMasterApk.toString(), onDemandAssetMasterApk.toString());
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ArrayList(java.util.ArrayList) ZipPath(com.android.tools.build.bundletool.model.ZipPath) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) AdbServer(com.android.tools.build.bundletool.device.AdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Aggregations

AdbServer (com.android.tools.build.bundletool.device.AdbServer)25 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)20 Test (org.junit.Test)20 Path (java.nio.file.Path)19 ZipPath (com.android.tools.build.bundletool.model.ZipPath)17 FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)17 BuildApksResult (com.android.bundle.Commands.BuildApksResult)13 ArrayList (java.util.ArrayList)10 DeviceSpec (com.android.bundle.Devices.DeviceSpec)9 Theory (org.junit.experimental.theories.Theory)9 DeviceAnalyzer (com.android.tools.build.bundletool.device.DeviceAnalyzer)4 ParsedFlags (com.android.tools.build.bundletool.flags.ParsedFlags)2 TempDirectory (com.android.tools.build.bundletool.io.TempDirectory)2 BundleConfig (com.android.bundle.Config.BundleConfig)1 Aapt2Command (com.android.tools.build.bundletool.androidtools.Aapt2Command)1 AdbCommand (com.android.tools.build.bundletool.androidtools.AdbCommand)1 ApkBuildMode (com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode)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