Search in sources :

Example 1 with ExopackageInfo

use of com.facebook.buck.rules.ExopackageInfo in project buck by facebook.

the class AdbHelper method installApk.

/**
   * Install apk on all matching devices. This functions performs device
   * filtering based on three possible arguments:
   *
   *  -e (emulator-only) - only emulators are passing the filter
   *  -d (device-only) - only real devices are passing the filter
   *  -s (serial) - only device/emulator with specific serial number are passing the filter
   *
   *  If more than one device matches the filter this function will fail unless multi-install
   *  mode is enabled (-x). This flag is used as a marker that user understands that multiple
   *  devices will be used to install the apk if needed.
   */
@SuppressForbidden
public boolean installApk(SourcePathResolver pathResolver, HasInstallableApk hasInstallableApk, boolean installViaSd, boolean quiet) throws InterruptedException {
    Optional<ExopackageInfo> exopackageInfo = hasInstallableApk.getApkInfo().getExopackageInfo();
    if (exopackageInfo.isPresent()) {
        return new ExopackageInstaller(pathResolver, context, this, hasInstallableApk).install(quiet);
    }
    InstallEvent.Started started = InstallEvent.started(hasInstallableApk.getBuildTarget());
    if (!quiet) {
        getBuckEventBus().post(started);
    }
    File apk = pathResolver.getAbsolutePath(hasInstallableApk.getApkInfo().getApkPath()).toFile();
    boolean success = adbCall(new AdbHelper.AdbCallable() {

        @Override
        public boolean call(IDevice device) throws Exception {
            return installApkOnDevice(device, apk, installViaSd, quiet);
        }

        @Override
        @SuppressForbidden
        public String toString() {
            return String.format("install apk %s", hasInstallableApk.getBuildTarget().toString());
        }
    }, quiet);
    if (!quiet) {
        AdbHelper.tryToExtractPackageNameFromManifest(pathResolver, hasInstallableApk.getApkInfo());
        getBuckEventBus().post(InstallEvent.finished(started, success, Optional.empty(), Optional.of(AdbHelper.tryToExtractPackageNameFromManifest(pathResolver, hasInstallableApk.getApkInfo()))));
    }
    return success;
}
Also used : IDevice(com.android.ddmlib.IDevice) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) InterruptionFailedException(com.facebook.buck.util.InterruptionFailedException) CancellationException(java.util.concurrent.CancellationException) InstallException(com.android.ddmlib.InstallException) TimeoutException(com.android.ddmlib.TimeoutException) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) ExecutionException(java.util.concurrent.ExecutionException) ShellCommandUnresponsiveException(com.android.ddmlib.ShellCommandUnresponsiveException) InstallEvent(com.facebook.buck.event.InstallEvent) ExopackageInfo(com.facebook.buck.rules.ExopackageInfo) SuppressForbidden(com.facebook.buck.annotations.SuppressForbidden) File(java.io.File) SuppressForbidden(com.facebook.buck.annotations.SuppressForbidden)

Example 2 with ExopackageInfo

use of com.facebook.buck.rules.ExopackageInfo in project buck by facebook.

the class AndroidBinary method getExopackageInfo.

private Optional<ExopackageInfo> getExopackageInfo() {
    boolean shouldInstall = false;
    ExopackageInfo.Builder builder = ExopackageInfo.builder();
    if (ExopackageMode.enabledForSecondaryDexes(exopackageModes)) {
        PreDexMerge preDexMerge = enhancementResult.getPreDexMerge().get();
        builder.setDexInfo(ExopackageInfo.DexInfo.of(preDexMerge.getMetadataTxtPath(), preDexMerge.getDexDirectory()));
        shouldInstall = true;
    }
    if (ExopackageMode.enabledForNativeLibraries(exopackageModes) && enhancementResult.getCopyNativeLibraries().isPresent()) {
        CopyNativeLibraries copyNativeLibraries = Preconditions.checkNotNull(enhancementResult.getCopyNativeLibraries().get().get(enhancementResult.getAPKModuleGraph().getRootAPKModule()));
        builder.setNativeLibsInfo(ExopackageInfo.NativeLibsInfo.of(copyNativeLibraries.getPathToMetadataTxt(), copyNativeLibraries.getPathToAllLibsDir()));
        shouldInstall = true;
    }
    if (!shouldInstall) {
        return Optional.empty();
    }
    ExopackageInfo exopackageInfo = builder.build();
    return Optional.of(exopackageInfo);
}
Also used : ExopackageInfo(com.facebook.buck.rules.ExopackageInfo)

Aggregations

ExopackageInfo (com.facebook.buck.rules.ExopackageInfo)2 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)1 IDevice (com.android.ddmlib.IDevice)1 InstallException (com.android.ddmlib.InstallException)1 ShellCommandUnresponsiveException (com.android.ddmlib.ShellCommandUnresponsiveException)1 TimeoutException (com.android.ddmlib.TimeoutException)1 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)1 InstallEvent (com.facebook.buck.event.InstallEvent)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 InterruptionFailedException (com.facebook.buck.util.InterruptionFailedException)1 File (java.io.File)1 IOException (java.io.IOException)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1