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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With