LoginSignup
2
2

More than 5 years have passed since last update.

NativeScriptのGetting Startedを試してみる(1

Last updated at Posted at 2015-03-24

http://docs.nativescript.org/getting-started
では前回に引き続いて、
JavascriptでAndoroid,iOS,Windows Phoneのアプリが書けるNativeScriptのGetting Startedを試していきます。今回はサンプル画面の表示までです。

Getting Started

  • NativeScriptはプラットフォームに依存したセットアップとスキルの複雑さを取り除く
  • TypeScriptでもよい
  • XML, javascript, CSSの知識が必要
  • Objective-C, Javaの知識は不要

1. Choose your tools and set up your system.

開発環境の準備です。
私はWindowsですが、その場合Androidしか実行できないようです。iOSの実行にはOS X環境が必要のようです。Windows Phoneの話が書いてありませんがとりあえず置いておきます。
ローカルで開発しようと思いますので、まずCLIのインストールです。

Set Up the NativeScript CLI on Windows

http://docs.nativescript.org/setup/ns-cli-setup/ns-setup-win.html
必要なものは以下です。

原文ではChocolateyの使用を推奨してましたが、うまくいかなかったので手動でいれました。
Android SDKのインストールには管理者権限が必要です。また現状Lolipop(API22)に対応してない?ため、4.4(API19)のSDK Platform をマネージャーからインストールしました。
最後に
npm i -g nativescript
で本体をインストールして終わりです。

Hello World from the NativeScript CLI

http://docs.nativescript.org/hello-world/hello-world-ns-cli.html
では本番です。定番のハローワールドです。まずサンプル画面の表示に挑戦します。

Create New Project

コマンドtns create hello-worldでプロジェクトを作成します。初回のみ使用方法の統計情報を送るか聞かれるのでお好きにどうぞ。

C:\workspace\NativeScript>tns create hello-world
...
Project hello-world was successfully created

C:\workspace\NativeScript>

つぎに使用するプラットフォームを追加します。今回はandroidだけです。うまくいかない人は管理者権限とAPI19(Android4.4.2)のSDKをインストールしているか確認してください。

C:\workspace\NativeScript>cd hello-world

C:\workspace\NativeScript\hello-world>tns platform add android
Unable to find adb in PATH. Default one from NativeScript resources will be used
.
Copying template files...
Updated project.properties
Updated local.properties
Added file C:\workspace\NativeScript\hello-world\platforms\android\build.xml
Added file C:\workspace\NativeScript\hello-world\platforms\android\proguard-proj
ect.txt
Project successfully created.

C:\workspace\NativeScript\hello-world>

つぎにサンプルをエミュレータで表示します。コマンドはtns run android --emulatorです。いろいろ出力されます。成功したならデモ画面が表示されるはずです。私は失敗しました。

どうもエミュレータが起動に失敗しているようです。AVD Managerでエミュレータを作成して起動しても失敗しました。エラーはemulator: ERROR: x86 emulation currently requires hardware acceleration! 。調べた結果、以下のサイトにたどり着きました。

以下のサイトから入手できるソフトウェアをインストールする必要があったようです。
https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager

失敗するかたはまずAVD Managerからエミュレータが起動するか確認してください。AVD Managerで起動に成功すれば、デモの実行も成功するはずです。

区切りがいいので一端切ります。次回

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2