在 iOS 框架中嵌入 .dylib [英] Embedding a .dylib inside a framework for iOS

查看:25
本文介绍了在 iOS 框架中嵌入 .dylib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试提交一个带有 Obj-C 动态库 (.dylib) 的 Swift 应用程序,该应用程序不断被 iOS App Store 拒绝并显示诸如

I've been trying to submit a Swift app with an Obj-C Dynamic Library (.dylib) which keeps getting rejected by the iOS App Store with error messages such as

无效的 Swift 支持 - 文件 libswiftDarwin.dylib,libswiftDispatch.dylib、libswiftCoreGraphics.dylib、libswiftUIKit.dylib、libswiftCore.dylib、libswiftFoundation.dylib、libswiftQuartzCore.dylib, libswiftObjectiveC.dylib,libswiftCoreImage.dylib 不在预期位置/有效载荷//框架.将文件移动到预期的位置位置,使用当前的公共(GM)版本重建您的应用程序Xcode,然后重新提交

Invalid Swift Support - The files libswiftDarwin.dylib, libswiftDispatch.dylib, libswiftCoreGraphics.dylib, libswiftUIKit.dylib, libswiftCore.dylib, libswiftFoundation.dylib, libswiftQuartzCore.dylib, libswiftObjectiveC.dylib, libswiftCoreImage.dylib aren’t at the expected location /Payload//Frameworks. Move the file to the expected location, rebuild your app using the current public (GM) version of Xcode, and resubmit it

来自 https://developer.apple.com/library/archive/technotes/tn2435/_index.html#//apple_ref/doc/uid/DTS40017543-CH1-PROJ_CONFIG-APPS_WITH_DEPENDENCIES_BETWEEN_FRAMEWORKS 错误"可能表明您的应用正在嵌入一个未打包为框架的动态库.框架包之外的动态库(通常具有文件扩展名 .dylib)在 iOS、watchOS 或 tvOS 上不受支持,除了对于 Xcode 提供的系统 Swift 库."

因此,下一步是将动态库(作为子项目)嵌入到 Cocoa Touch 框架项目中.设置完成后,尽管框架构建良好,但我在导入的 dylib 类中遇到了找不到符号"错误.

So the next step was to embed the Dynamic Library (as a subproject) within a Cocoa Touch Framework project. Once that was set up, although the framework built fine, I got stuck on "symbol not found" errors for the imported dylib classes.

我想知道实现这个项目结构所需的步骤,或者在 iOS 上是否可行.

I would like to know the steps required to achieve this project structure, or if its even possible on iOS.

推荐答案

我能够通过首先创建一个框架来提交一个带有 .dylib 的应用程序.我首先尝试了苹果文档中描述的方法,但是在提交到商店时出现错误(无效的捆绑.xyz.framework 的捆绑包含不允许的文件'框架')

I was able to submit an app with a .dylib by creating a framework first. I first tried the method described in the apple documentation, but got errors when submitting to the store ( "invalid bundle. the bundle at xyz.framework contains disallowed file 'Frameworks' )

我所做的是使用 lipo 手动将我的 .dylib 打包到框架中.

What i did was use lipo to manually package my .dylib into a framework.

$ lipo -create mylib.dylib -output mylib

现在你得到一个名为mylib"的二进制文件创建一个名为 mylib.framework 的文件夹并将二进制文件放入其中.然后添加一个 Info.plist(您可以从现有框架中复制和修改一个.)在 Info.plist 中,为您的框架填写字段.要更新或添加的主要是可执行文件".这应该是该二进制文件的名称.

Now you get a binary file called 'mylib' Create a folder called mylib.framework and put the binary file in it. Then add an Info.plist ( you can just copy and modify one from an existing framework. ) In the Info.plist, fill out the fields for your framework. The main one to update or add is "Executable" which should be the name of that binary file.

我遇到了另一个问题,我使用的另一个框架引用了我原来的 .dylib,它已经消失了,现在在框架中.为了解决这个问题,我使用了install_name_tool".修改其他框架以查找我的新框架.

I had another issue where another framework I was using was referencing my original .dylib, which is gone and now inside the framework. To fix this I used the "install_name_tool" to modify the other framework to look for my new framework.

$ cd OtherLib.framework 
$ install_name_tool -change @rpath/mylib.dylib @rpath/mylib.framework/mylib OtherLib

您可以在这篇精彩的博文中了解有关该工具的更多信息:https://medium.com/@donblas/fun-with-rpath-otool-and-install-name-tool-e3e41ae86172

You can read more about that tool in this good blog post: https://medium.com/@donblas/fun-with-rpath-otool-and-install-name-tool-e3e41ae86172

这篇关于在 iOS 框架中嵌入 .dylib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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