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

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

问题描述

我一直在尝试提交带有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

来自Apple文档,位于"可能表明您的应用正在嵌入未打包为框架的动态库.iOS,watchOS或tvOS不支持框架捆绑包之外的动态库(通常具有文件扩展名.dylib), Xcode提供的系统Swift库除外."

From the Apple docs at https://developer.apple.com/library/archive/technotes/tn2435/_index.html#//apple_ref/doc/uid/DTS40017543-CH1-PROJ_CONFIG-APPS_WITH_DEPENDENCIES_BETWEEN_FRAMEWORKS the error "may indicate your app is embedding a dynamic library that is not packaged as a framework. Dynamic libraries outside of a framework bundle, which typically have the file extension .dylib, are not supported on iOS, watchOS, or tvOS, except for the system Swift libraries provided by Xcode."

因此,下一步是将动态库(作为子项目)嵌入Cocoa Touch Framework项目中.一旦设置完成,尽管框架构建良好,但我陷入了导入的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提交应用. 我首先尝试了Apple文档中描述的方法,但是提交到商店时遇到错误(无效的捆绑包.xyz.framework的捆绑包包含不允许的文件'Frameworks')

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,该.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/与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

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

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