Skip to content

Fix tns doctor command #1298

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 1 commit into from
Dec 3, 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: 13 additions & 7 deletions lib/android-tools-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
private $logger: ILogger,
private $options: IOptions) {}

public getPathToAndroidExecutable(): IFuture<string> {
public getPathToAndroidExecutable(options?: {showWarningsAsErrors: boolean}): IFuture<string> {
return ((): string => {
if(options) {
this.showWarningsAsErrors = options.showWarningsAsErrors;
}
if (!this.pathToAndroidExecutable) {
if(this.validateAndroidHomeEnvVariable(this.androidHome).wait()) {
let androidPath = path.join(this.androidHome, "tools", this.androidExecutableName);
if(!this.trySetAndroidPath(androidPath).wait() && !this.trySetAndroidPath(this.androidExecutableName).wait()) {
this.printMessage(`Unable to find "${this.androidExecutableName}" executable file. Make sure you have set ANDROID_HOME environment variable correctly.`);
}
} else {
this.printMessage("ANDROID_HOME environment variable is not set correctly.");
this.$logger.trace("ANDROID_HOME environment variable is not set correctly.");
}
}

Expand Down Expand Up @@ -338,11 +341,14 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
return (() => {
if (!this.installedTargetsCache) {
try {
let result = this.$childProcess.spawnFromEvent(this.getPathToAndroidExecutable().wait(), ["list", "targets"], "close", {}, {throwError: false}).wait();
if(result.stdout) {
this.$logger.trace(result.stdout);
this.installedTargetsCache = [];
result.stdout.replace(/id: \d+ or "(.+)"/g, (m:string, p1:string) => (this.installedTargetsCache.push(p1), m));
let pathToAndroidExecutable = this.getPathToAndroidExecutable().wait();
if(pathToAndroidExecutable) {
let result = this.$childProcess.spawnFromEvent(pathToAndroidExecutable, ["list", "targets"], "close", {}, {throwError: false}).wait();
if(result && result.stdout) {
this.$logger.trace(result.stdout);
this.installedTargetsCache = [];
result.stdout.replace(/id: \d+ or "(.+)"/g, (m:string, p1:string) => (this.installedTargetsCache.push(p1), m));
}
}
} catch(err) {
this.$logger.trace("Unable to get Android targets. Error is: " + err);
Expand Down
2 changes: 1 addition & 1 deletion lib/common
Submodule common updated 1 files
+11 −5 sys-info-base.ts
3 changes: 2 additions & 1 deletion lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ 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.
* @param {any} options Defines if the warning messages should treated as error.
* @return {string} Path to the `android` executable.
*/
getPathToAndroidExecutable(): IFuture<string>;
getPathToAndroidExecutable(options?: {showWarningsAsErrors: boolean}): IFuture<string>;

/**
* Gets the path to `adb` executable from ANDROID_HOME. It should be `$ANDROID_HOME/platform-tools/adb` in case it exists.
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 @@ -79,7 +79,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
this.validateProjectName(this.$projectData.projectName);

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