Skip to content

Commit 433334c

Browse files
Merge pull request #1170 from NativeScript/vladimirov/fix-doctor-command-again
Fix doctor command for android and adb
2 parents 76b5a35 + b150659 commit 433334c

8 files changed

+58
-32
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");
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/bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,4 @@ $injector.require("androidToolsInfo", "./android-tools-info");
8484

8585
$injector.require("iosUsbLiveSyncServiceLocator", "./services/usb-livesync-service");
8686
$injector.require("androidUsbLiveSyncServiceLocator", "./services/usb-livesync-service");
87+
$injector.require("sysInfo", "./sys-info");

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/android-project-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
8181

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

lib/services/doctor-service.ts

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

1414
public printWarnings(): boolean {
1515
let result = false;
16-
let sysInfo = this.$sysInfo.getSysInfo();
16+
let sysInfo = this.$sysInfo.getSysInfo().wait();
1717

1818
if (!sysInfo.adbVer) {
1919
this.$logger.warn("WARNING: adb from the Android SDK is not installed or is not configured properly.");
@@ -59,19 +59,8 @@ class DoctorService implements IDoctorService {
5959
result = true;
6060
}
6161
} else {
62-
this.$logger.warn("WARNING: You can work with iOS only on Mac OS X systems.");
62+
this.$logger.out("NOTE: You can develop for iOS only on Mac OS X systems.");
6363
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;
65-
}
66-
67-
if(!sysInfo.javaVer) {
68-
this.$logger.warn("WARNING: The Java Development Kit (JDK) is not installed or is not configured properly.");
69-
this.$logger.out("You will not be able to work with the Android SDK and you might not be able" + EOL
70-
+ "to perform some Android-related operations. To ensure that you can develop and" + EOL
71-
+ "test your apps for Android, verify that you have installed the JDK as" + EOL
72-
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8)" + EOL
73-
+ "or http://docs.oracle.com/javase/7/docs/webnotes/install/ (for JDK 7)." + EOL);
74-
result = true;
7564
}
7665

7766
let androidToolsIssues = this.$androidToolsInfo.validateInfo().wait();

lib/sys-info.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
///<reference path=".d.ts"/>
2+
"use strict";
3+
4+
import {SysInfoBase} from "./common/sys-info-base";
5+
6+
export class SysInfo extends SysInfoBase {
7+
constructor(protected $childProcess: IChildProcess,
8+
protected $hostInfo: IHostInfo,
9+
protected $iTunesValidator: Mobile.IiTunesValidator,
10+
protected $logger: ILogger,
11+
private $androidToolsInfo: IAndroidToolsInfo) {
12+
super($childProcess, $hostInfo, $iTunesValidator, $logger);
13+
}
14+
15+
public getSysInfo(androidToolsInfo?: {pathToAdb: string, pathToAndroid: string}): IFuture<ISysInfoData> {
16+
return ((): ISysInfoData => {
17+
let defaultAndroidToolsInfo = {
18+
pathToAdb: this.$androidToolsInfo.getPathToAdbFromAndroidHome().wait(),
19+
pathToAndroid: this.$androidToolsInfo.getPathToAndroidExecutable().wait()
20+
};
21+
return super.getSysInfo(androidToolsInfo || defaultAndroidToolsInfo).wait();
22+
}).future<ISysInfoData>()();
23+
}
24+
}
25+
$injector.register("sysInfo", SysInfo);

0 commit comments

Comments
 (0)