5

I'm new to developing apps with Cordova but I've got a lot working well. I just successfully implemented the 'phonegap-facebook-plugin'. However, following the instructions, I put many files (from the facebook SDK and plugin) directly into the /platform/ios/ directory - which means instead of working in the root /www/ directory and building both platforms at once, my code is now less 'flexible' and is platform specific. Is there a better way to do structure my files and/or workflow? Am I missing a step or a trick?

I appreciate any help.

Mark Pruce
  • 945
  • 10
  • 25

1 Answers1

3

Starting with Cordova 3.x, there is a new cordova command-line interface that will greatly help you organize code for multiple operating systems. You will use the CLI to create a project and then do all of your development in the main /www/ folder. You can then use the CLI to run commands that will copy your /www/ code into the appropriate place for web assets for each platform (like /myApp/assets/www/ for Android.)

Check out my answer here: Should a phonegap plugin be declared in the config.xml file?

I talk about how the directory structure that gets created, how you should version control /www/ and /merges/ folders, and how you can think about anything in /platforms/ as a build artifact. (The things in this folder aren't necessarily build artifacts but it's helpful to think about it that way if you are doing cross-platform work.)

If you are only developing for a single platform, or are hacking on the native pieces of the platform, then you will be inside these folders changing things. I don't recommend this approach for most people though because the vast majority of use cases are creating cross-platform apps with HTML5.

I have been working on the documentation to make this more clear. The new overview guide should help you: https://github.com/mbillau/cordova-docs/blob/30fb71d11b4db5d34b3ff1c48a16443d5fed1be3/docs/en/edge/guide/overview/index.md (If you read it and still have questions, please let me know so I can address those questions in the documentation and everyone will benefit.)

EDIT: I did not see that most of your question was about plugins. What should happen is that if you have a plugin updated for Cordova 3.x, then you should be able to install it with cordova plugin add .... This should copy the native and .js files into the /plugins/ folder for you. Then when you do cordova prepare it will copy the specific platform files for that plugin into the specific platform folder. So you shouldn't have to copy files all over the place. I'm pretty sure that the plugin you are using is not supported with 3.x though, in which case...I'm not really sure what to tell you. Running prepare should just copy over files, not erase files already there...but I'm not positive.

Community
  • 1
  • 1
MBillau
  • 5,366
  • 2
  • 28
  • 29
  • MBillau - Will you take a look at my Cordova Plugin development question here: http://stackoverflow.com/q/20010461/273628? I don't think this is addressed in the Cordova documentation anywhere (not even on the wiki). – ajh158 Nov 15 '13 at 21:11
  • Hey, it's a great question. Unfortunately I'm not that familiar with plugin development. I'll think about it and try to answer your question in a few days but in the mean time, you could ask on #cordova and #phonegap on freenode. I know that the plugin development story does need work, you could take this opportunity to help us figure out the best workflow for plugin devs (and other things, like identifying documentation holes). – MBillau Nov 15 '13 at 21:48
  • MBillau - thanks. Mark Pruce - sorry to hijack the comments on the answer to your question. Upvotes for the both of you! – ajh158 Nov 15 '13 at 21:51
  • I think the doc should include an explanation of the use case in which you choose plugin X on iOS and plugin Y in Android, covering 1. how do you install plugin X of just one platform 2. how do you check in javascript so that you have if (platform is iOS) { objectX.methodOfX(); else if (platform is Android) { objectY.metofOfY(); } – mico Nov 27 '15 at 09:44