Upgrade to Pro — share decks privately, control downloads, hide ads and more …

5分でわかる!Xcode 11から使えるXCFrameworks

Avatar for Sho Ikeda Sho Ikeda
September 06, 2019

5分でわかる!Xcode 11から使えるXCFrameworks

Avatar for Sho Ikeda

Sho Ikeda

September 06, 2019
Tweet

More Decks by Sho Ikeda

Other Decks in Programming

Transcript

  1. Sho Ikeda / @ikesyo • ͍͚͠ΐʔʗ஑ా ᠳ • ͸ͯͳ@ژ౎ •

    εϚʔτϑΥϯΞϓϦ։ൃ • iOS / Android / React Native • Swiftίϛολʔ • https://twitter.com/ikesyo • https://github.com/ikesyo
  2. XCFrameworks • WWDC19ͷηογϣϯ • What's New in Swift - WWDC

    2019 - Videos - Apple Developer • Binary Frameworks in Swift - WWDC 2019 - Videos - Apple Developer • [New!] ϑϨʔϜϫʔΫͷόΠφϦ഑෍༻ͷ৽ ϑΥʔϚοτ • .xcframework֦ுࢠ
  3. XCFrameworks Multiplatform Support • 1ͭͷ.xcframeworkͷதʹෳ਺ͷϓϥοτϑΥʔ Ϝ༻ͷ.frameworkΛόϯυϧ͢Δ • macOS • iOS

    Simulator, iOS Device, Mac Catalyst (UIKit for Mac), • tvOS Simulator, tvOS Device • watchOS Simulator, watchOS Device
  4. XCFrameworks Mac Catalyst (UIKit for Mac) • Mac Catalyst͸iOSͷѥछ •

    ͜Ε·ͰͷiOSͰͷόΠφϦ഑෍ • iOS Deviceͷarmv7ͱarm64ɺiOS Simulatorͷx86_64ʢͱi386ʣ Λ1ͭʹ·ͱΊͨFat Binary • lipoίϚϯυͰ݁߹͢Δ • Mac Catalyst΋CPUΞʔΩςΫνϟ͸x86_64 • 1ͭͷFat BinaryͰ͸iOS SimulatorͱMac CatalystΛڞଘͤ͞ΒΕͳ͍ • ඞવతʹ෼཭͢Δඞཁ͕͋Δ
  5. XCFrameworks Mac Catalyst (UIKit for Mac) • ϓϥοτϑΥʔϜຖʹframework͕෼཭͞Ε͍ͯΔ • iOS

    SimulatorͱMac Catalyst͕ڞଘͰ͖Δ • carthage copy-frameworks͕ෆཁʹͳΔʢରԠ଴ͪʣ • ετΞਃ੥࣌ʹ͸xcframeworkͷத͔ΒɺiOS Device༻ͷ framework͕ຒΊࠐ·ΕΔʢiOS Simulatorͷ෼͸ຒΊࠐ· Εͳ͍ʣ • ετΞਃ੥༻ͷFat Binary͔ΒSimulatorͷCPUΞʔΩς ΫνϟΛऔΓআ͘ඞཁ͕ͳ͘ͳΔ
  6. Build Settings • "Build Libraries for Distribution" • > Frameworks

    or libraries bundled in an XCFramework should be built with the Build Libraries for Distribution build setting set to YES. • "Supports Mac Catalyst" • "Derive Mac Catalyst Product Bundle Identifier"
  7. Building Frameworks • xcodebuild archive: Multiple Destinations including Simulator xcodebuild

    archive \ -scheme FooBarBaz-iOS -destination "generic/platform=iOS" \ -destination "generic/platform=iOS Simulator" \ -destination "generic/platform=macOS" SKIP_INSTALL=NO
  8. Building Frameworks xcodebuild archive -scheme Himotoki-iOS \ -destination "generic/platform=iOS" \

    -archivePath build/iphoneos \ SKIP_INSTALL=NO xcodebuild archive -scheme Himotoki-iOS \ -destination "generic/platform=iOS Simulator" \ -archivePath build/iphonesimulator \ SKIP_INSTALL=NO xcodebuild archive -scheme Himotoki-iOS \ -destination "generic/platform=macOS" \ -archivePath build/maccatalyst \ SKIP_INSTALL=NO ...
  9. Creating XCFrameworks $ xcodebuild -create-xcframework \ -framework build/macosx.xcarchive/Products/@rpath/Himotoki.framework \ -framework

    build/iphoneos.xcarchive/Products/@rpath/Himotoki.framework \ -framework build/iphonesimulator.xcarchive/Products/@rpath/Himotoki.framework \ -framework build/maccatalyst.xcarchive/Products/@rpath/Himotoki.framework \ -framework build/appletvos.xcarchive/Products/@rpath/Himotoki.framework \ -framework build/appletvsimulator.xcarchive/Products/@rpath/Himotoki.framework \ -framework build/watchos.xcarchive/Products/@rpath/Himotoki.framework \ -framework build/watchsimulator.xcarchive/Products/@rpath/Himotoki.framework \ -output Himotoki.xcframework
  10. XCFrameworks: Directory Structure Himotoki.xcframework ├── Info.plist ├── ios-armv7_arm64 │ └──

    Himotoki.framework ├── ios-i386_x86_64-simulator │ └── Himotoki.framework ├── ios-x86_64-maccatalyst │ └── Himotoki.framework ├── macos-x86_64 │ └── Himotoki.framework ├── tvos-arm64 │ └── Himotoki.framework ├── tvos-x86_64-simulator │ └── Himotoki.framework ├── watchos-armv7k_arm64_32 │ └── Himotoki.framework └── watchos-i386-simulator └── Himotoki.framework
  11. XCFrameworks: Info.plist <?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>AvailableLibraries</key> <array> <dict> <key>LibraryIdentifier</key> <string>watchos-armv7k_arm64_32</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>armv7k</string> <string>arm64_32</string> </array> <key>SupportedPlatform</key> <string>watchos</string> </dict> <dict> <key>LibraryIdentifier</key> <string>watchos-i386-simulator</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>i386</string> </array> <key>SupportedPlatform</key> <string>watchos</string> <key>SupportedPlatformVariant</key> <string>simulator</string> </dict> <dict> <key>LibraryIdentifier</key> <string>ios-x86_64-maccatalyst</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>ios</string> <key>SupportedPlatformVariant</key> <string>maccatalyst</string> </dict> <dict> <key>LibraryIdentifier</key> <string>macos-x86_64</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>macos</string> </dict> <dict> <key>LibraryIdentifier</key> <string>tvos-x86_64-simulator</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>tvos</string> <key>SupportedPlatformVariant</key> <string>simulator</string> </dict> <dict> <key>LibraryIdentifier</key> <string>tvos-arm64</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>arm64</string> </array> <key>SupportedPlatform</key> <string>tvos</string> </dict> <dict> <key>LibraryIdentifier</key> <string>ios-i386_x86_64-simulator</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>i386</string> <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>ios</string> <key>SupportedPlatformVariant</key> <string>simulator</string> </dict> <dict> <key>LibraryIdentifier</key> <string>ios-armv7_arm64</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key> <array> <string>armv7</string> <string>arm64</string> </array> <key>SupportedPlatform</key> <string>ios</string> </dict> </array> <key>CFBundlePackageType</key> <string>XFWK</string> <key>XCFrameworkFormatVersion</key> <string>1.0</string> </dict> </plist>
  12. <dict> <key>AvailableLibraries</key> <array> ... <dict> <key>LibraryIdentifier</key> <string>ios-x86_64-maccatalyst</string> <key>LibraryPath</key> <string>Himotoki.framework</string> <key>SupportedArchitectures</key>

    <array> <string>x86_64</string> </array> <key>SupportedPlatform</key> <string>ios</string> <key>SupportedPlatformVariant</key> <string>maccatalyst</string> </dict>
  13. xcodebuild -create- xcframework $ xcodebuild -create-xcframework -help OVERVIEW: Utility for

    packaging multiple build configurations of a given library or framework into a single xcframework. USAGE: xcodebuild -create-xcframework -framework <path> [-framework <path>...] -output <path> xcodebuild -create-xcframework -library <path> [-headers <path>] [-library <path> [-headers <path>]...] -output <path> OPTIONS: -framework <path> Adds a framework from the given <path>. -library <path> Adds a static or dynamic library from the given <path>. -headers <path> Adds the headers from the given <path>. Only applicable with -library. -output <path> The <path> to write the xcframework to. -allow-internal-distribution Specifies that the created xcframework contains information not suitable for public distribution. -help Show this help content.