Skip to content

Commit 051c6af

Browse files
Allow specifying compileSdk
Users should be able to select compileSdk. Add `--compileSdk` option and DO NOT verify it against our min required compile sdk. This implements: #927 Set min required compileSdk to 22 according to: #920
1 parent 5d83392 commit 051c6af

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

lib/android-tools-info.ts

+17-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as semver from "semver";
77
export class AndroidToolsInfo implements IAndroidToolsInfo {
88
private static ANDROID_TARGET_PREFIX = "android";
99
private static SUPPORTED_TARGETS = ["android-17", "android-18", "android-19", "android-21", "android-22", "android-23"];
10-
private static MIN_REQUIRED_COMPILE_TARGET = 21;
10+
private static MIN_REQUIRED_COMPILE_TARGET = 22;
1111
private static REQUIRED_BUILD_TOOLS_RANGE_PREFIX = ">=22";
1212
private static VERSION_REGEX = /^(\d+\.){2}\d+$/;
1313
private showWarningsAsErrors: boolean;
@@ -120,12 +120,23 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
120120
private getCompileSdk(): IFuture<number> {
121121
return ((): number => {
122122
if(!this.selectedCompileSdk) {
123-
let latestValidAndroidTarget = this.getLatestValidAndroidTarget().wait();
124-
if(latestValidAndroidTarget) {
125-
let integerVersion = this.parseAndroidSdkString(latestValidAndroidTarget);
123+
let userSpecifiedCompileSdk = this.$options.compileSdk;
124+
if(userSpecifiedCompileSdk) {
125+
let installedTargets = this.getInstalledTargets().wait();
126+
let androidCompileSdk = `${AndroidToolsInfo.ANDROID_TARGET_PREFIX}-${userSpecifiedCompileSdk}`;
127+
if(!_.contains(installedTargets, androidCompileSdk)) {
128+
this.$errors.failWithoutHelp(`You have specified '${userSpecifiedCompileSdk}' for compile sdk, but it is not installed on your system.`);
129+
}
130+
131+
this.selectedCompileSdk = userSpecifiedCompileSdk;
132+
} else {
133+
let latestValidAndroidTarget = this.getLatestValidAndroidTarget().wait();
134+
if(latestValidAndroidTarget) {
135+
let integerVersion = this.parseAndroidSdkString(latestValidAndroidTarget);
126136

127-
if(integerVersion && integerVersion >= AndroidToolsInfo.MIN_REQUIRED_COMPILE_TARGET) {
128-
this.selectedCompileSdk = integerVersion;
137+
if(integerVersion && integerVersion >= AndroidToolsInfo.MIN_REQUIRED_COMPILE_TARGET) {
138+
this.selectedCompileSdk = integerVersion;
139+
}
129140
}
130141
}
131142
}

lib/declarations.ts

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ interface IOptions extends ICommonOptions {
8181
ignoreScripts: boolean;
8282
tnsModulesVersion: string;
8383
staticBindings: boolean;
84+
compileSdk: number;
8485
}
8586

8687
interface IProjectFilesManager {

lib/options.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export class Options extends commonOptionsLibPath.OptionsBase {
2929
sdk: { type: OptionType.String },
3030
ignoreScripts: {type: OptionType.Boolean },
3131
tnsModulesVersion: { type: OptionType.String },
32-
staticBindings: {type: OptionType.Boolean}
32+
staticBindings: {type: OptionType.Boolean},
33+
compileSdk: {type: OptionType.Number }
3334
},
3435
path.join($hostInfo.isWindows ? process.env.LocalAppData : path.join(osenv.home(), ".local/share"), ".nativescript-cli"),
3536
$errors, $staticConfig);

0 commit comments

Comments
 (0)