使用Crosswalk时管理和安装Cordova插件的正确方法是什么?

时间:2022-04-22 16:24:28

I'm using Crosswalk (cordova-plugin-crosswalk-webview) in my Cordova project and I'm bit confused because Crosswalk affects plugins, Cordova 5 switched to NPM for plugins, and the naming of plugins has changed. It seems documentation has not been updated/unified everywhere yet.

我在我的Cordova项目中使用Crosswalk(cordova-plugin-crosswalk-webview),我有点困惑,因为Crosswalk影响了插件,Cordova 5切换到NPM插件,并且插件的命名已经改变。似乎文档尚未在任何地方更新/统一。

Anyway,

This works:
<plugin name="org.apache.cordova.camera" version="0.3.6" />

这有效:

This also works:
<plugin name="https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git#1.0.0" />

这也有效:

This does not work:
<plugin name="cordova-plugin-camera" version="1" /> (gives me a build error on Android)

这不起作用: (在Android上给我一个构建错误)

Three questions about that:

关于这三个问题:

  1. What's the difference between these plugins?
  2. 这些插件之间有什么区别?

  3. Which plugin configuration is the best to use for Cordova >= 5?
  4. 哪个插件配置最适合Cordova> = 5?

  5. Are these plugins maintained by the same organization?
  6. 这些插件是否由同一组织维护?

1 个解决方案

#1


The difference between the plugins is none other that the source of the plugin installation. Both were installed either with the cordova CLI or plugman with one of the following commands

插件之间的区别在于插件安装的来源。两者都使用cordova CLI或plugman与以下命令之一安装

cordova plugin install
plugman install --platform [platform] --project . \ --plugin [plugin_name]

In your first case

在你的第一个案例

<plugin name="org.apache.cordova.camera" version="0.3.6" />

was installed using any of the above but with a syntax like this

使用上述任何一个安装,但使用这样的语法

cordova plugin install org.apache.cordova.camera 

This might not work correctly if you are using an older version of cordova because they moved the plugin repository to npm so you can use the next alternative

如果您使用旧版本的cordova,这可能无法正常工作,因为他们将插件存储库移动到npm,因此您可以使用下一个替代方案

<plugin name="https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git#1.0.0" />

was installed using git directly from the github repository

是直接从github存储库使用git安装的

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git

It's basically the same, the second being more flexible since it let you install plugins not registered in the cordova plugin registry so you can test your own plugins.

它基本相同,第二个更灵活,因为它允许您安装未在cordova插件注册表中注册的插件,因此您可以测试自己的插件。

As for your second question "Which plugin configuration is the best to use for Cordova >= 5" there is a catch here. You are using crosswalk, this means that you must use the plugin compatibility table listed here. This is probably why you are getting a compilation error on android, wrong plugin version.

至于你的第二个问题“哪个插件配置最适合Cordova> = 5”,这里有一个问题。您正在使用crosswalk,这意味着您必须使用此处列出的插件兼容性表。这可能就是为什么你在android,错误的插件版本上收到编译错误的原因。

If you were not using crosswalk always use the last version of the plugin. Cordova is making a lot of changes lately so this will keep you up to date.

如果您不使用crosswalk,请始终使用该插件的最新版本。科尔多瓦最近做了很多改变,所以这将让你保持最新。

As for the last question you usually can lookup the plugin name for the author. Cordova is an Apache project so all plugin starting with org.apache.cordova prefix are the official cordova plugins. This doesn't mean that they are better that others, just that they are created by the same team that develop cordova itself which gives you a certain degree of trust but is normal that any plugin have bugs, they are programs after all :)

至于最后一个问题,您通常可以查找作者的插件名称。 Cordova是一个Apache项目,因此所有以org.apache.cordova前缀开头的插件都是官方的cordova插件。这并不意味着他们比其他人更好,只是他们是由开发cordova本身的同一团队创建的,这给了你一定程度的信任但是任何插件都有错误是正常的,毕竟他们是程序:)

You can look for more information on the plugin registry site. This will also give you information like who are the people maintaining the plugin, documentation, it's github repository and it's issue tracker to report bugs. Plugins usually contain a README file with relevant information about the author and website that that you can use also.

您可以在插件注册表站点上查找更多信息。这也将为您提供信息,例如维护插件的人员,文档,github存储库以及报告错误的问题跟踪器。插件通常包含一个README文件,其中包含有关作者和网站的相关信息,您也可以使用它们。

#1


The difference between the plugins is none other that the source of the plugin installation. Both were installed either with the cordova CLI or plugman with one of the following commands

插件之间的区别在于插件安装的来源。两者都使用cordova CLI或plugman与以下命令之一安装

cordova plugin install
plugman install --platform [platform] --project . \ --plugin [plugin_name]

In your first case

在你的第一个案例

<plugin name="org.apache.cordova.camera" version="0.3.6" />

was installed using any of the above but with a syntax like this

使用上述任何一个安装,但使用这样的语法

cordova plugin install org.apache.cordova.camera 

This might not work correctly if you are using an older version of cordova because they moved the plugin repository to npm so you can use the next alternative

如果您使用旧版本的cordova,这可能无法正常工作,因为他们将插件存储库移动到npm,因此您可以使用下一个替代方案

<plugin name="https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git#1.0.0" />

was installed using git directly from the github repository

是直接从github存储库使用git安装的

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git

It's basically the same, the second being more flexible since it let you install plugins not registered in the cordova plugin registry so you can test your own plugins.

它基本相同,第二个更灵活,因为它允许您安装未在cordova插件注册表中注册的插件,因此您可以测试自己的插件。

As for your second question "Which plugin configuration is the best to use for Cordova >= 5" there is a catch here. You are using crosswalk, this means that you must use the plugin compatibility table listed here. This is probably why you are getting a compilation error on android, wrong plugin version.

至于你的第二个问题“哪个插件配置最适合Cordova> = 5”,这里有一个问题。您正在使用crosswalk,这意味着您必须使用此处列出的插件兼容性表。这可能就是为什么你在android,错误的插件版本上收到编译错误的原因。

If you were not using crosswalk always use the last version of the plugin. Cordova is making a lot of changes lately so this will keep you up to date.

如果您不使用crosswalk,请始终使用该插件的最新版本。科尔多瓦最近做了很多改变,所以这将让你保持最新。

As for the last question you usually can lookup the plugin name for the author. Cordova is an Apache project so all plugin starting with org.apache.cordova prefix are the official cordova plugins. This doesn't mean that they are better that others, just that they are created by the same team that develop cordova itself which gives you a certain degree of trust but is normal that any plugin have bugs, they are programs after all :)

至于最后一个问题,您通常可以查找作者的插件名称。 Cordova是一个Apache项目,因此所有以org.apache.cordova前缀开头的插件都是官方的cordova插件。这并不意味着他们比其他人更好,只是他们是由开发cordova本身的同一团队创建的,这给了你一定程度的信任但是任何插件都有错误是正常的,毕竟他们是程序:)

You can look for more information on the plugin registry site. This will also give you information like who are the people maintaining the plugin, documentation, it's github repository and it's issue tracker to report bugs. Plugins usually contain a README file with relevant information about the author and website that that you can use also.

您可以在插件注册表站点上查找更多信息。这也将为您提供信息,例如维护插件的人员,文档,github存储库以及报告错误的问题跟踪器。插件通常包含一个README文件,其中包含有关作者和网站的相关信息,您也可以使用它们。