📺 "One project. One language. Three apps." Learn more in our upcoming code sharing webinar!

NativeScript Core

tns run android

Description

Runs your project on a connected Android device or Android emulator, if configured. This is shorthand for prepare, build and deploy. While your app is running, prints the output from the application in the console and watches for changes in your code. Once a change is detected, it synchronizes the change with all selected devices and restarts/refreshes the application.

To enable Hot Module Replacement (HMR) in Angular projects, follow the steps outlined in this wiki: https://github.com/NativeScript/nativescript-angular/wiki/HMR.

Commands

Usage Synopsis
Run on all connected devices and running emulators $ tns run android [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]
Run on a selected connected device or running emulator. Will start emulator with specified Device Identifier, if not already running. $ tns run android --device <Device ID> [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]
Start a default emulator if none are running, or run application on all connected emulators. $ tns run android --emulator [--key-store-path <File Path> --key-store-password <Password> --key-store-alias <Name> --key-store-alias-password <Password>] [--release] [--justlaunch] [--bundle [<value>] [--env.*]]

Options

  • --device - Specifies a connected device or emulator to start and run the app. <Device ID> is the index or Device Identifier of the target device as listed by the $ tns device android --available-devices command.
  • --emulator - If set, runs the app in all available and configured Android emulators. It will start an emulator if none are already running.
  • --justlaunch - If set, does not print the application output in the console.
  • --clean - If set, forces the complete rebuild of the native application.
  • --no-watch - If set, changes in your code will not be reflected during the execution of this command.
  • --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.
  • --bundle - Specifies that the webpack bundler will be used to bundle the application.
  • --hmr - (Beta) Enables the hot module replacement (HMR) feature. HMR depends on webpack and adding the --hmr flag to the command will automatically enable the --bundle option as well. The HMR feature is currently in Beta. For more information about the current development state and any known issues, please check the relevant GitHub issue: https://github.com/NativeScript/NativeScript/issues/6398.
  • --env.* - Specifies additional flags that the bundler may process. May be passed multiple times. For example: --env.uglify --env.snapshot.
  • --syncAllFiles - Watches all production dependencies inside node_modules for changes. Triggers project rebuild if necessary!

Note: Hot Module Replacement (HMR) is currently in Beta. For more information about the current development state and any known issues, please check the relevant GitHub issue: https://github.com/NativeScript/NativeScript/issues/6398.

Prerequisites

Before running your app in the Android emulator from the Android SDK, verify that your system meets the following requirements.

  • Verify that you have installed the Android SDK.
  • Verify that you have added the following Android SDK directories to the PATH environment variable:
    • platform-tools
    • tools

Command Limitations

  • You cannot use the --device and --emulator options simultaneously.
  • When the --release flag is set, you must also specify all --key-store-* options.
Command Description
build android Builds the project for Android and produces an APK that you can manually deploy on device or in the native emulator.
build ios Builds the project for iOS and produces an APP or IPA that you can manually deploy in the iOS Simulator or on device, respectively.
build Builds the project for the selected target platform and produces an application package that you can manually deploy on device or in the native emulator.
debug android Debugs your project on a connected Android device or in a native emulator.
debug ios Debugs your project on a connected iOS device or in a native emulator.
debug Debugs your project on a connected device or in a native emulator.
deploy Builds and deploys the project to a connected physical or virtual device.
run ios Runs your project on a connected iOS device or in the iOS Simulator, if configured.
run Runs your project on a connected device or in the native emulator for the selected platform.
test init Configures your project for unit testing with a selected framework.
test android Runs the tests in your project on Android devices or native emulators.
test ios Runs the tests in your project on iOS devices or the iOS Simulator.