如何设置Cordova插件项目与IDE支持? [英] How to set up Cordova plugin project with IDE support?

查看:194
本文介绍了如何设置Cordova插件项目与IDE支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力设置我的cordova插件项目。主要是由于以下事实:




  • 插件需要在远离主项目的单独文件夹

    li>
  • 当我使用例如 cordova build android 来构建项目时,cordova会从我的插件文件夹复制java文件,因此我不应该修改我的插件的.java文件夹。


  • 但是我无法将plugin文件夹导入到IDE项目中,因此,


  • 在没有IDE支持的情况下编写Java / Objective-C基本上是不可能的

    b


如何为我的插件开发设置代码完成的IDE(例如,Android Studio)项目?

解决方案

开发Cordova插件有点痛苦。



这是一种方法:


  1. 创建基本文件您的插件( plugin.xml 文件, .java 文件用于Android插件, .h
  2. 在您的<$ c>文件夹中提供 $ c> plugin.xml 需要安装插件

  3. 在Cordova应用程序中安装插件: cordova plugin add / path / to / pugin

  4. 构建您要开发插件的平台。 cordova build android cordova build ios

然后对于每个平台,您必须在构建的项目中直接在您的插件上工作:




  • Android:使用Android Studio打开位于 yourCordovaAppFolder / platforms / android 中的构建的Android项目导入项目(Eclipse ADT,Gradle等) strong>


    1. 打开项目 查看>工具Windows>项目 + 1

    2. 打开位于: android> java> com.your.plugin> YourPlugin


  • iOS:构建的iOS项目位于 yourCordovaAppFolder / platforms / ios
    在Xcode中,您的插件类文件位于插件文件夹




然后,您可以直接开发和测试每个平台的插件,而无需重新安装一次又一次...只需从Android Studio / Xcode运行该项目,不要重新安装插件,它会清除您在项目中执行的操作



当你认为你的开发完成时(或者你想要),将第一步创建的原始插件文件夹中的插件文件替换为你正在开发的项目中的插件文件



我发现Eclipse进行了更新去年夏天, Eclipse Mars(4.5) 包含 Thym (HYbrid Mobile Tools)。



如果需要,他们有一个 Github项目页面



我已经快速测试它,它允许创建Cordova项目,轻松添加插件,并直接在所需的平台(Android,iOS)上运行。



Microsoft还制作了一个免费版本的 Apache Cordova的Visual Studio ,但我没有测试它。



关于Eclipse与Thym,我的第一个快速的结论是,开发Cordova应用程序是实用的,但不会是开发Cordova插件的最终解决方案,因为它不是以这种方式定向的,并且不是为插件而是为应用程序制作的(对于Visual Studio for Apache Cordova来说可能是一样的)。



顺便说一下,我用Eclipse + Thym启动iOS模拟器有些麻烦,所以也许它仍然需要改进,即使它看起来已经很好了。


I've been struggling to set up my cordova plugin project. Mainly due the facts that:

  • Plugins need to be in a separate folder away from the main project

  • When I use, for example, cordova build android to build the project, cordova copies the java file from my plugin folder and put it into platforms/android/src folder.

  • Thus I should not modify my plugin's .java file in the Android project manually, I have to write my code in my plugin folder.

  • But I can't import plugin folder into the IDE project, thus I don't have code completion.

  • It's basically impossible to write Java/Objective-C without IDE support

How can I set up an IDE(for example, for Android Studio) project with code completion for my plugin development?

解决方案

Developing a Cordova plugin is a bit of a pain.

Here is a way to do it :

  1. Create the basic files of your plugin (plugin.xml file, .java file for Android plugin, .h and .m files for iOS) in a separated folder for your plugin
  2. Provide in your plugin.xml what is needed to install the plugin
  3. Install your plugin in your Cordova app : cordova plugin add /path/to/pugin
  4. Build the platforms you want to develop your plugin. cordova build android or cordova build ios

Then for each platform, you'll have to work directly on your plugin in the builded project :

  • Android : open with Android Studio the builded Android project located in yourCordovaAppFolder/platforms/android with "Import project (Eclipse ADT, Gradle, etc.)"

    1. Open the Project tool window : View > Tool Windows > Project , or + 1
    2. Open your plugin class file located at : android > java > com.your.plugin > YourPlugin

  • iOS : open with Xcode the builded iOS project located in yourCordovaAppFolder/platforms/ios In Xcode, your plugin class files are located in the Plugins folder

You can then develop and test directly your plugin for each platform without the need to reinstall it again and again and again... just run the project from Android Studio/Xcode, and don't reinstall your plugin, it will erase what you have done in the project.

When you think your developments are done (or when you want to), replace the plugin file(s) in the original plugin folder created at very first step, with the one from the project you were developing on.

EDIT :

I've discovered that Eclipse made an update last summer, Eclipse Mars (4.5) that includes Thym (The HYbrid Mobile Tools).

If needed they have a Github project page.

I've quickly tested it, it allows to create Cordova projects, easily add plugins, and run directly on desired platform (Android, iOS).

Microsoft has also made a free version of Visual Studio for Apache Cordova, but I haven't tested it.

Regarding Eclipse with Thym, my first quick conclusion is that it is practical to develop Cordova apps but won't be THE ultimate solution to develop Cordova plugins because it is not oriented this way and was not made for plugins but apps making (and it is probably the same for Visual Studio for Apache Cordova).

By the way I had some trouble to launch iOS simulator with Eclipse+Thym, so maybe it still needs improvements even if it looks already good.

这篇关于如何设置Cordova插件项目与IDE支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