使用 Eclipse 和 Phonegap/Cordova 3 进行开发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18680504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:10:04  来源:igfitidea点击:

Developing with Eclipse and Phonegap/Cordova 3

androideclipsecordovacordova-3

提问by stevemarvell

It seem the documentation is a bit thin and I assure you I have tried to find this online, but I really don't get how the development process is supposed to work with phonegap and eclipse.

看起来文档有点薄,我向你保证我已经尝试在网上找到它,但我真的不明白开发过程应该如何与 phonegap 和 eclipse 一起工作。

I followed one of the many tutorials and created the Hello World example using the the cordova command line. I then added the android platform and ran the build. After that, I added the andoridy bit as a project in eclipse with respect to existing source as instructed using the subdirectory platforms/android directory. This allowed me to set up the emulator and all worked very well.

我遵循了众多教程之一,并使用cordova 命令行创建了Hello World 示例。然后我添加了 android 平台并运行了构建。之后,我按照使用子目录平台/android 目录的指示,在 eclipse 中添加了 andoridy 位作为一个项目,相对于现有源。这使我能够设置模拟器并且一切都运行良好。

The problem I now have is with the development process.

我现在遇到的问题是开发过程。

I understand that I have to edit the top level files, not the ones presented in the assets directory of the project in eclipse as these are created using the "build" command. These top level files don't exist in the project I've created in eclipse as they are above the root of the project.

我知道我必须编辑顶级文件,而不是 eclipse 中项目的资产目录中显示的文件,因为这些文件是使用“build”命令创建的。这些顶级文件在我在 eclipse 中创建的项目中不存在,因为它们位于项目的根目录之上。

So, my question is ... can I use eclipse to develop this project in a sensible way?

所以,我的问题是……我可以使用 eclipse 以明智的方式开发这个项目吗?

What I'm doing at the moment is editing the android www files and then to pump it up to the cloud build, I'm copying them back up the tree. This seems insane.

我目前正在做的是编辑 android www 文件,然后将其上传到云构建,我将它们复制到树上。这似乎很疯狂。

Is there a way of having the real files available in eclipse so I can develop them and then build and deploy to an emulator easily?

有没有办法让 eclipse 中的真实文件可用,这样我就可以开发它们,然后轻松地构建和部署到模拟器?

PS is it my imagination or does cordova build take ages!

PS是我的想象还是cordova构建需要很长时间!

Solution

解决方案

I added a folder within the Android project which is a link to the location of the www in the root. This is under advanced options of creating a folder.

我在 Android 项目中添加了一个文件夹,该文件夹是指向根目录中 www 位置的链接。这是在创建文件夹的高级选项下。

采纳答案by miwe

