Skip to content

Commit 43ef688

Browse files
Fix doctor command for android and adb
Fix doctor command, which checks adb and android incorrectly. Pass correct paths for verification. Also make sure "No issues were detected" is printed when there are no issues.
1 parent 55bdcc2 commit 43ef688

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

lib/android-tools-info.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
149149
}
150150
}
151151

152-
return detectedErrors || isAndroidHomeValid;
152+
return detectedErrors || !isAndroidHomeValid;
153153
}).future<boolean>()();
154154
}
155155

@@ -177,6 +177,24 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
177177
}).future<boolean>()();
178178
}
179179

180+
public getPathToAdbFromAndroidHome(): IFuture<string> {
181+
return (() => {
182+
if(this.androidHome) {
183+
let pathToAdb = path.join(this.androidHome, "platform-tools", "adb") + (this.$hostInfo.isWindows ? ".exe" : "");
184+
try {
185+
this.$childProcess.execFile(pathToAdb, ["help"]).wait();
186+
return pathToAdb;
187+
} catch (err) {
188+
// adb does not exist, so ANDROID_HOME is not set correctly
189+
// try getting default adb path (included in CLI package)
190+
this.$logger.trace(`Error while executing '${pathToAdb} help'. Error is: ${err.message}`);
191+
}
192+
}
193+
194+
return null;
195+
}).future<string>()();
196+
}
197+
180198
/**
181199
* Prints messages on the screen. In case the showWarningsAsErrors flag is set to true, warnings are shown, else - errors.
182200
* Uses logger.warn for warnings and errors.failWithoutHelp when erros must be shown.

lib/common

lib/config.ts

+2-15
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,8 @@ export class StaticConfig extends staticConfigBaseLibPath.StaticConfigBase imple
8181
public getAdbFilePath(): IFuture<string> {
8282
return (() => {
8383
if(!this._adbFilePath) {
84-
let androidHomeEnvVar = process.env.ANDROID_HOME;
85-
if(androidHomeEnvVar) {
86-
let pathToAdb = path.join(androidHomeEnvVar, "platform-tools", "adb");
87-
let childProcess: IChildProcess = this.$injector.resolve("$childProcess");
88-
try {
89-
childProcess.execFile(pathToAdb, ["help"]).wait();
90-
this._adbFilePath = pathToAdb;
91-
} catch (err) {
92-
// adb does not exist, so ANDROID_HOME is not set correctly
93-
// try getting default adb path (included in CLI package)
94-
super.getAdbFilePath().wait();
95-
}
96-
} else {
97-
super.getAdbFilePath().wait();
98-
}
84+
let androidToolsInfo: IAndroidToolsInfo = this.$injector.resolve("androidToolsInfo");
85+
this._adbFilePath = androidToolsInfo.getPathToAdbFromAndroidHome().wait() || super.getAdbFilePath().wait();
9986
}
10087

10188
return this._adbFilePath;

lib/declarations.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,15 @@ interface IAndroidToolsInfo {
127127
/**
128128
* Returns the path to `android` executable. It should be `$ANDROID_HOME/tools/android`.
129129
* In case ANDROID_HOME is not defined, check if `android` is part of $PATH.
130-
* @return {boolean} Path to the `android` executable.
130+
* @return {string} Path to the `android` executable.
131131
*/
132132
getPathToAndroidExecutable(): IFuture<string>;
133+
134+
/**
135+
* Gets the path to `adb` executable from ANDROID_HOME. It should be `$ANDROID_HOME/platform-tools/adb` in case it exists.
136+
* @return {string} Path to the `adb` executable. In case it does not exists, null is returned.
137+
*/
138+
getPathToAdbFromAndroidHome(): IFuture<string>;
133139
}
134140

135141
/**

lib/services/doctor-service.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ class DoctorService implements IDoctorService {
1313

1414
public printWarnings(): boolean {
1515
let result = false;
16-
let sysInfo = this.$sysInfo.getSysInfo();
16+
let androidToolsInfo = {
17+
pathToAdb: this.$androidToolsInfo.getPathToAdbFromAndroidHome().wait(),
18+
pathToAndroid: this.$androidToolsInfo.getPathToAndroidExecutable().wait()
19+
};
20+
let sysInfo = this.$sysInfo.getSysInfo(androidToolsInfo);
1721

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

6770
if(!sysInfo.javaVer) {

0 commit comments

Comments
 (0)