一。 安装 PhoneGap
http://phonegap.com/install/
官方教程说,首先需要安装 node.js ,幸好bob早就有了
然后在命令行里运行
C:\> npm install -g phonegap
遇到问题:
npm http GET https://registry.npmjs.org/shelljs/0.1.4
npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.
到说,找不到git命令 。 其实bob 早已经安装了git bash .
于是打开git bash 运行npm install -g phonegap, 经过一小长段时间(超极本运行了10分钟约, 当然了主要是网速……) , 终于完成 (中间好像有报一个git clone cordova的返回错误,没有理会它)
http://phonegap.com/install/
官方教程说,首先需要安装 node.js ,幸好bob早就有了
然后在命令行里运行
C:\> npm install -g phonegap
遇到问题:
npm http GET https://registry.npmjs.org/shelljs/0.1.4
npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.
到说,找不到git命令 。 其实bob 早已经安装了git bash .
于是打开git bash 运行npm install -g phonegap, 经过一小长段时间(超极本运行了10分钟约, 当然了主要是网速……) , 终于完成 (中间好像有报一个git clone cordova的返回错误,没有理会它)
npm http GET https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.25-1.tgz
npm http 200 https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.1.tgz
npm http 200 https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz
npm http 200 https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.25-1.tgz
C:\Users\hp\AppData\Roaming\npm\phonegap -> C:\Users\hp\AppData\Roaming\npm\node_modules\phonegap\bin\phonegap.js
[email protected] C:\Users\hp\AppData\Roaming\npm\node_modules\phonegap
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], semver@2
.0.11, [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
, [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], node-static
@0.7.0, [email protected], [email protected], [email protected], [email protected], [email protected])
2. 使用安装好的phonegap命令
$ phonegap create my-app
$ cd my-app
$ phonegap run android
在执行第三行命令的时候出错
hp@HP-PC /d/Work/web
$ phonegap run android
[Error: project directory could not be found]
[error] project directory could not be found
查阅了 相关文章 ,需要 下载 ant
下载完成,解压到任意目录, 我这里为 D:\Work\apache-ant-1.9.4
设置环境变量:
重新打开 git bash 命令窗口执行,报新的错误提示:
下载完成,解压到任意目录, 我这里为 D:\Work\apache-ant-1.9.4
设置环境变量:
- ANT_HOME: D:\Work\apache-ant-1.9.4
- Path: %ANT_HOME%\bin
重新打开 git bash 命令窗口执行,报新的错误提示:
hp@HP-PC /d/work/web/bob-app
$ phonegap run android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.js:126
throw e;
^
Error: An error occurred while listing Android targets
at C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\lib\check_reqs.js:87:29
at _rejected (C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.js:808:24)
at C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.js:834:30
at Promise.when (C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.js:1079:31)
at Promise.promise.promiseDispatch (C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.js:752:41)
at C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.js:574:44
at flush (C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:415:13)
{ [Error: C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\create.bat: Command failed with exit code 8] code: 8 }
[error] C:\Users\hp\.cordova\lib\android\cordova\3.5.0\bin\create.bat: Command failed with exit code 8
经过 stackoverflow 的指点, 原来需要以下两个路径添加到PATH中
D:\Work\adt-bundle-windows-x86_64-20131030\sdk\platforms;
D:\Work\adt-bundle-windows-x86_64-20131030\sdk\tools;
(在此应该顺便添加 D:\Work\adt-bundle-windows-x86_64-20131030\sdk\platform-tools的, 要不然下面还会遇到说adb命令找不到的错误)
然后,重启git bash 命令窗口, 进入到 D:/work/web/my-app/下 再运行 phonegap run android,
几乎就要成功了,可是最后又出现一个错误
D:\Work\adt-bundle-windows-x86_64-20131030\sdk\platforms;
D:\Work\adt-bundle-windows-x86_64-20131030\sdk\tools;
(在此应该顺便添加 D:\Work\adt-bundle-windows-x86_64-20131030\sdk\platform-tools的, 要不然下面还会遇到说adb命令找不到的错误)
然后,重启git bash 命令窗口, 进入到 D:/work/web/my-app/下 再运行 phonegap run android,
几乎就要成功了,可是最后又出现一个错误
Invalid number of parameters
The system cannot find the path specified.
Project successfully created.
cp: no such file or directory: d:\Work\web\bob-app\icon.png
cp: no such file or directory: d:\Work\web\bob-app\icon.png
cp: no such file or directory: d:\Work\web\bob-app\res\icon\ios\icon-72.png
cp: no such file or directory: d:\Work\web\bob-app\icon.png
[phonegap] compiling Android...
cp: no such file or directory: d:\Work\web\bob-app\icon.png
cp: no such file or directory: d:\Work\web\bob-app\icon.png
cp: no such file or directory: d:\Work\web\bob-app\res\icon\ios\icon-72.png
cp: no such file or directory: d:\Work\web\bob-app\icon.png
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
Buildfile: d:\Work\web\bob-app\platforms\android\build.xml
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 22.3.0
[checkenv] Installed at d:\Work\adt-bundle-windows-x86_64-20131030\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: 19.0.0
[echo] Resolving Build Target for HelloWorld...
[gettarget] Project Target: Android 4.4
[gettarget] API level: 19
[echo] ----------
[echo] Creating output directories if needed...
[mkdir] Created dir: d:\Work\web\bob-app\platforms\android\ant-build
[mkdir] Created dir: d:\Work\web\bob-app\platforms\android\ant-build\res
[mkdir] Created dir: d:\Work\web\bob-app\platforms\android\ant-build\rsObj
[mkdir] Created dir: d:\Work\web\bob-app\platforms\android\ant-build\rsLibs
[mkdir] Created dir: d:\Work\web\bob-app\platforms\android\ant-gen
[mkdir] Created dir: d:\Work\web\bob-app\platforms\android\ant-build\classes
[mkdir] Created dir: d:\Work\web\bob-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 22.3.0
[checkenv] Installed at d:\Work\adt-bundle-windows-x86_64-20131030\sdk
-setup:
[echo] Project Name: CordovaLib
[gettype] Project Type: Android Library
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 19.0.0
[echo] Resolving Build Target for CordovaLib...
[gettarget] Project Target: Android 4.4
[gettarget] API level: 19
[echo] ----------
[echo] Creating output directories if needed...
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\res
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\libs
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\ant-build
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\ant-build\res
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\ant-build\rsObj
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\ant-build\rsLibs
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\ant-gen
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\ant-build\classes
[mkdir] Created dir: D:\Work\web\bob-app\platforms\android\CordovaLib\ant-build\dexedLibs
[echo] ----------
[echo] Resolving Dependencies for CordovaLib...
[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 89 source files to D:\Work\web\bob-app\platforms\android\CordovaLib\ant-build\classes
BUILD FAILED
d:\Work\adt-bundle-windows-x86_64-20131030\sdk\tools\ant\build.xml:601: The following error occurred while executing thi
s line:
d:\Work\adt-bundle-windows-x86_64-20131030\sdk\tools\ant\build.xml:720: The following error occurred while executing thi
s line:
d:\Work\adt-bundle-windows-x86_64-20131030\sdk\tools\ant\build.xml:734: Error running javac.exe compiler
Total time: 6 seconds
Error code 1 for command: cmd with args: /s,/c,ant,debug,-f,d:\Work\web\bob-app\platforms\android\build.xml,-Dout.dir=an
t-build,-Dgen.absolute.dir=ant-gen
{ [Error: d:\Work\web\bob-app\platforms\android\cordova\build.bat: Command failed with exit code 2] code: 2 }
[error] d:\Work\web\bob-app\platforms\android\cordova\build.bat: Command failed with exit code 2
主要有两个问题
一。 Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
我找了一个,我电脑上的 tools.jar 的实际路径为 C:\Program Files\Java\jdk1.6.0_43\lib
这是因为,没有定义 JAVA_HOME , 它就按默认的地方去找了,没找到。(stackoverflow)
于是添加 JAVA_HOME变量 指定值为: C:\Program Files\Java\jdk1.6.0_43\
二, 没有找到icon ,这个暂时先不考虑它
重启 git bash , 再运行 phonegap run android
一。 Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib\tools.jar
我找了一个,我电脑上的 tools.jar 的实际路径为 C:\Program Files\Java\jdk1.6.0_43\lib
这是因为,没有定义 JAVA_HOME , 它就按默认的地方去找了,没找到。(stackoverflow)
于是添加 JAVA_HOME变量 指定值为: C:\Program Files\Java\jdk1.6.0_43\
二, 没有找到icon ,这个暂时先不考虑它
重启 git bash , 再运行 phonegap run android
-package:
[apkbuilder] Found Deleted Target File
[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: d:\Work\web\bob-app\platforms\android\ant-build\HelloWorld-debug.apk
[propertyfile] Updating property file: d:\Work\web\bob-app\platforms\android\ant-build\build.prop
[propertyfile] Updating property file: d:\Work\web\bob-app\platforms\android\ant-build\build.prop
[propertyfile] Updating property file: d:\Work\web\bob-app\platforms\android\ant-build\build.prop
[propertyfile] Updating property file: d:\Work\web\bob-app\platforms\android\ant-build\build.prop
-post-build:
[move] Moving 1 file to d:\Work\web\bob-app\platforms\android\ant-build
[move] Moving 1 file to d:\Work\web\bob-app\platforms\android\CordovaLib\ant-build
debug:
BUILD SUCCESSFUL
Total time: 4 seconds
d:\Work\web\bob-app\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error executing "adb devices": 'adb' is not recognized as an internal or external command,
operable program or batch file.
hp@HP-PC /d/work/web/bob-app
看到了 BUILD SUCCESSFUL 真不容易。 等等,好像还有一个错 adb 不认识。
再把 D:\Work\adt-bundle-windows-x86_64-20131030\sdk\platform-tools 添加到 PATH中
重启 git bash, 再运行 phonegap run android
再把 D:\Work\adt-bundle-windows-x86_64-20131030\sdk\platform-tools 添加到 PATH中
重启 git bash, 再运行 phonegap run android
[propertyfile] Updating property file: d:\Work\web\bob-app\platforms\android\ant-build\build.prop
[propertyfile] Updating property file: d:\Work\web\bob-app\platforms\android\ant-build\build.prop
[propertyfile] Updating property file: d:\Work\web\bob-app\platforms\android\ant-build\build.prop
-post-build:
[move] Moving 1 file to d:\Work\web\bob-app\platforms\android\ant-build
[move] Moving 1 file to d:\Work\web\bob-app\platforms\android\CordovaLib\ant-build
debug:
BUILD SUCCESSFUL
Total time: 10 seconds
WARNING : No started emulators found, starting an emulator.
d:\Work\web\bob-app\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
ERROR : No emulator images (avds) found, if you would like to create an
avd follow the instructions provided here:
http://developer.android.com/tools/devices/index.html
Or run 'android create avd --name <name> --target <targetID>'
in on the command line.
苍天呐,大地呐。 生命不息,错误不止啊。
不过仔细一看,是说No emulator ,需要 avd.
要什么avd 啊,直接手机连上电脑!
再次运行 phonegap run android
终于在三儿子(Galaxy Nexus)上看到到亲切的 小盒子机器人了,
收工!
PS:
以上都是在鲍勃的机器环境上一步一步的完成。如果您的机器和本文相差甚远,您可能需要参考以下内容:
http://teusink.blogspot.jp/2013/07/guide-phonegap-3-android-windows.html
PhoneGap Cordova 环境搭建
不过仔细一看,是说No emulator ,需要 avd.
要什么avd 啊,直接手机连上电脑!
再次运行 phonegap run android
终于在三儿子(Galaxy Nexus)上看到到亲切的 小盒子机器人了,
收工!
PS:
以上都是在鲍勃的机器环境上一步一步的完成。如果您的机器和本文相差甚远,您可能需要参考以下内容:
http://teusink.blogspot.jp/2013/07/guide-phonegap-3-android-windows.html
PhoneGap Cordova 环境搭建