Skip to content

Commit 85c4ecf

Browse files
Merge pull request #1298 from NativeScript/vladimirov/fix-android-home-log-trace
Fix tns doctor command
2 parents a8a99ab + 4834e80 commit 85c4ecf

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

lib/android-tools-info.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
3838
private $logger: ILogger,
3939
private $options: IOptions) {}
4040

41-
public getPathToAndroidExecutable(): IFuture<string> {
41+
public getPathToAndroidExecutable(options?: {showWarningsAsErrors: boolean}): IFuture<string> {
4242
return ((): string => {
43+
if(options) {
44+
this.showWarningsAsErrors = options.showWarningsAsErrors;
45+
}
4346
if (!this.pathToAndroidExecutable) {
4447
if(this.validateAndroidHomeEnvVariable(this.androidHome).wait()) {
4548
let androidPath = path.join(this.androidHome, "tools", this.androidExecutableName);
4649
if(!this.trySetAndroidPath(androidPath).wait() && !this.trySetAndroidPath(this.androidExecutableName).wait()) {
4750
this.printMessage(`Unable to find "${this.androidExecutableName}" executable file. Make sure you have set ANDROID_HOME environment variable correctly.`);
4851
}
4952
} else {
50-
this.printMessage("ANDROID_HOME environment variable is not set correctly.");
53+
this.$logger.trace("ANDROID_HOME environment variable is not set correctly.");
5154
}
5255
}
5356

@@ -338,11 +341,14 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
338341
return (() => {
339342
if (!this.installedTargetsCache) {
340343
try {
341-
let result = this.$childProcess.spawnFromEvent(this.getPathToAndroidExecutable().wait(), ["list", "targets"], "close", {}, {throwError: false}).wait();
342-
if(result.stdout) {
343-
this.$logger.trace(result.stdout);
344-
this.installedTargetsCache = [];
345-
result.stdout.replace(/id: \d+ or "(.+)"/g, (m:string, p1:string) => (this.installedTargetsCache.push(p1), m));
344+
let pathToAndroidExecutable = this.getPathToAndroidExecutable().wait();
345+
if(pathToAndroidExecutable) {
346+
let result = this.$childProcess.spawnFromEvent(pathToAndroidExecutable, ["list", "targets"], "close", {}, {throwError: false}).wait();
347+
if(result && result.stdout) {
348+
this.$logger.trace(result.stdout);
349+
this.installedTargetsCache = [];
350+
result.stdout.replace(/id: \d+ or "(.+)"/g, (m:string, p1:string) => (this.installedTargetsCache.push(p1), m));
351+
}
346352
}
347353
} catch(err) {
348354
this.$logger.trace("Unable to get Android targets. Error is: " + err);

lib/common

lib/declarations.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ interface IAndroidToolsInfo {
126126
/**
127127
* Returns the path to `android` executable. It should be `$ANDROID_HOME/tools/android`.
128128
* In case ANDROID_HOME is not defined, check if `android` is part of $PATH.
129+
* @param {any} options Defines if the warning messages should treated as error.
129130
* @return {string} Path to the `android` executable.
130131
*/
131-
getPathToAndroidExecutable(): IFuture<string>;
132+
getPathToAndroidExecutable(options?: {showWarningsAsErrors: boolean}): IFuture<string>;
132133

133134
/**
134135
* Gets the path to `adb` executable from ANDROID_HOME. It should be `$ANDROID_HOME/platform-tools/adb` in case it exists.

lib/services/android-project-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
7979
this.validateProjectName(this.$projectData.projectName);
8080

8181
// this call will fail in case `android` is not set correctly.
82-
this.$androidToolsInfo.getPathToAndroidExecutable().wait();
82+
this.$androidToolsInfo.getPathToAndroidExecutable({showWarningsAsErrors: true}).wait();
8383
this.$androidToolsInfo.validateJavacVersion(this.$sysInfo.getSysInfo(path.join(__dirname, "..", "..", "package.json")).wait().javacVersion, {showWarningsAsErrors: true}).wait();
8484
}).future<void>()();
8585
}

0 commit comments

Comments
 (0)