Skip to content

Allow specifying compileSdk #967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/man_pages/project/testing/build-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ build android

Usage | Synopsis
---|---
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]`
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]`

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

### Options
* `--compileSdk` - Sets the Android SDK that will be used to build the project.
* `--release` - If set, produces a release build. Otherwise, produces a debug build. When set, you must also specify the `--key-store-*` options.
* `--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.
* `--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.
* `--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.
* `--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.
* `--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.

<% if(isHtml) { %>
### Attributes
`<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).<% } %>

<% if(isHtml) { %>
### Command Limitations

* When the `--release` flag is set, you must also specify all `--key-store-*` options.
Expand Down
23 changes: 17 additions & 6 deletions lib/android-tools-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,12 +120,23 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
private getCompileSdk(): IFuture<number> {
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;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ interface IOptions extends ICommonOptions {
ignoreScripts: boolean;
tnsModulesVersion: string;
staticBindings: boolean;
compileSdk: number;
}

interface IProjectFilesManager {
Expand Down
3 changes: 2 additions & 1 deletion lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down