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);
}
}
}
Aggregations