8.5.3 • Published 8 months ago

nativescript v8.5.3

Weekly downloads
6,417
License
Apache-2.0
Repository
github
Last release
8 months ago

NativeScript Command-Line Interface

Master Branch Build Status. Get it using: npm install nativescript@next -g

  • Create, build, and run native apps for iOS and Android using JavaScript or TypeScript *

The NativeScript CLI lets you create, build, and deploy NativeScript-based projects on iOS and Android devices.

What is NativeScript

NativeScript is a cross-platform JavaScript framework that lets you develop native iOS and Android apps from a single code base. The framework provides JavaScript access to the native APIs, user interface, and rendering engines of iOS and Android. By using JavaScript or TypeScript, you can create one project that builds into an iOS or Android app with completely native user experience.

To learn more about NativeScript, you can check the following resources:

Back to Top

Supported Platforms

With the NativeScript CLI, you can target the following mobile platforms.

  • Android 4.2 or a later stable official release
  • iOS 7.0 or later stable official release

Back to Top

System Requirements

You can install and run the NativeScript CLI on Windows, macOS or Linux.

Installation

Install the NativeScript CLI

The NativeScript CLI is available for installing as an npm package.

In the command prompt, run the following command.

OSNode.js installed from http://nodejs.org/Node.js installed via package manager
Windowsnpm install nativescript -gnpm install nativescript -g
macOSsudo npm install nativescript -g --unsafe-permnpm install nativescript -g
Linuxsudo npm install nativescript -g --unsafe-permnpm install nativescript -g

To check if your system is configured properly, run the following command.

tns doctor

Configure Proxy Usage

If you are working with the NativeScript CLI behind a web proxy, you might need to configure your proxy settings.

  1. On your file system, locate the directory where the nativescript npm package is installed.
  2. In a text editor, open config config.json.
  3. Set USE_PROXY to true.
  4. Set PROXY_PORT.
  5. Set PROXY_HOSTNAME.

Make sure to preserve the quotation marks and commas as in the initial config.json file.

Back to Top

Quick Start

The Commands

Run tns help to view all available commands in the browser. Run tns help <Command> to view more information about a selected command in the browser. tns --help opens console help, where help information is shown in the console.

Back to Top

Create Project

To create a new cross-platform project from the default JavaScript template, run the following command.

tns create MyApp

To create a new cross-platform project from the default TypeScript or Angular template, use the template option followed by either typescript, or angular.

tns create MyApp --template typescript
tns create MyApp --template angular

Or you can simply use the shorthand tsc and ng options.

tns create MyApp --tsc
tns create MyApp --ng

With the template option you can also specify a local or a remote path to the template that you want to use to create your project. For example, if you want to use the nightly build of the default JavaScript template, run the following command.

tns create MyApp --template https://github.com/NativeScript/template-hello-world.git

To create a new cross-platform project from an existing NativeScript project, run the following command.

tns create MyApp --copy-from <Directory>

Where <Directory> is the complete path to the directory that contains your existing project. You can use any NativeScript project, created with the Telerik AppBuilder clients.

The NativeScript CLI creates a new project and sets the application identifier to org.nativescript.myapp.

The CLI places the project in a new directory in the current directory. The newly created directory has the following structure.

MyApp/
├── app
│   ├── app.css
│   ├── app.js
│   ├── bootstrap.js
│   ├── main-page.js
│   ├── main-page.xml
│   ├── App_Resources
│   │   └── ...
│   └── tns_modules
│       └── ...
└── platforms
    └── ...
  • The app directory is the development space for your application. You should modify all common and platform-specific code within this directory. When you run prepare <Platform>, the NativeScript CLI copies relevant content to the platform-specific folders for each target platform.
  • The platforms directory is created empty. When you add a target platform to your project, the NativeScript CLI creates a new subdirectory with the platform name. The subdirectory contains the ready-to-build resources of your app. When you run prepare <Platform>, the NativeScript CLI copies relevant content from the app directory to the platform-specific subdirectory for each target platform.

Back to Top

Add Platforms

After you have created your project, you can start adding target platforms to it. To be able to build your project into an application package for a selected target platform, you need to add the platform to your project first. Currently, you can target Android and iOS with your NativeScript projects.

Navigate to the directory that contains your newly created project and run the following commands.

tns platform add android
tns platform add ios

platform add creates the android and the ios subdirectories in the platforms directory. These subdirectories have the platform-specific project structure required for native development with the native SDKs for the platform.

