如何在离子电容器定制插件上嵌入第三方框架? [英] How to embed third party framework on ionic capacitor custom plugin?

查看:96
本文介绍了如何在离子电容器定制插件上嵌入第三方框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Ionic Capacitor插件,该插件可导入2个iOs .framework文件和一个引用此.framework文件之一的.bundle.问题是,无论我如何在插件项目上链接/嵌入和指向/复制此文件,xcode都声称在应用程序项目上,它无法在swift文件中找到该模块.

I am developing an Ionic Capacitor plugin which imports 2 iOs .framework files and a .bundle that refers to one of this .framework files. The thing is that no matter how I link/embed and point/copy this files on the plugin project, xcode claims, on the app project, that it cant find the module in the swift file.

我已经尝试将文件添加到项目中,使用嵌入式二进制文件"选项,链接库,允许非模块化包含(在构建选项菜单上),将文件添加到标头(在构建阶段),以及等等.

I already tried to add the files to the project, used the "Embedded binaries" option, linked libraries, allow non-modular includes (on build options menu), add the files to the headers (on build phases), and so on....

xcode指出错误的行是:

The line that xcode point the error is:

import OneFramework

xcode声称: 没有这样的模块"OneFramework"

And xcode claims: No such module 'OneFramework'

我期望当我通过npm将插件添加到我的应用程序项目中,并随后运行"$ rm -rf ios&&ionic电容器运行ios"来运行该应用程序时,xcode会找到该插件的所有模块我正在尝试做的插件.

I was expecting that when I add the plugin to my app project via npm, and later running a "$ rm -rf ios && ionic capacitor run ios" to run the app, xcode find all the modules of the plugin that I am trying to do.

推荐答案

我找到了解决方案.要实现此目的,首先要知道的是,当您执行npx @capacitor/cli plugin:generate时,CLI为您执行的操作是生成可可豆荚.此Pod的根是生成的文件夹本身. 考虑到这一点,下一步是学习如何制作豆荚,但我将总结使我成功的主要方面.

I found the solution. To achieve this the first thing to know is that when you do npx @capacitor/cli plugin:generate what the CLI do for you is the generation of a cocoa pod. The root of this pod is the generated folder itself. With that in mind, the next thing to do is to learn how to make pods, but i'll sumarize the principal aspects that led me to the success.

-首先打开* .xcworkspace.接下来,单击将文件添加到Pod ..."选项,然后添加文件.请确保已选中如果需要复制文件"选项.请参考下图.

-First of all you open the *.xcworkspace. Followed by that, click on the "Add Files to Pod..." option and add your files. Please ensure that the "Copy files if needed" option is marked. Please refer to the picture below.

-现在可以为.framework创建一个文件夹,为.bundle(如果有)文件创建另一个文件夹.通过右键单击Pods项目并选择新组"选项来执行此操作.选择一个与xcode模式不同的名称,很高兴知道此文件夹是由您创建的.

-Now its nice to create a folder for your .framework and another for the .bundle (if there are any) files. Do this by right clicking the Pods project and select the option "New group". Select a name like that is different from the pattern of xcode, it is nice to know that this folders are created by you.

-如果您做对了,那么您最近添加到项目中的框架将显示在pods项目中,如下所示:

-If you done this right, the frameworks you recently added to the project will appear on the pods project like this:

-现在,为了快速实现查找文件,请拖动pods项目上的.frameworks作为插件项目的"Frameworks,Libraries和Embedded内容".结果将是这样的:

-Now, for your swift implementation find your files, drag your .frameworks that are on the pods project for the "Frameworks, Libraries and Embedded content" of the plugin project. The result will be something like this:

-确定,包含并链接了文件.现在我们应该让我们的可可豆知道这一点并声明这个文件.文件"YourAwesomePlugin.podspec"(位于插件项目的根目录)是窗格的主要入口.在此文件中,您将声明哪些文件(.frameworks,.bundle等)属于您的Pod,因此在您npm安装它时将属于您的插件.要声明这一点,您将需要三个指令:

-Ok, files included and linked. Now we should let our cocoa pod know about this and declare this files. The file "YourAwesomePlugin.podspec" (located at the root of the plugin project) is the main entrance of the pod. In this file you will declare which files (.frameworks, .bundle, etc) belong to your pod and consequently will belong to your plugin when you npm install it. To declare this you'll need three directives:

s.vendored_frameworks = 'ios/Pods/YourFrameworkFolder/**'
s.resource = 'ios/Pods/YourResourceFolder/YourBundle.bundle'   
s.xcconfig = {'ENABLE_BITCODE' => 'NO'} #This is mandatory on my case, but you need to evaluate if this options applies to your plugin. 

-现在我们在插件项目上进行游戏.要在您的应用程序上测试插件是否正常,您需要在APP项目的pods项目的podfile上添加插件项目根目录的路径.像这样:

-Now we hit play on the plugin project. To test on your app if the plugin is ok, you need to add the path of the root of the plugin project on the podfile of the pods project of the APP project. Like this:

-要安装它,您可以在Yourproject/ios/App上运行pod install.

-To install it you can go on Yourproject/ios/App and run pod install.

请注意:

要声明您最近创建的插件的存在,您还需要做一些声明,但这部分很简单,并且已经在电容器/插件文档中进行了记录.

To declare the existence of your recently created plugin you you need to do some declarations as well, but this part is easy and already documented on capacitor/plugin docs.

我建议的通过pod install的安装方法用于测试.如果您使用npm打包您的插件,然后像其他所有插件一样安装npm,那就太好了.

The installation method via pod install that I suggested is for testing. It would be nice if you pack your plugin using npm and npm install it like all other plugins.

我并不像我所希望的那样对椰壳足类有很多了解,但是这种方法行之有效,我认为这是一个干净的解决方案.如果没有,请告诉我.

I dont have much knowledge on cocoapods like I wish, but this works and I think that is a clean solution. If not, please let me know.

如果这个答案对您有用,请竖起大拇指,这是我研究和尝试的一个星期,我希望与大家分享,并写下来.

If this answer is useful for you, please thumbs it up, it is a week of research and trying that I am sharing, along the time to write it all down.

这篇关于如何在离子电容器定制插件上嵌入第三方框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