简体   繁体   English

在 iOS 框架内嵌入 a.dylib

[英]Embedding a .dylib inside a framework for iOS

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我一直在尝试提交一个带有 Obj-C 动态库 (.dylib) 的 Swift 应用程序,它一直被 iOS App Store 拒绝,并显示错误消息,例如

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.无效的 Swift 支持 - 文件 libswiftDarwin.dylib、libswiftDispatch.dylib、libswiftCoreGraphics.dylib、libswiftUIKit.dylib、libswiftCore.dylib、libswiftFoundation.dylib、libswiftQuartzCore.dylib、libswiftObjectiveC.dylib、libswiftCoreImage.dylib 不在预期位置 /Payload //构架。 Move the file to the expected location, rebuild your app using the current public (GM) version of Xcode, and resubmit it将文件移动到预期位置,使用当前公共 (GM) 版本的 Xcode 重建您的应用程序,然后重新提交

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. "从位于https://developer.apple.com/library/archive/technotes/tn2435/_index.html#//apple_ref/doc/uid/DTS40017543-CH1-PROJ_CONFIG-APPS_WITH_DEPENDENCIES_BETWEEN_FRAMEWORKS的 Apple 文档中,错误“可能表明您的应用是嵌入未打包为框架的动态库 框架包之外的动态库(通常具有文件扩展名.dylib)在 iOS、watchOS 或 tvOS 上不受支持,Xcode 提供的系统 Swift 库除外。

So the next step was to embed the Dynamic Library (as a subproject) within a Cocoa Touch Framework project.所以下一步是将动态库(作为子项目)嵌入到 Cocoa Touch Framework 项目中。 Once that was set up, although the framework built fine, I got stuck on "symbol not found" errors for the imported dylib classes.设置完成后,尽管框架构建良好,但我遇到了导入的 dylib 类的“找不到符号”错误。

I would like to know the steps required to achieve this project structure, or if its even possible on iOS.我想知道实现此项目结构所需的步骤,或者在 iOS 上是否可行。

I was able to submit an app with a.dylib by creating a framework first.我能够通过首先创建一个框架来提交一个带有 a.dylib 的应用程序。 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' )我首先尝试了苹果文档中描述的方法,但在提交到商店时出现错误(“无效的包。xyz.framework 的包包含不允许的文件‘Frameworks’)

What i did was use lipo to manually package my.dylib into a framework.我所做的是使用 lipo 手动将 my.dylib 打包到一个框架中。

$ lipo -create mylib.dylib -output mylib

Now you get a binary file called 'mylib' Create a folder called mylib.framework and put the binary file in it.现在你得到一个名为“mylib”的二进制文件 创建一个名为 mylib.framework 的文件夹并将二进制文件放入其中。 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.然后添加一个 Info.plist(您可以从现有框架中复制和修改一个。)在 Info.plist 中,填写您的框架的字段。 The main one to update or add is "Executable" which should be the name of that binary file.要更新或添加的主要内容是“可执行文件”,它应该是该二进制文件的名称。

I had another issue where another framework I was using was referencing my original.dylib, which is gone and now inside the framework.我有另一个问题,我正在使用的另一个框架正在引用我的 original.dylib,它已经消失,现在在框架内。 To fix this I used the "install_name_tool" to modify the other framework to look for my new framework.为了解决这个问题,我使用了“install_name_tool”来修改另一个框架来寻找我的新框架。

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

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您可以在这篇不错的博客文章中阅读有关该工具的更多信息: https ://medium.com/@donblas/fun-with-rpath-otool-and-install-name-tool-e3e41ae86172

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

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