...
platforms/
|-- android/
|-- |-- assets/
|-- |-- gen/
|-- |-- libs/
|-- |-- node_modules/
|-- |-- res/
|-- |-- src/
|-- |-- .project
|-- |-- AndroidManifest.xml
|-- |-- build.xml
|-- |-- local.properties
|-- |-- proguard-project.txt
|-- `-- project.properties
|-- ios/
|-- |-- libTNSBridge.a
|-- |-- node_modules
`-- |-- MyApp/
    `-- MyApp.xcodeproj
...

For more information about the structure of Android native projects, see Android Projects.

For more information about the structure of iOS native projects, see Code Organization in Xcode Projects.

TIP: The NativeScript team provides experimental support for the latest versions of iOS and Android. You can choose which platform runtime to use in your project by running tns platform add <platform>@<Version>To list all available versions for android, run $ npm view tns-android versionsTo list only experimental versions for android, run $ npm view tns-android dist-tags To list all available versions for ios, run $ npm view tns-ios versionsTo list only experimental versions for ios, run $ npm view tns-ios dist-tags

Back to Top

Develop Your Project

Development with NativeScript

For more information about working with NativeScript, see the following resources.

Development in app

The app directory in the root of the project is the development space for your project. Place all your common and platform-specific code in this directory. When you run prepare <Platform>, the NativeScript CLI copies relevant content to the platform-specific folders for each target platform.

In the app directory, you can use platform-specific files to provide customized functionality and design for each target platform. To indicate that a file is platform-specific, make sure that the file name is in the following format: name.ios.extension or name.android.extension. For example: main.ios.js or main.android.js.

You can develop shared functionality or design in common files. To indicate that a file is common, make sure that the file name does not contain a .android. or .ios. string.

Development in platforms

IMPORTANT: Avoid editing files located in the platforms subdirectory because the NativeScript CLI overrides such files during the prepare <Platform> using the contents of the app directory.

Modifying Configuration Files

The NativeScript CLI respects any platform configuration files placed inside app/App_Resources. Those files are respectively app/App_Resources/AndroidManifest.xml for Android and app/App_Resources/Info.plist for iOS.

Additionaly, you can modify app/App_Resources/build.xcconfig and app/App_Resources/app.gradle for adding/removing additional build properties for iOS and Android, respectively.

Modifying Entitlements File (iOS only)

To specify which Capabilities are required by your App - Maps, Push Notifications, Wallet and etc. you can add or edit the app.entitlements file placed inside app/App_Resources/iOS. When building the project, the default app/App_Resources/iOS/app.entitlements file gets merged with all Plugins entitlement files and a new yourAppName.entitlements is created in the platforms directory. The path would be app/platforms/ios/<application name>/<application name>.entitlements and will be linked in the build.xcconfig file.

You can always override the generated entitlements file, by pointing to your own entitlements file by setting the CODE_SIGN_ENTITLEMENTS property in the app/App_Resources/iOS/build.xcconfig file.

Back to Top

Prepare for Build

When you run build, the NativeScript CLI uses the resources from the platform-specific subdirectory in the platforms directory. To populate the platform-specific subdirectory with the correct application assets, you need to run prepare.

tns prepare android
tns prepare ios

prepare <Platform> takes content from app, analyzes it and copies it to the platform-specific subdirectory in platforms. This operation copies common and relevant platform-specific content that applies to the selected platform. This ensures that your Android or iOS application contain only the correct assets.

Keep in mind that prepare overrides changes made to the platform-specific subdirectory in platforms. For more information, see Development in platforms.

Back to Top

Build Your Project

After you have prepared your project, you can build it for your target mobile platforms.

tns build android
tns build ios

The NativeScript CLI calls the SDK for the selected target platform and uses it to build your app locally.

When you build for Android, the NativeScript CLI saves the application package as an APK in platforms android bin.

When you build for iOS, the NativeScript CLI will either build for a device, if there's a device attached, or for the native emulator if there are no devices attached. To trigger a native emulator build when a device is attached, set the --emulator flag.

The native emulator build is saved as an APP in platforms ios build emulator. The device build is saved as an IPA in platforms ios build device.

IMPORTANT: To build your app for an iOS device, you must configure a valid certificate and provisioning profile pair, and have that pair present on your system for code signing your application package. For more information, see iOS Code Signing - A Complete Walkthrough.

Back to Top

Deploy Your Project

You can test your work in progress on connected Android or iOS devices.

To verify that the NativeScript CLI recognizes your connected devices, run the following command.

tns device

The NativeScript CLI lists all connected physical devices and running Android Virtual Devices.

After you have listed the available devices, you can deploy your app on all devices from the selected target platform.

tns deploy android
tns deploy ios

The NativeScript CLI calls the SDK for the selected target platform and uses it to build your app locally. After the build is complete, the NativeScript CLI downloads and installs the application package on your connected devices.

On Android devices, the app runs automatically.

On iOS devices, the app does not run automatically. To run the app, tap the app icon.

IMPORTANT: To deploy your app on iOS devices, you need to configure a valid pair of certificate and provisioning profile for code signing your application package. For more information, see iOS Code Signing - A Complete Walkthrough.

Back to Top

Emulate Your Project

If you do not have any physical devices on which to test your app or if you have not configured any certificates and provisioning profiles for iOS, you can run your app in the native emulator of your target platform.

tns run android --emulator
tns run ios --emulator

This operation calls the SDK for the selected target platform, builds your app locally, launches the native device emulator for the selected target platform, and runs your project on the virtual device.

For Android, the NativeScript CLI runs your app in the earliest created virtual device or the currently running Android Virtual Device. Before running your app in the Android native emulator, make sure that you have configured at least one virtual device in the Android Virtual Device manager.

For iOS, the NativeScript CLI runs your app in the iOS Simulator.

Back to Top

Run Your Project

You can quickly run your app on connected devices, including all running Android Virtual Devices. The following command is shorthand for prepare, build, and deploy.

tns run android
tns run ios

Back to Top

Extending the CLI

The NativeScript CLI lets you extend its behavior and customize it to fit your needs by using hooks.

When you run one of the extendable commands (for example, tns build), the CLI checks for hooks and executes them. Plugins can also use hooks to control the compilation of the application package.

For more information, see the Extending the CLI document

Back to Top

Troubleshooting

If the NativeScript CLI does not behave as expected, you might be facing a configuration issue. For example, a missing JAVA path. To check if your system is configured properly for the NativeScript CLI, run the following command.

tns doctor

This command prints warnings about current configuration issues and provides basic information about how to resolve them.

If addressing the configuration issues does not resolve your problem, you can report an issue or post in the NativeScript forums.

Back to Top

Known Issues

  • You cannot synchronize changes to apps on Android 4.3 devices and on some Samsung devices using the run android command.Workaround: Upgrade to a later version of Android to be able to use the livesync command. If you need to develop for Android 4.3 devices, re-build and re-deploy your app to get your latest changes on device.

  • On macOS systems with configured firewall or web proxy, when you run a command, the operation might not release the command line and you might not be able to run other commands until you break the current operation.If you have enabled feature usage tracking for the NativeScript CLI, but you have not authenticated with the firewall or web proxy on your macOS system, the NativeScript CLI might not release the command line after you run a command. To continue working with the NativeScript CLI, you need to break the current operation by pressing Ctrl+C.Workaround: Authenticate with the firewall or web proxy.

    1. Close the terminal.
    2. Run Safari.
    3. Attempt to open a web page.
    4. Provide your authentication credentials for accessing the Internet.
    5. Run the terminal and continue working with the NativeScript CLI.

Back to Top

How to Contribute

To learn how to log a bug that you just discovered, click here.

To learn how to suggest a new feature or improvement, click here.

To learn how to contribute to the code base, click here.

Back to Top

How to Build

git clone https://github.com/NativeScript/nativescript-cli
cd nativescript-cli
git submodule update --init
npm install
grunt

To use the locally built CLI instead tns you can call PATH_TO_CLI_FOLDER/bin/tns. For example: PATH_TO_CLI_FOLDER/bin/tns run ios|android

Back to Top

License

This software is licensed under the Apache 2.0 license, quoted here.

Back to Top

npm.io

8.5.5-vision.0

10 months ago

8.5.4-dev.0

1 year ago

8.5.4-dev.1

1 year ago

8.5.3

1 year ago

8.5.1-dev.0

1 year ago

8.5.0

1 year ago

8.5.2

1 year ago

8.5.1

1 year ago

6.8.1

1 year ago

8.5.0-dev.2

1 year ago

8.5.0-dev.1

1 year ago

8.5.0-dev.0

1 year ago

8.5.0-rc.0

1 year ago

8.4.0

1 year ago

8.3.3

2 years ago

8.3.0-beta.0

2 years ago

8.3.2

2 years ago

8.3.1

2 years ago

8.3.0

2 years ago

8.2.4-alpha.1

2 years ago

8.2.4-alpha.0

2 years ago

8.2.3

2 years ago

8.2.2

2 years ago

8.2.1

2 years ago

8.2.0

2 years ago

8.1.5

2 years ago

8.1.4

3 years ago

8.1.3

3 years ago

8.1.2

3 years ago

8.1.1

3 years ago

8.1.0

3 years ago

8.0.2-alpha.0

3 years ago

8.0.2-alpha.1

3 years ago

8.0.2

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

8.0.0-alpha.4

3 years ago

8.0.0-alpha.3

3 years ago

8.0.0-alpha.1

3 years ago

8.0.0-alpha.2

3 years ago

8.0.0-alpha.0

3 years ago

7.2.1

3 years ago

7.2.0

3 years ago

7.1.2

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

7.0.12

3 years ago

7.0.11

4 years ago

7.0.9

4 years ago

7.0.10

4 years ago

7.0.9-rc.4

4 years ago

7.0.9-rc.5

4 years ago

7.0.9-rc.3

4 years ago

7.0.9-rc.2

4 years ago

7.0.9-rc.1

4 years ago

7.0.9-rc.0

4 years ago

7.0.8

4 years ago

7.0.7

4 years ago

7.0.6

4 years ago

7.0.5

4 years ago

7.0.5-rc.0

4 years ago

7.0.4

4 years ago

7.0.3

4 years ago

7.0.2

4 years ago

7.0.1

4 years ago

7.0.0

4 years ago

7.0.0-rc.4

4 years ago

7.0.0-rc.3

4 years ago

7.0.0-rc.5

4 years ago

7.0.0-rc.2

4 years ago

7.0.0-rc.1

4 years ago

7.0.0-rc.0

4 years ago

6.8.1-rc.1

4 years ago

6.8.1-rc.0

4 years ago

6.8.0

4 years ago

6.8.0-rc.4

4 years ago

6.8.0-rc.3

4 years ago

6.8.0-rc.2

4 years ago

6.8.0-rc.1

4 years ago

6.8.0-rc.0

4 years ago

6.8.0-alpha.1

4 years ago

6.8.0-alpha.0

4 years ago

6.7.8

4 years ago

6.7.7

4 years ago

6.7.6

4 years ago

6.7.5

4 years ago

6.7.4

4 years ago

6.7.3

4 years ago

6.7.2

4 years ago

6.7.1

4 years ago

6.7.0

4 years ago

6.5.1

4 years ago

6.5.0

4 years ago

6.4.1

4 years ago

6.4.0

4 years ago

6.3.3

4 years ago

6.3.2

4 years ago

6.3.1

4 years ago

6.3.0

4 years ago

6.2.2

4 years ago

6.2.1

4 years ago

6.2.0

4 years ago

6.3.0-mustang-ci

4 years ago

6.1.2

5 years ago

6.1.1

5 years ago

6.1.0

5 years ago

6.0.3

5 years ago

6.0.2

5 years ago

6.0.1

5 years ago

6.0.0

5 years ago

5.4.2

5 years ago

5.4.1

5 years ago

5.4.0

5 years ago

5.3.4

5 years ago

5.3.3

5 years ago

5.3.2

5 years ago

5.3.1

5 years ago

5.3.0

5 years ago

5.2.4

5 years ago

5.2.3

5 years ago

5.2.2

5 years ago

5.2.1

5 years ago

5.2.0

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.2.4

6 years ago

4.2.3

6 years ago

3.4.4

6 years ago

4.2.2

6 years ago

4.2.1

6 years ago

4.2.0

6 years ago

4.1.2

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.4.3

6 years ago

3.4.2

6 years ago

3.4.1

6 years ago

3.4.0

6 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.3

7 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

2.5.5

7 years ago

3.0.0

7 years ago

3.0.0-rc.2

7 years ago

2.5.4

7 years ago

3.0.0-rc.1

7 years ago

2.5.3

7 years ago

2.5.2

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.2

7 years ago

2.4.1

7 years ago

2.4.0

7 years ago

2.3.0

8 years ago

2.2.1

8 years ago

2.3.0-6532-ci

8 years ago

2.2.0

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.7.1

8 years ago

1.7.0

8 years ago

1.6.2

8 years ago

1.6.1

8 years ago

1.6.0

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.3

9 years ago

1.4.2

9 years ago

1.4.1

9 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

1.0.0-rc0

9 years ago

0.10.0

9 years ago

0.9.4

9 years ago

0.9.3

9 years ago

0.9.2

9 years ago

0.9.1

9 years ago

0.9.0

9 years ago

0.4.2

9 years ago

0.4.0

9 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.1-18

10 years ago

0.3.0

10 years ago

0.2.0-471

10 years ago

0.1.0-40

10 years ago

0.1.0-27

10 years ago

0.1.0-25

10 years ago