LoginSignup
5
5

More than 5 years have passed since last update.

Cordovaによるアプリ作成メモ - 環境準備 -

Last updated at Posted at 2016-02-24

Cordovaを利用してサンプルアプリの起動確認までを行った際のメモ。

  • PC環境
    • OS X El Capitan

1.環境構築

nodeインストール

  • node version確認
terminal
$ nodebrew list

current: v5.0.0

terminal
$ nodebrew ls-remote

v5.7.0

  • node最新化
terminal
$ nodebrew install v5.7.0
$ nodebrew use v5.7.0
$ nodebrew ls
$ node -v

current: v5.7.0

cordovaインストール

  • cordova最新化
terminal
$ npm install cordova -g
$ cordova -v

6.0.0

Android SDKインストール

  • Android SDK 環境確認
.bashrc
## android sdk
export ANDROID_SDK_HOME=/Users/xxxxx/Library/Android/sdk
export PATH=$PATH:$ANDROID_SDK_HOME/tools:$ANDROID_SDK_HOME/platform-tools

パスが通ってればOK.

terminal
$ android -h
$ adb version

iOSエミュレータインストール

terminal
$ brew install ios-sim

2.プロジェクト作成

generator

terminal
$ cordova create hello com.example.hello HelloWorld -d
terminal
$ tree hello
hello
├── config.xml
├── hooks
│   └── README.md
├── platforms
├── plugins
└── www
    ├── css
    │   └── index.css
    ├── img
    │   └── logo.png
    ├── index.html
    └── js
        └── index.js

7 directories, 6 files

AndroidとiOS用のファイルを追加

