ページ

2014年10月21日火曜日

PhoneGapを使用する 1

クロスプラットフォームで開発可能なPhoneGapを使ってみる。

・インストール
以下公式サイトに載っているようにnpmを使ってインストール。
http://phonegap.com/install/

実際にインストールしてみるも・・失敗orz
https://github.com/npm/npm/issues/2701
どうやらバージョンが古い?かも、ということで最新のNode.js / npmをインストールして
再チャレンジ!!

今度はうまくいきました^^

実際にプロジェクトを作成し、iOSアプリを作ってみる。
$ phonegap create hello-app
[phonegap] create called with the options /Users/{ユーザ名}/Documents/develop/phonegap/hello-app com.phonegap.helloworld HelloWorld
[phonegap] Customizing default config.xml file
[phonegap] created project at /Users/{ユーザ名}/Documents/develop/phonegap/hello-app
$ cd hello-app/
$ phonegap run ios
[phonegap] detecting iOS SDK environment...
[phonegap] using the local environment
[phonegap] adding the iOS platform...
[phonegap] compiling iOS...
Build settings from command line:
    ARCHS = i386
    CONFIGURATION_BUILD_DIR = /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/ios/build/emulator
    SDKROOT = iphonesimulator8.0
    VALID_ARCHS = i386

=== BUILD TARGET CordovaLib OF PROJECT CordovaLib WITH CONFIGURATION Debug ===

Check dependencies
この後もずらっとビルドされ、hello-app/platforms/ios配下にxcodeのプロジェクトが作成される。
















HelloWorld.xcodeprojをxcodeで開いて、シュミレータで確認してみる。
























ちゃんと実行できる事を確認。今度は同じアプリをAndroidで実行してみる。
Androidの場合は色々環境がなってないと怒られました・・・
環境変数にANDROID_HOMEが設定されていない、androidコマンドや、antコマンドが使えない!!など、.bash_profileにもろもろ追加して再実行。
$ phonegap build android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.phonegap.helloworld
Name: HelloWorld
Android target: android-19
Copying template files...
Project successfully created.
cp: no such file or directory: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/icon.png

[phonegap] compiling Android...
cp: no such file or directory: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/icon.png

Buildfile: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/build.xml

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 23.0.2
 [checkenv] Installed at /Applications/Android Studio.app/sdk

-setup:
     [echo] Project Name: HelloWorld
  [gettype] Project Type: Application

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 20.0.0
     [echo] Resolving Build Target for HelloWorld...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/rsObj
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/rsLibs
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-gen
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/classes
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloWorld...
[dependency] Library dependencies:
[dependency] 
[dependency] ------------------
[dependency] Ordered libraries:
[dependency] 
[dependency] ------------------
     [echo] ----------
     [echo] Building Libraries with 'debug'...

nodeps:

-set-mode-check:

-set-debug-files:

-check-env:
 [checkenv] Android SDK Tools Revision 23.0.2
 [checkenv] Installed at /Applications/Android Studio.app/sdk

-setup:
     [echo] Project Name: HelloWorld
  [gettype] Project Type: Android Library

-set-debug-mode:

-debug-obfuscation-check:

-pre-build:

-build-setup:
[getbuildtools] Using latest Build Tools: 20.0.0
     [echo] Resolving Build Target for HelloWorld...
[gettarget] Project Target:   Android 4.4.2
[gettarget] API level:        19
     [echo] ----------
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/res
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/libs
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/res
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/rsObj
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/rsLibs
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-gen
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes
    [mkdir] Created dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/dexedLibs
     [echo] ----------
     [echo] Resolving Dependencies for HelloWorld...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency] 
[dependency] ------------------

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:

-compile:
    [javac] Compiling 93 source files to /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes
    [javac] 注意:一部の入力ファイルは非推奨のAPIを使用またはオーバーライドしています。
    [javac] 注意:詳細は、-Xlint:deprecationオプションを指定して再コンパイルしてください。
     [echo] Creating library output jar file...
      [jar] Building jar: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes.jar

-post-compile:

-obfuscate:

-dex:
     [echo] Library project: do not convert bytecode...

-crunch:
   [crunch] Crunching PNG Files in source dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/res
   [crunch] To destination dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/res
   [crunch] Crunched 0 PNG files to update cache

-package-resources:
     [echo] Library project: do not package resources...

-package:
     [echo] Library project: do not package apk...

-post-package:

-do-debug:
     [echo] Library project: do not create apk...
[propertyfile] Creating new property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/build.prop

-post-build:

debug:

-code-gen:
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...
     [echo] ----------
     [echo] Handling BuildConfig class...
[buildconfig] Generating BuildConfig class.

-pre-compile:
     [echo] Set jars path to: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes.jar

-compile:
    [javac] Compiling 3 source files to /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/classes

-post-compile:

-obfuscate:

-dex:
      [dex] input: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/classes
      [dex] input: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes.jar
      [dex] Pre-Dexing /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build/classes.jar -> classes-0892cf444a5a04f0045d76451949d362.jar
      [dex] Converting compiled files and external libraries into /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/classes.dex...
       [dx] Merged dex A (7 defs/2.2KiB) with dex B (209 defs/317.1KiB). Result is 216 defs/389.0KiB. Took 0.4s

-crunch:
   [crunch] Crunching PNG Files in source dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res
   [crunch] To destination dir: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-hdpi/icon.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-hdpi/icon.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-hdpi/icon.png: 52% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-land-hdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-hdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-hdpi/screen.png: 97% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-land-ldpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-ldpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-ldpi/screen.png: 96% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-land-mdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-mdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-mdpi/screen.png: 97% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-land-xhdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-xhdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-land-xhdpi/screen.png: 99% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-port-hdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-hdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-hdpi/screen.png: 97% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-port-ldpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-ldpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-ldpi/screen.png: 97% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-port-mdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-mdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-mdpi/screen.png: 99% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable-port-xhdpi/screen.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-xhdpi/screen.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable-port-xhdpi/screen.png: 99% size of source)
   [crunch] Processing image to cache: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/res/drawable/icon.png => /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable/icon.png
   [crunch]   (processed image to cache entry /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/res/drawable/icon.png: 53% size of source)
   [crunch] Crunched 10 PNG files to update cache

-package-resources:
     [aapt] Creating full resource package...
     [aapt]     (skipping file '.pgbomit' due to ANDROID_AAPT_IGNORE pattern '.*')

-package:
[apkbuilder] Current build type is different than previous build: forced apkbuilder run.
[apkbuilder] Creating HelloWorld-debug-unaligned.apk and signing it with a debug key...

-post-package:

-do-debug:
 [zipalign] Running zip align on final apk...
     [echo] Debug Package: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/HelloWorld-debug.apk
[propertyfile] Creating new property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/build.prop

-post-build:
     [move] Moving 1 file to /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build
     [move] Moving 1 file to /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/CordovaLib/ant-build

debug:

BUILD SUCCESSFUL
Total time: 42 seconds
Using apk: /Users/{ユーザ名}/Documents/develop/phonegap/hello-app/platforms/android/ant-build/HelloWorld-debug-unaligned.apk
[phonegap] successfully compiled Android app
今度は無事に実行できました。

apkファイルはというと、hello-app/platforms/android/ant-build配下にあります。
















実際にAndroid端末にインストールして確認。
























ちゃんと両方で確認できました^^
Bluetoothも触れるっぽい!!
https://github.com/don/BluetoothSerial

0 件のコメント:

コメントを投稿