diff --git a/lib/android-tools-info.ts b/lib/android-tools-info.ts index f7bc8359e6..da2ef0b14f 100644 --- a/lib/android-tools-info.ts +++ b/lib/android-tools-info.ts @@ -7,7 +7,7 @@ import * as semver from "semver"; export class AndroidToolsInfo implements IAndroidToolsInfo { private static ANDROID_TARGET_PREFIX = "android"; private static SUPPORTED_TARGETS = ["android-17", "android-18", "android-19", "android-21", "android-22", "android-23"]; - private static MIN_REQUIRED_COMPILE_TARGET = 21; + private static MIN_REQUIRED_COMPILE_TARGET = 22; private static REQUIRED_BUILD_TOOLS_RANGE_PREFIX = ">=22"; private static VERSION_REGEX = /^(\d+\.){2}\d+$/; private showWarningsAsErrors: boolean; @@ -120,12 +120,23 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { private getCompileSdk(): IFuture { return ((): number => { if(!this.selectedCompileSdk) { - let latestValidAndroidTarget = this.getLatestValidAndroidTarget().wait(); - if(latestValidAndroidTarget) { - let integerVersion = this.parseAndroidSdkString(latestValidAndroidTarget); + let userSpecifiedCompileSdk = this.$options.compileSdk; + if(userSpecifiedCompileSdk) { + let installedTargets = this.getInstalledTargets().wait(); + let androidCompileSdk = `${AndroidToolsInfo.ANDROID_TARGET_PREFIX}-${userSpecifiedCompileSdk}`; + if(!_.contains(installedTargets, androidCompileSdk)) { + this.$errors.failWithoutHelp(`You have specified '${userSpecifiedCompileSdk}' for compile sdk, but it is not installed on your system.`); + } + + this.selectedCompileSdk = userSpecifiedCompileSdk; + } else { + let latestValidAndroidTarget = this.getLatestValidAndroidTarget().wait(); + if(latestValidAndroidTarget) { + let integerVersion = this.parseAndroidSdkString(latestValidAndroidTarget); - if(integerVersion && integerVersion >= AndroidToolsInfo.MIN_REQUIRED_COMPILE_TARGET) { - this.selectedCompileSdk = integerVersion; + if(integerVersion && integerVersion >= AndroidToolsInfo.MIN_REQUIRED_COMPILE_TARGET) { + this.selectedCompileSdk = integerVersion; + } } } } diff --git a/lib/declarations.ts b/lib/declarations.ts index 756208bc43..3a59e4b2d5 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -81,6 +81,7 @@ interface IOptions extends ICommonOptions { ignoreScripts: boolean; tnsModulesVersion: string; staticBindings: boolean; + compileSdk: number; } interface IProjectFilesManager { diff --git a/lib/options.ts b/lib/options.ts index 6a6fd53138..aef6e40ab9 100644 --- a/lib/options.ts +++ b/lib/options.ts @@ -29,7 +29,8 @@ export class Options extends commonOptionsLibPath.OptionsBase { sdk: { type: OptionType.String }, ignoreScripts: {type: OptionType.Boolean }, tnsModulesVersion: { type: OptionType.String }, - staticBindings: {type: OptionType.Boolean} + staticBindings: {type: OptionType.Boolean}, + compileSdk: {type: OptionType.Number } }, path.join($hostInfo.isWindows ? process.env.LocalAppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"), $errors, $staticConfig);