While the answer of @Morty points you in the right direction, it leaves a lot open to interpretation and didn't work for me, so here's what I had to do:
Open a terminal at your Mylib.dylib
file and run
$ lipo -create Mylib.dylib -output Mylib
Create a folder with the same name as the created binary.framework
and mirror this folder structure:
.
└── Mylib.framework
├── Mylib <- Binary created by lipo
├── Headers
│ └── Mylib.h <- Symbols you want to access from the binary
├── Info.plist
└── Modules
└── module.modulemap
Minimal Info.plist
file for iOS Device:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>XXXXX</string> <- See Mac System Report/Software
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>Mylib</string>
<key>CFBundleIdentifier</key>
<string>some.bundle.identifier</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Mylib</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>16.0</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
</dict>
</plist>
Make sure CFBundleExecutable
is set to the name of your binary, otherwise you'll get the signing issue: "The code signature version is no longer supported.".
Example module.modulemap
:
framework module Mylib {
umbrella header "Mylib.h"
export *
}
Now you should be able to add the framework with Embed & Sign to your target, import it in swift via import Mylib
and use the symbols defined by Mylib.h
. When you run the app, you might encounter the crash Library not loaded: @rpath/Mylib.dylib
, which can be fixed with this command in the directory of the binary:
$ install_name_tool -id @rpath/Mylib.framework/Mylib Mylib