SilverFruity / OCRunner

Execute Objective-C code as script. AST Interpreter. iOS hotfix SDK.
MIT License
660 stars 149 forks source link

NSRunner 加载 Framework #12

Closed xcphantomxc closed 3 years ago

xcphantomxc commented 3 years ago

我想实现用NSRunner 加载 从服务器下发的 framework这个功能,我想知道是我framework打包的有问题,还是我NSRunner使用有问题

1.framework使用swift打包静态库

运行时发现如下错误 Error Domain=NSCocoaErrorDomain Code=3587 "dlopen_preflight(/Users/xuechen/Library/Developer/CoreSimulator/Devices/0FA624E9-ABC6-49AA-8123-B5D6DF709536/data/Containers/Data/Application/8D827040-88BB-4B27-9291-428273A7E516/Documents/ToolFramework.framework/ToolFramework): no suitable image found. Did find: /Users/xuechen/Library/Developer/CoreSimulator/Devices/0FA624E9-ABC6-49AA-8123-B5D6DF709536/data/Containers/Data/Application/8D827040-88BB-4B27-9291-428273A7E516/Documents/ToolFramework.framework/ToolFramework: unknown file type, first eight bytes: 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A" UserInfo={NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Users/xuechen/Library/Developer/CoreSimulator/Devices/0FA624E9-ABC6-49AA-8123-B5D6DF709536/data/Containers/Data/Application/8D827040-88BB-4B27-9291-428273A7E516/Documents/ToolFramework.framework/ToolFramework, NSDebugDescription=dlopen_preflight(/Users/xuechen/Library/Developer/CoreSimulator/Devices/0FA624E9-ABC6-49AA-8123-B5D6DF709536/data/Containers/Data/Application/8D827040-88BB-4B27-9291-428273A7E516/Documents/ToolFramework.framework/ToolFramework): no suitable image found. Did find: /Users/xuechen/Library/Developer/CoreSimulator/Devices/0FA624E9-ABC6-49AA-8123-B5D6DF709536/data/Containers/Data/Application/8D827040-88BB-4B27-9291-428273A7E516/Documents/ToolFramework.framework/ToolFramework: unknown file type, first eight bytes: 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A, NSBundlePath=/Users/xuechen/Library/Developer/CoreSimulator/Devices/0FA624E9-ABC6-49AA-8123-B5D6DF709536/data/Containers/Data/Application/8D827040-88BB-4B27-9291-428273A7E516/Documents/ToolFramework.framework, NSLocalizedDescription=The bundle “ToolFramework” couldn’t be loaded because it is damaged or missing necessary resources.}

SilverFruity commented 3 years ago

dlopen只能加载 App Bundle 中的动态库哟

xcphantomxc commented 3 years ago

你好 我这个是用的bundle ,我在网上看到教程有把framework下载到document目录下 然后通过bundle加载并调用 请问这个存在什么问题吗 谢谢

SilverFruity commented 3 years ago

App Bundle指的是Main Bundle,需要是App内部的资源文件,真机沙盒目录下的动态库是无法被加载的哟。

xcphantomxc commented 3 years ago

那网上那些插件化开发教程是实现不了的喽 😭

SilverFruity commented 3 years ago

我记得模拟器是可以的,真机不行😂

xcphantomxc commented 3 years ago

哈哈哈哈 我也在模拟器上试成功 才上真机的 哈哈哈 大佬辛苦