Skip to content

Notes: packaging for iOS

Feodor Fitsner edited this page May 8, 2024 · 10 revisions

Converting .dylib to a framework

  • Use lipo command to create a framework library from .dylib for every architecture:
    • ios-arm64
    • ios-arm64-simulator
    • ios-x86_64-simulator
  • Change frameworks library names with install_name_tool.
  • Create Info.plist for every framework library in <arch>/<package>.framework directory:
<?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>CFBundleName</key>
        <string>{python-package-name}</string>
        <key>CFBundleIdentifier</key>
        <string>com.{company_name}.{python-package-name}</string>
        <key>CFBundleVersion</key>
        <string>{python-package-version}</string>
        <key>CFBundleShortVersionString</key>
        <string>{python-package-version}</string>
        <key>CFBundleExecutable</key>
        <string>{python-package-name}</string>
        <key>CFBundleSupportedPlatforms</key>
        <array>
            <string>iPhoneOS</string>
        </array>
        <key>MinimumOSVersion</key>
        <string>12.0</string>
        <key>CFBundleDevelopmentRegion</key>
        <string>en</string>
        <key>CFBundlePackageType</key>
        <string>FMWK</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
    </dict>
</plist>
  • Merge multiple .framework into .xcframework with xcodebuild -create-xcframework.
  • Remove rpaths of references frameworks from serious_python_darwin.

Sources:

Commands

Check what architectures are embedded into a library/executable - file:

file <library.dylib>

Check library/executable references - otool:

otool -L <path-to-exec-or-library>

Merging static/dynamic libraries into a library or framework - lipo:

lipo -create <library1.dylib> <library2.dylib> ... -output <library>

Create .xcframework from multiple .frameworks:

xcodebuild -create-xcframework \
  -framework ios-arm64/a.framework \
  -framework ios-arm64-simulator/a.framework \
  -output a.xcframework

Change library references - install_name_tool:

install_name_tool -change <old-reference> <new-reference> <library>

Change library name:

install_name_tool -id @rpath/<name>.framework/<name> <name>

Check library exported functions - nm:

nm -gU <library>