Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
114 views
in Technique[技术] by (71.8m points)

java - How to set up Cordova plugin project with IDE support?

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?

question from:https://stackoverflow.com/questions/32649070/how-to-set-up-cordova-plugin-project-with-ide-support

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...