Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 525160e

Browse files
Fix adb related commands when path has spaces
When CLI is installed in directory, which has space (or the path above this dir has spaces) and android-sdk is not installed, we are trying to execute adb from our resources. This is failing due to missing `"` in our commands. Fixes NativeScript/nativescript-cli#470
1 parent 6546f12 commit 525160e

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

mobile/android/android-emulator-services.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,27 @@ class AndroidEmulatorServices implements Mobile.IEmulatorPlatformServices {
5555
}
5656

5757
private checkAndroidSDKConfiguration(): IFuture<void> {
58-
return this.$childProcess.tryExecuteApplication('emulator', ['-help'], "exit", AndroidEmulatorServices.MISSING_SDK_MESSAGE);
58+
return (() => {
59+
try {
60+
this.$childProcess.tryExecuteApplication('emulator', ['-help'], "exit", AndroidEmulatorServices.MISSING_SDK_MESSAGE).wait();
61+
} catch (err) {
62+
this.$logger.trace(`Error while checking Android SDK configuration: ${err}`);
63+
this.$errors.failWithoutHelp("Android SDK is not configured properly. Make sure you have added tools and platform-tools to your PATH environment variable.");
64+
}
65+
}).future<void>()();
66+
return
5967
}
6068

6169
private checkGenymotionConfiguration(): IFuture<void> {
62-
let condition = (childProcess: any) => childProcess.stderr && !_.startsWith(childProcess.stderr, "Usage:");
63-
return this.$childProcess.tryExecuteApplication("player", [], "exit", AndroidEmulatorServices.MISSING_GENYMOTION_MESSAGE, condition);
70+
return (() => {
71+
try {
72+
let condition = (childProcess: any) => childProcess.stderr && !_.startsWith(childProcess.stderr, "Usage:");
73+
this.$childProcess.tryExecuteApplication("player", [], "exit", AndroidEmulatorServices.MISSING_GENYMOTION_MESSAGE, condition).wait();
74+
} catch(err) {
75+
this.$logger.trace(`Error while checking Genymotion configuration: ${err}`);
76+
this.$errors.failWithoutHelp("Genymotion is not configured properly. Make sure you have added its installation directory to your PATH environment variable.");
77+
}
78+
}).future<void>()();
6479
}
6580

6681
public checkAvailability(): IFuture<void> {

mobile/mobile-core/device-discovery.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"use strict";
33

44
import ref = require("ref");
5-
import util = require("util");
65
import os = require("os");
76
import path = require("path");
87
import IOSDevice = require("./../ios/ios-device");
@@ -187,7 +186,7 @@ export class AndroidDeviceDiscovery extends DeviceDiscovery {
187186
return(()=> {
188187
this.ensureAdbServerStarted().wait();
189188

190-
let requestAllDevicesCommand = `${this.$staticConfig.getAdbFilePath().wait()} devices`;
189+
let requestAllDevicesCommand = `"${this.$staticConfig.getAdbFilePath().wait()}" devices`;
191190
let result = this.$childProcess.exec(requestAllDevicesCommand).wait();
192191

193192
let devices = result.toString().split(os.EOL).slice(1)
@@ -205,7 +204,7 @@ export class AndroidDeviceDiscovery extends DeviceDiscovery {
205204
}
206205

207206
private ensureAdbServerStarted(): IFuture<void> {
208-
let startAdbServerCommand = `${this.$staticConfig.getAdbFilePath().wait()} start-server`;
207+
let startAdbServerCommand = `"${this.$staticConfig.getAdbFilePath().wait()}" start-server`;
209208
return this.$childProcess.exec(startAdbServerCommand);
210209
}
211210
}

0 commit comments

Comments
 (0)