Skip to content

Commit 9e8d71a

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Validate java version
Fixes #663
1 parent 144a28b commit 9e8d71a

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/common

Submodule common updated 1 file

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>;
@@ -35,6 +36,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
3536
private $options: IOptions,
3637
private $projectData: IProjectData,
3738
private $propertiesParser: IPropertiesParser,
39+
private $sysInfo: ISysInfo,
3840
$fs: IFileSystem) {
3941
super($fs);
4042
this._androidProjectPropertiesManagers = Object.create(null);
@@ -73,7 +75,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
7375
this.validatePackageName(this.$projectData.projectId);
7476
this.validateProjectName(this.$projectData.projectName);
7577

76-
this.checkAnt().wait() && this.checkAndroid().wait();
78+
this.checkJava().wait() && this.checkAnt().wait() && this.checkAndroid().wait();
7779
}).future<void>()();
7880
}
7981

@@ -478,6 +480,19 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
478480
return this.targetApi;
479481
}).future<string>()();
480482
}
483+
484+
private checkJava(): IFuture<void> {
485+
return (() => {
486+
try {
487+
let javaVersion = this.$sysInfo.getSysInfo().javaVer;
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.failWithoutHelp("Error executing command 'java'. 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)