Skip to content

Commit 2715178

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Validate java version
Fixes #663
1 parent 8caba2c commit 2715178

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/services/android-project-service.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import constants = require("../constants");
88
import helpers = require("../common/helpers");
99
import fs = require("fs");
1010
import os = require("os");
11+
import semver = require("semver");
1112

1213
import androidProjectPropertiesManagerLib = require("./android-project-properties-manager");
1314
import projectServiceBaseLib = require("./platform-project-service-base");
@@ -21,7 +22,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
2122
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v";
2223
private static ANDROID_PLATFORM_NAME = "android";
2324
private static LIBS_FOLDER_NAME = "libs";
24-
25+
private static MIN_JAVA_VERSION = "1.7.0";
2526

2627
private targetApi: string;
2728
private _androidProjectPropertiesManagers: IDictionary<IAndroidProjectPropertiesManager>;
@@ -73,7 +74,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
7374
this.validatePackageName(this.$projectData.projectId);
7475
this.validateProjectName(this.$projectData.projectName);
7576

76-
this.checkAnt().wait() && this.checkAndroid().wait();
77+
this.checkJava().wait() && this.checkAnt().wait() && this.checkAndroid().wait();
7778
}).future<void>()();
7879
}
7980

@@ -478,6 +479,20 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
478479
return this.targetApi;
479480
}).future<string>()();
480481
}
482+
483+
private checkJava(): IFuture<void> {
484+
return (() => {
485+
try {
486+
let output = this.$childProcess.exec("javac -version").wait();
487+
let javaVersion = /^javac ((?:\d+\.)+(?:\d+))/i.exec(output)[1];
488+
if(semver.lt(javaVersion, AndroidProjectService.MIN_JAVA_VERSION)) {
489+
this.$errors.failWithoutHelp(`Your current java version is ${javaVersion}. NativeScript CLI needs at least ${AndroidProjectService.MIN_JAVA_VERSION} version to work correctly. Ensure that you have at least ${AndroidProjectService.MIN_JAVA_VERSION} java version installed and try again.`);
490+
}
491+
} catch(error) {
492+
this.$errors.fail("Error executing command 'javac'. Make sure you have java installed and added to your PATH.");
493+
}
494+
}).future<void>()();
495+
}
481496

482497
private checkAnt(): IFuture<void> {
483498
return (() => {

0 commit comments

Comments
 (0)