Skip to content

Commit 9e67966

Browse files
Merge pull request #967 from NativeScript/vladimirov/update-min-compile-sdk
Allow specifying compileSdk
2 parents ab1ed5c + 0985be6 commit 9e67966

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

docs/man_pages/project/testing/build-android.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@ build android
33

44
Usage | Synopsis
55
---|---
6-
General | `$ tns build android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings]`
6+
General | `$ tns build android [--compileSdk <API Level>] [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--static-bindings]`
77

88
Builds the project for Android and produces an APK that you can manually deploy on device or in the native emulator.
99

1010
### Options
11+
* `--compileSdk` - Sets the Android SDK that will be used to build the project.
1112
* `--release` - If set, produces a release build. Otherwise, produces a debug build. When set, you must also specify the `--key-store-*` options.
1213
* `--key-store-path` - Specifies the file path to the keystore file (P12) which you want to use to code sign your APK. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1314
* `--key-store-password` - Provides the password for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1415
* `--key-store-alias` - Provides the alias for the keystore file specified with `--key-store-path`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1516
* `--key-store-alias-password` - Provides the password for the alias specified with `--key-store-alias-password`. You can use the `--key-store-*` options along with `--release` to produce a signed release build. You need to specify all `--key-store-*` options.
1617
* `--static-bindings` - If set, generates static bindings from your JavaScript code to corresponding native Android APIs during build. This static bindings speed up app loading.
1718

18-
<% if(isHtml) { %>
19+
### Attributes
20+
`<API Level>` is a valid Android API level. For example: 22, 23.<% if(isHtml) { %> For a complete list of the Android API levels and their corresponding Android versions, click [here](http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#platform).<% } %>
21+
22+
<% if(isHtml) { %>
1923
### Command Limitations
2024

2125
* When the `--release` flag is set, you must also specify all `--key-store-*` options.

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)