terminal
$ cordova platform add ios
$ cordova platform add android
terminal
$tree hello -d
hello
├── hooks
├── platforms
│   └── android
│       ├── CordovaLib
│       │   └── src
│       │       └── org
│       │           └── apache
│       │               └── cordova
│       │                   └── engine
│       ├── assets
│       │   └── www
│       │       ├── cordova-js-src
│       │       │   ├── android
│       │       │   └── plugin
│       │       │       └── android
│       │       ├── css
│       │       ├── img
│       │       └── js
│       ├── cordova
│       │   ├── lib
│       │   │   └── builders
│       │   └── node_modules
│       │       ├── cordova-common
│       │       │   ├── node_modules
│       │       │   │   ├── bplist-parser
│       │       │   │   │   ├── node_modules
│       │       │   │   │   │   └── big-integer
│       │       │   │   │   └── test
│       │       │   │   ├── cordova-registry-mapper
│       │       │   │   │   └── tests
│       │       │   │   ├── glob
│       │       │   │   │   └── node_modules
│       │       │   │   │       ├── inflight
│       │       │   │   │       │   └── node_modules
│       │       │   │   │       │       └── wrappy
│       │       │   │   │       │           └── test
│       │       │   │   │       ├── inherits
│       │       │   │   │       ├── minimatch
│       │       │   │   │       │   └── node_modules
│       │       │   │   │       │       └── brace-expansion
│       │       │   │   │       │           └── node_modules
│       │       │   │   │       │               ├── balanced-match
│       │       │   │   │       │               │   └── test
│       │       │   │   │       │               └── concat-map
│       │       │   │   │       │                   ├── example
│       │       │   │   │       │                   └── test
│       │       │   │   │       ├── once
│       │       │   │   │       │   └── node_modules
│       │       │   │   │       │       └── wrappy
│       │       │   │   │       │           └── test
│       │       │   │   │       └── path-is-absolute
│       │       │   │   ├── osenv
│       │       │   │   │   ├── node_modules
│       │       │   │   │   │   ├── os-homedir
│       │       │   │   │   │   └── os-tmpdir
│       │       │   │   │   └── test
│       │       │   │   ├── plist
│       │       │   │   │   ├── dist
│       │       │   │   │   ├── examples
│       │       │   │   │   │   └── browser
│       │       │   │   │   ├── lib
│       │       │   │   │   └── node_modules
│       │       │   │   │       ├── base64-js
│       │       │   │   │       │   ├── bench
│       │       │   │   │       │   ├── lib
│       │       │   │   │       │   └── test
│       │       │   │   │       ├── util-deprecate
│       │       │   │   │       ├── xmlbuilder
│       │       │   │   │       │   ├── lib
│       │       │   │   │       │   └── node_modules
│       │       │   │   │       │       └── lodash
│       │       │   │   │       │           ├── array
│       │       │   │   │       │           ├── chain
│       │       │   │   │       │           ├── collection
│       │       │   │   │       │           ├── date
│       │       │   │   │       │           ├── function
│       │       │   │   │       │           ├── internal
│       │       │   │   │       │           ├── lang
│       │       │   │   │       │           ├── math
│       │       │   │   │       │           ├── number
│       │       │   │   │       │           ├── object
│       │       │   │   │       │           ├── string
│       │       │   │   │       │           └── utility
│       │       │   │   │       └── xmldom
│       │       │   │   ├── semver
│       │       │   │   │   ├── bin
│       │       │   │   │   └── test
│       │       │   │   ├── underscore
│       │       │   │   └── unorm
│       │       │   │       └── lib
│       │       │   └── src
│       │       │       ├── ConfigChanges
│       │       │       ├── ConfigParser
│       │       │       ├── CordovaError
│       │       │       ├── PluginInfo
│       │       │       └── util
│       │       ├── elementtree
│       │       │   ├── lib
│       │       │   │   └── parsers
│       │       │   ├── node_modules
│       │       │   │   └── sax
│       │       │   │       ├── examples
│       │       │   │       ├── lib
│       │       │   │       └── test
│       │       │   └── tests
│       │       │       └── data
│       │       ├── nopt
│       │       │   ├── bin
│       │       │   ├── examples
│       │       │   ├── lib
│       │       │   ├── node_modules
│       │       │   │   └── abbrev
│       │       │   └── test
│       │       ├── properties-parser
│       │       │   └── test
│       │       ├── q
│       │       └── shelljs
│       │           ├── bin
│       │           ├── scripts
│       │           └── src
│       ├── libs
│       ├── platform_www
│       │   ├── cordova-js-src
│       │   │   ├── android
│       │   │   └── plugin
│       │   │       └── android
│       │   └── plugins
│       │       └── cordova-plugin-whitelist
│       ├── res
│       │   ├── drawable-hdpi
│       │   ├── drawable-land-hdpi
│       │   ├── drawable-land-ldpi
│       │   ├── drawable-land-mdpi
│       │   ├── drawable-land-xhdpi
│       │   ├── drawable-ldpi
│       │   ├── drawable-mdpi
│       │   ├── drawable-port-hdpi
│       │   ├── drawable-port-ldpi
│       │   ├── drawable-port-mdpi
│       │   ├── drawable-port-xhdpi
│       │   ├── drawable-xhdpi
│       │   ├── values
│       │   └── xml
│       └── src
│           ├── com
│           │   └── example
│           │       └── hello
│           └── org
│               └── apache
│                   └── cordova
│                       └── whitelist
├── plugins
│   └── cordova-plugin-whitelist
│       ├── doc
│       │   ├── de
│       │   ├── es
│       │   ├── fr
│       │   ├── it
│       │   ├── ja
│       │   ├── ko
│       │   ├── pl
│       │   └── zh
│       └── src
│           └── android
└── www
    ├── css
    ├── img
    └── js

168 directories

対象プラットフォーム確認

terminal
$cordova platform ls

Installed platforms: android 5.1.0
Available platforms: amazon-fireos, blackberry10, >browser, firefoxos, ios, osx, webos

メモ

対象プラットフォーム削除

terminal
$ cordova platform remove ios

プロジェクト構成

dir description
hello/
├ .cordova -> cordovaプロジェクト設定ファイルが格納されている
├ www -> HTML5リソースやアプリ設定に関するファイル
├ platforms -> 各プラットフォーム特有のプロジェクトファイルが記述されている
├ merges -> 各プラットフォーム特有のリソース
wwwディレクトリがプラットフォームごとにコンパイルされる際にマージされる
└ plugins -> Cordovaプラグインが格納されている

3.エミュレータ起動

Androidエミュレータ

terminal
$ cordova emulate android -d

AVDとのバージョンを合わせておくこと

terminal
cat ./hello/platforms/android/AndroidManifest.xml
※ build.gradleはManifestから情報取得

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />

iOSエミュレータ

terminal
$ cordova emulate ios -d

ブラウザエミュレータ

terminal
$ cordova serve android

Static file server running on: http://localhost:8000 (CTRL + C to shut down)

4.実機起動

Android端末

terminal
$ cordova run android

参考URL

5
5
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
5
5