Phonegap:将android平台添加到已经构建的应用程序中

时间:2014-03-02 00:04:06

标签: android ios cordova

我为iOS创建了一个phonegap,我想为Android构建它,但以下命令不会将其转换为Android项目:

phonegap platform update android
phonegap install android
phonegap build android

以下是我收到的错误之一:

lucas@lucas-ThinkPad-W520:~/projects/ecostartup/ecometrix-app$ phonegap platform update android
[phonegap] updating Android platform...
   [error] Platform "android" is not installed.
lucas@lucas-ThinkPad-W520:~/projects/ecostartup/ecometrix-app$ phonegap install android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] trying to install app onto device
[phonegap] no device was found
[phonegap] trying to install app onto emulator
   [error] The provided path "/home/lucas/Dropbox/projects/ecostartup/ecometrix-app/platforms/android" is not an Android project.

这是另一个错误:

lucas@lucas-ThinkPad-W520:~/projects/ecostartup/ecometrix-app$ phonegap build android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] adding the Android platform...
   [error] An error occured during creation of android sub-project. 

/home/lucas/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:126
                    throw e;
                          ^
Error: An error occurred while listing Android targets
    at /home/lucas/.cordova/lib/android/cordova/3.3.0/bin/lib/check_reqs.js:87:29
    at _rejected (/home/lucas/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:808:24)
    at /home/lucas/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:834:30
    at Promise.when (/home/lucas/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:1079:31)
    at Promise.promise.promiseDispatch (/home/lucas/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:752:41)
    at /home/lucas/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:574:44
    at flush (/home/lucas/.cordova/lib/android/cordova/3.3.0/bin/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:415:13)

lucas@lucas-ThinkPad-W520:~/projects/ecostartup/ecometrix-app$ 

以下是一些项目信息:

lucas@lucas-ThinkPad-W520:~/projects/ecostartup/ecometrix-app$ ls
platforms  plugins  README.md  www
lucas@lucas-ThinkPad-W520:~/projects/ecostartup/ecometrix-app$ ls platforms/
ios

如何将其转换为Android?

2 个答案:

答案 0 :(得分:2)

实际上看着你的日志,似乎已经构建了应用程序。唯一可见的错误是未检测到手机且无法启动仿真器。

关于您使用的命令:

  • phonegap platform update android这个是你已经为你的项目添加了android平台并安装了更新版本的phonegap所以你暂时不需要它
  • phonegap install android在这里,您尝试将应用安装到连接到计算机的设备上,并安装了适当的驱动程序并允许进行调试
  • phonegap build android在这里,这是构建android项目并生成调试apk的好命令。

运行构建后,您应该在platforms / android / bin

中找到调试apk

如果使用某些插件,还要检查它们是否与android兼容。

答案 1 :(得分:0)

我仔细检查以确保Android在我的路上:

lucas@lucas-ThinkPad-W520:~/projects/ecostartup/ecometrix-app/platforms$ echo $PATH
(rest of path)...:/opt/android-sdk-linux/sdk/tools:/opt/android-sdk-linux/sdk/platform-tools

但我需要安装Cordova:

sudo npm install -g cordova

然后我运行了phonegap build android,这给了我安装Ant的另一个错误:

sudo apt-get install ant

这是安装nodejsnpmphonegap后的全部内容。

我发现这篇文章非常有帮助:

PhoneGap/Cordova Android Development

(我花了一段时间才找到它)