简体   繁体   English

cordova 插件是否与电容器一起工作(离子)

[英]Do cordova plugins work with capacitor (ionic)

When I add plugin: ionic cordova plugin add cordova-sqlite-storage for use https://ionicframework.com/docs/angular/storage Is there any trouble here?当我添加插件时: ionic cordova plugin add cordova-sqlite-storage for use https://ionicframework.com/docs/angular/storage这里有什么问题吗? I am using capacitor.我正在使用电容器。 What if I add the cordova plugins?.如果我添加 cordova 插件会怎么样?

when add ionic cordova plugin add cordova-sqlite-storage当添加 ionic cordova 插件时添加 cordova-sqlite-storage

[WARN] About to integrate your app with Cordova.
       
       We now recommend Capacitor (https://ion.link/capacitor) as the official native runtime for Ionic. To learn about 
       the differences between Capacitor and Cordova, see these docs[1]. For a getting started guide, see these docs[2].
       
       [1]: https://ion.link/capacitor-differences-with-cordova-docs
       [2]: https://ion.link/capacitor-using-with-ionic-docs

Yes, it is possible to use Cordova plugins with Capacitor.是的,可以将 Cordova 插件与 Capacitor 一起使用。 There is no guarantee they will be fully compatible, but you can install and use them in your project.不能保证它们将完全兼容,但您可以在您的项目中安装和使用它们。

However, you don't have to run ionic cordova plugin add cordova-plugin-name , since that will effectively initialize Cordova for your app, which is not what you want.但是,您不必运行ionic cordova plugin add cordova-plugin-name ,因为这将有效地为您的应用程序初始化 Cordova,这不是您想要的。

Instead, install the Cordova plugin and sync Capacitor:相反,安装 Cordova 插件并同步 Capacitor:

npm install cordova-plugin-name
npx cap sync

If the plugin is from Ionic Native, you also have to install the Ionic native package before the Cordova plugin:如果插件来自 Ionic Native,你还必须在 Cordova 插件之前安装 Ionic native package:

npm install @ionic-native/plugin-name
npm install cordova-plugin-name
npx cap sync

See more information here: Capacitor - Using Cordova Plugins and Ionic Native在此处查看更多信息: Capacitor - 使用 Cordova 插件和 Ionic Native


Update 15/01/2021更新 15/01/2021

I have been using this in actual projects for a while and I have verified it works all fine, however, there is a common problem you may run into when building with AndroidX.我已经在实际项目中使用了一段时间,并且我已经验证它可以正常工作,但是,在使用 AndroidX 构建时,您可能会遇到一个常见问题。 Some Cordova plugins still use the old compatibility libraries and may fail to build.一些 Cordova 插件仍然使用旧的兼容库,可能无法构建。

The solution is using Jetifier to upgrade the packages as required.解决方案是使用Jetifier根据需要升级软件包。 Install Jetifier using npm i jetifier --save-dev to add it as a dev dependency in your package.json.使用npm i jetifier --save-dev安装 Jetifier,将其添加为 package.json 中的开发依赖项。

After running npx cap add android to generate the Android project if it did not exist yet, run npx cap sync android and finally npx jetifier before running Gradle to build the app.运行npx cap add android以生成 Android 项目(如果尚不存在),运行npx cap sync android最后运行 npx npx jetifier ,然后再运行 Gradle 构建应用程序。

Jetifier will identify the packages that require an upgrade. Jetifier 将识别需要升级的包。

Hope this helps out with some of the troubleshooting.希望这有助于解决一些故障排除问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM