Skip to content

Commit 007fa48

Browse files
author
Vladimir Enchev
committed
Related to #1296
Try/Catch gradle spawn and suggest platform add/remove in case of error
1 parent 27c888e commit 007fa48

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/services/android-project-service.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
256256
}
257257

258258
public buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void> {
259+
let platformRemoveMessage = "Run `tns platform remove android && tns platform add android` to switch to Gradle and try again.";
259260
return (() => {
260261
if (this.canUseGradle().wait()) {
261262
this.$androidToolsInfo.validateInfo({ showWarningsAsErrors: true, validateTargetSdk: true }).wait();
@@ -287,10 +288,14 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
287288
if (this.$hostInfo.isWindows) {
288289
gradleBin += ".bat"; // cmd command line parsing rules are weird. Avoid issues with quotes. See https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib/builders/GradleBuilder.js for another approach
289290
}
290-
this.spawn(gradleBin, buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait();
291+
292+
try {
293+
this.spawn(gradleBin, buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait();
294+
} catch (ex) {
295+
this.$errors.failWithoutHelp("Gradle build failed." + EOL + platformRemoveMessage);
296+
}
291297
} else {
292-
this.$errors.failWithoutHelp("Cannot complete build because this project is ANT-based." + EOL +
293-
"Run `tns platform remove android && tns platform add android` to switch to Gradle and try again.");
298+
this.$errors.failWithoutHelp("Cannot complete build because this project is ANT-based." + EOL + platformRemoveMessage);
294299
}
295300
}).future<void>()();
296301
}

0 commit comments

Comments
 (0)