![]() This is especially the case when you want to use a Cordova plugin that makes use of install variables that look like this: cordova plugin add cordova-plugin-facebook4 -variable APP_ID="123456789" -variable APP_NAME="myApplication"Ĭapacitor doesn't have a mechanism to supply variables like this when installing a plugin. Capacitor will look at this file and interpret it the best it can in order to set up the plugin in Capacitor as well. The plugin.xml file serves as a sort of road map as to how the plugin should be installed and configured in a Cordova project. The plugin.xml file that Cordova plugins use is the key to getting everything correctly configured for Capacitor. This means that there are a lot of things happening in "Cordova-land" for a plugin to work outside of the native files for the plugin, and that is going to need to be translated to work in the native projects that Capacitor creates for us (either by us, or by Capacitor itself). Capacitor takes a more simplistic approach where things are generally configured directly in the native projects. One of the key differences between Cordova and Capacitor is that Cordova takes more of an abstracted approach, where things are configured through Cordova. Capacitor can just take the same native files that the Cordova plugin is using and add them to the Capacitor project. This is why Capacitor is able to utilise Cordova plugins, because the idea is fundamentally the same. They both have code that runs in the native iOS or Android projects, and allow communication between your application running in the web view and the rest of the native code, such that your application can send requests for native functionality and receive results. The basic principles behind how Cordova plugins and Capacitor plugins work are the same. The trick is to figure out what needs to be done to configure the plugin correctly, which can be difficult to do if you don't really know how it works behind the scenes. This will be the main focus of this tutorial: Cordova plugins that don't work out of the box, but can be made to work with some additional configuration. Cordova Plugins that Require Additional Configuration Keep in mind that this is not necessarily an exhaustive list of all incompatible plugins. You can find a list of these incompatible plugins here: known incompatible Cordova plugins. ![]() In some cases Capacitor provides its own way to achieve the functionality already, and sometimes there are other reasons the plugin doesn't work. Cordova Plugins that Require Additional ConfigurationĮxample Cordova/Capacitor Plugin Migration: Facebook (cordova-plugin-facebook4)īefore we get into the main portion of this tutorial, it is important to note that there is a list of known plugins that do not work with Capacitor. Cordova Plugins that are Incompatible with CapacitorĢ. I have a much more brief tutorial that covers setting up cordova-plugin-facebook4 in Capacitor here: Using Cordova Plugins that Require Install Variables with Capacitor. It goes into a lot of technical detail, and if you're only interested in getting the cordova-plugin-facebook4 plugin up and running you might find it frustrating. WARNING: The purpose of this tutorial is to serve as a deep dive into how a Cordova plugin is utilised by Capacitor and, through understanding this process, how we can attempt to configure plugins correctly for Capacitor. This tutorial will explore how Capacitor utilises Cordova plugins, and how we can attempt to migrate Cordova plugins that don't just work out of the box. There are some Cordova plugins that just won't work in Capacitor, and some that will require additional manual configuration before they work. To pull that plugin into your native Capacitor projects. Most of the time, installing a Cordova plugin in Capacitor is as simple as running: npm install name-of-plugin ![]() This means that, in general, you won't need to give up access to the plugins you want to use if you move to Capacitor. It will take some time before Capacitor plugins are as prolific as their Cordova counterparts, which is why it is fortunate that we can still use Cordova plugins in Capacitor. Capacitor has its own method for allowing developers to create plugins, for themselves or for the community in general, but this ecosystem is still in its infancy as Capacitor is a relatively new project. Cordova has a huge ecosystem of existing plugins that have been created over the past decade.
0 Comments
Leave a Reply. |