To do this, you must use two different eclipse projects. One containing the myProject/www folder for developing (let's call it 'top-level project') and one for your specific platform-project (e.g. android, as you already did).

为此,您必须使用两个不同的 eclipse 项目。一个包含用于开发的 myProject/www 文件夹(我们称之为“顶级项目”),另一个用于您的特定平台项目(例如 android,正如您已经做过的那样)。

In your top level project, you write your code and, if you feel like, you can even debug up to a certain degree (functions which do not require cordova). Then save and type cordova preparein your CLI. You can then switch to your android project, hit refresh (F5) and run the emulator / device and look for bugs, and make Android-Manifest changes. If you want to change code, switch again to your top-level project and do the same over again.

在您的顶级项目中,您编写代码,如果您愿意,您甚至可以调试到一定程度(不需要cordova 的函数)。然后保存并输入cordova prepare您的 CLI。然后您可以切换到您的 android 项目,点击刷新 (F5) 并运行模拟器/设备并查找错误,并进行 Android-Manifest 更改。如果您想更改代码,请再次切换到您的顶级项目并再次执行相同操作。

This seems a bit unhandy, right. Nevertheless, think about cordova not beeing only for developing on android, but also on ios, windows phone, blackberry, ... To access all these platforms, you have to switch to multiple ide's anyway. It makes it a lot easier then, to have the top-level code in a independent project.

这似乎有点不方便,对吧。尽管如此,想想cordova 不仅仅用于在android 上开发,还可以用于ios、windows 手机、黑莓……要访问所有这些平台,无论如何你必须切换到多个ide。在一个独立的项目中拥有顶级代码会让事情变得更容易。

Some sidenodes:

一些侧节点:

  1. After doing this process a few times, you will loose not more than 2 or 3 seconds to cordova prepareand switch projects. Which is ok, I think.

  2. I myself don't just use different eclipse projects, I even use different eclipse installations. This seemed better arranged for me, as it protects me from confusing top and low level files.

  3. Even if you develop only for android, you should use two different projects, as 'cordova prepare' (or any cli command containing prepare, as build, emulate and run) would overwrite/delete your files.

  4. On my installation, building with CLI takes the same amount of time as it does in eclipse. Which makes sense, as I am using the same sdk for both. However, in the process written above, there is no need to use the cli-build command.

  5. If you use just the android platform and don't get easily confused with same-named files in one project, you might link the myApp/www folder in your Android project. In this case, you will only have one project (Credit for this answer goes to stevemarvell himself, im just adding this here for completeness)

  1. 做几次这个过程后,你将有不超过 2 或 3 秒的时间来cordova prepare切换项目。没关系,我想。

  2. 我自己不只是使用不同的 eclipse 项目,我什至使用不同的 eclipse 安装。这对我来说似乎更好,因为它可以保护我免于混淆顶级和低级文件。

  3. 即使您只为 android 开发,您也应该使用两个不同的项目,因为“cordova prepare”(或任何包含 prepare、as build、emulate 和 run 的 cli 命令)会覆盖/删除您的文件。

  4. 在我的安装中,使用 CLI 构建所需的时间与在 eclipse 中的构建时间相同。这是有道理的,因为我对两者都使用相同的 sdk。但是,在上面写的过程中,没有必要使用cli-build命令。

  5. 如果您只使用 android 平台并且不会轻易与一个项目中的同名文件混淆,那么您可以链接您的 Android 项目中的 myApp/www 文件夹。在这种情况下,您将只有一个项目(此答案的功劳归于 stevemarvell 本人,我只是在此处添加此内容以确保完整性)

回答by bishopthom

in addition to the solution above, i created an 'external tools' configuration that runs the phonegap utility with 'local build android' options and a environment PATH variable set to '/opt/local/bin:/usr/bin:/bin' for my Mac. from there, i installed the Eclipse CDT tools and used its 'Launch Group' feature to run the external tool from the top-level project before calling a debug on the platform-specific project.

除了上述解决方案之外,我还创建了一个“外部工具”配置,该配置运行带有“本地构建 android”选项和设置为“/opt/local/bin:/usr/bin:/bin”的环境 PATH 变量的 phonegap 实用程序对于我的 Mac。从那里,我安装了 Eclipse CDT 工具并使用其“启动组”功能从顶级项目运行外部工具,然后在特定于平台的项目上调用调试。

seems to work fairly well. unfortunately they top-level project doesn't 'remember' the Launch Group execution, so i have to select it from the Debug drop-down each time. i converted the top-level project to a JavaScript as a test, but it didn't seem to help and the 'Run/Debug Settings' in Project Properties are all greyed out.

似乎工作得很好。不幸的是,他们的顶级项目不“记住”启动组执行,所以我每次都必须从调试下拉菜单中选择它。我将顶级项目转换为 JavaScript 作为测试,但它似乎没有帮助,并且项目属性中的“运行/调试设置”全部变灰。

回答by user2898616

See my answer here: Multiple Html files in PhoneGap Android project

在此处查看我的答案:PhoneGap Android 项目中的多个 Html 文件

Why I moved to Netbeans with Phonegap 3.0 CLI. Suited my workflow better.

为什么我使用 Phonegap 3.0 CLI 迁移到 Netbeans。更适合我的工作流程。