Search in sources :

Example 1 with ExecutionException

use of com.taobao.android.builder.tools.command.ExecutionException in project atlas by alibaba.

the class AwoInstaller method installPatchIfDeviceConnected.

/**
     * no device or too many device make install fail
     *
     * @param patch
     * @return
     */
private static boolean installPatchIfDeviceConnected(AndroidBuilder androidBuilder, File patch, String patchPkg, Logger logger) {
    final AndroidDebugBridge androidDebugBridge = initAndroidDebugBridge(androidBuilder);
    if (!androidDebugBridge.isConnected()) {
        throw new RuntimeException("Android Debug Bridge is not connected.");
    }
    waitForInitialDeviceList(androidDebugBridge, logger);
    List<IDevice> devices = Arrays.asList(androidDebugBridge.getDevices());
    String PATCH_INSTALL_DIRECTORY = String.format("%s%s%s", PATCH_INSTALL_DIRECTORY_PREFIX, patchPkg, PATCH_INSTALL_DIRECTORY_SUFFIX);
    if (devices.size() == 0) {
        throw new RuntimeException(String.format("%s%s%s%s%s", "no device connected,please check whether the connection is successful or copy ", patch, " in build/outputs/awbs/libxxx.so ", PATCH_INSTALL_DIRECTORY, " and restart you app"));
    }
    if (devices.size() > 1) {
        throw new RuntimeException("too much devices be connected,please disconnect the others and try again");
    }
    CommandExecutor executor = CommandExecutor.Factory.createDefaultCommmandExecutor();
    executor.setLogger(logger);
    executor.setCaptureStdOut(true);
    executor.setCaptureStdErr(true);
    List<String> cmd = Arrays.asList("push", patch.getAbsolutePath(), PATCH_INSTALL_DIRECTORY + patch.getName());
    try {
        executor.executeCommand(androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), cmd, false);
        return true;
    } catch (ExecutionException e) {
        throw new RuntimeException("Error while trying to push patch to device ", e);
    } finally {
        String errout = executor.getStandardError();
        if ((errout != null) && (errout.trim().length() > 0)) {
            logger.error(errout);
        }
    }
}
Also used : CommandExecutor(com.taobao.android.builder.tools.command.CommandExecutor) IDevice(com.android.ddmlib.IDevice) ExecutionException(com.taobao.android.builder.tools.command.ExecutionException) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Aggregations

AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)1 IDevice (com.android.ddmlib.IDevice)1 CommandExecutor (com.taobao.android.builder.tools.command.CommandExecutor)1 ExecutionException (com.taobao.android.builder.tools.command.ExecutionException)1