Skip to content

Fix doctor command for android and adb #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/android-tools-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
}
}

return detectedErrors || isAndroidHomeValid;
return detectedErrors || !isAndroidHomeValid;
}).future<boolean>()();
}

Expand Down Expand Up @@ -177,6 +177,24 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
}).future<boolean>()();
}

public getPathToAdbFromAndroidHome(): IFuture<string> {
return (() => {
if(this.androidHome) {
let pathToAdb = path.join(this.androidHome, "platform-tools", "adb");
try {
this.$childProcess.execFile(pathToAdb, ["help"]).wait();
return pathToAdb;
} catch (err) {
// adb does not exist, so ANDROID_HOME is not set correctly
// try getting default adb path (included in CLI package)
this.$logger.trace(`Error while executing '${pathToAdb} help'. Error is: ${err.message}`);
}
}

return null;
}).future<string>()();
}

/**
* Prints messages on the screen. In case the showWarningsAsErrors flag is set to true, warnings are shown, else - errors.
* Uses logger.warn for warnings and errors.failWithoutHelp when erros must be shown.
Expand Down
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ $injector.require("androidToolsInfo", "./android-tools-info");

$injector.require("iosUsbLiveSyncServiceLocator", "./services/usb-livesync-service");
$injector.require("androidUsbLiveSyncServiceLocator", "./services/usb-livesync-service");
$injector.require("sysInfo", "./sys-info");
2 changes: 1 addition & 1 deletion lib/common
17 changes: 2 additions & 15 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,8 @@ export class StaticConfig extends staticConfigBaseLibPath.StaticConfigBase imple
public getAdbFilePath(): IFuture<string> {
return (() => {
if(!this._adbFilePath) {
let androidHomeEnvVar = process.env.ANDROID_HOME;
if(androidHomeEnvVar) {
let pathToAdb = path.join(androidHomeEnvVar, "platform-tools", "adb");
let childProcess: IChildProcess = this.$injector.resolve("$childProcess");
try {
childProcess.execFile(pathToAdb, ["help"]).wait();
this._adbFilePath = pathToAdb;
} catch (err) {
// adb does not exist, so ANDROID_HOME is not set correctly
// try getting default adb path (included in CLI package)
super.getAdbFilePath().wait();
}
} else {
super.getAdbFilePath().wait();
}
let androidToolsInfo: IAndroidToolsInfo = this.$injector.resolve("androidToolsInfo");
this._adbFilePath = androidToolsInfo.getPathToAdbFromAndroidHome().wait() || super.getAdbFilePath().wait();
}

return this._adbFilePath;
Expand Down
8 changes: 7 additions & 1 deletion lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ interface IAndroidToolsInfo {
/**
* Returns the path to `android` executable. It should be `$ANDROID_HOME/tools/android`.
* In case ANDROID_HOME is not defined, check if `android` is part of $PATH.
* @return {boolean} Path to the `android` executable.
* @return {string} Path to the `android` executable.
*/
getPathToAndroidExecutable(): IFuture<string>;

/**
* Gets the path to `adb` executable from ANDROID_HOME. It should be `$ANDROID_HOME/platform-tools/adb` in case it exists.
* @return {string} Path to the `adb` executable. In case it does not exists, null is returned.
*/
getPathToAdbFromAndroidHome(): IFuture<string>;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject

// this call will fail in case `android` is not set correctly.
this.$androidToolsInfo.getPathToAndroidExecutable().wait();
this.$androidToolsInfo.validateJavacVersion(this.$sysInfo.getSysInfo().javacVersion, {showWarningsAsErrors: true}).wait();
this.$androidToolsInfo.validateJavacVersion(this.$sysInfo.getSysInfo().wait().javacVersion, {showWarningsAsErrors: true}).wait();
}).future<void>()();
}

Expand Down
15 changes: 2 additions & 13 deletions lib/services/doctor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DoctorService implements IDoctorService {

public printWarnings(): boolean {
let result = false;
let sysInfo = this.$sysInfo.getSysInfo();
let sysInfo = this.$sysInfo.getSysInfo().wait();

if (!sysInfo.adbVer) {
this.$logger.warn("WARNING: adb from the Android SDK is not installed or is not configured properly.");
Expand Down Expand Up @@ -59,19 +59,8 @@ class DoctorService implements IDoctorService {
result = true;
}
} else {
this.$logger.warn("WARNING: You can work with iOS only on Mac OS X systems.");
this.$logger.out("NOTE: You can develop for iOS only on Mac OS X systems.");
this.$logger.out("To be able to work with iOS devices and projects, you need Mac OS X Mavericks or later." + EOL);
result = true;
}

if(!sysInfo.javaVer) {
this.$logger.warn("WARNING: The Java Development Kit (JDK) is not installed or is not configured properly.");
this.$logger.out("You will not be able to work with the Android SDK and you might not be able" + EOL
+ "to perform some Android-related operations. To ensure that you can develop and" + EOL
+ "test your apps for Android, verify that you have installed the JDK as" + EOL
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8)" + EOL
+ "or http://docs.oracle.com/javase/7/docs/webnotes/install/ (for JDK 7)." + EOL);
result = true;
}

let androidToolsIssues = this.$androidToolsInfo.validateInfo().wait();
Expand Down
25 changes: 25 additions & 0 deletions lib/sys-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
///<reference path=".d.ts"/>
"use strict";

import {SysInfoBase} from "./common/sys-info-base";

export class SysInfo extends SysInfoBase {
constructor(protected $childProcess: IChildProcess,
protected $hostInfo: IHostInfo,
protected $iTunesValidator: Mobile.IiTunesValidator,
protected $logger: ILogger,
private $androidToolsInfo: IAndroidToolsInfo) {
super($childProcess, $hostInfo, $iTunesValidator, $logger);
}

public getSysInfo(androidToolsInfo?: {pathToAdb: string, pathToAndroid: string}): IFuture<ISysInfoData> {
return ((): ISysInfoData => {
let defaultAndroidToolsInfo = {
pathToAdb: this.$androidToolsInfo.getPathToAdbFromAndroidHome().wait(),
pathToAndroid: this.$androidToolsInfo.getPathToAndroidExecutable().wait()
};
return super.getSysInfo(androidToolsInfo || defaultAndroidToolsInfo).wait();
}).future<ISysInfoData>()();
}
}
$injector.register("sysInfo", SysInfo);