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

7ddcca09c00a2744b983974225447d19?s=47 Sho Ikeda
September 06, 2019

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

7ddcca09c00a2744b983974225447d19?s=128

Sho Ikeda

September 06, 2019
Tweet

Transcript

  1. 5෼ͰΘ͔Δʂ Xcode 11͔Β࢖͑Δ XCFrameworks Sho Ikeda / @ikesyo iOSDC Japan

    2019 2019-09-06 Fri #iosdc
  2. Sho Ikeda / @ikesyo • ͍͚͠ΐʔʗ஑ా ᠳ • ͸ͯͳ@ژ౎ •

    εϚʔτϑΥϯΞϓϦ։ൃ • iOS / Android / React Native • Swiftίϛολʔ • https://twitter.com/ikesyo • https://github.com/ikesyo
  3. XCFrameworks

  4. None
  5. XCFrameworks • WWDC19ͷηογϣϯ • What's New in Swift - WWDC

    2019 - Videos - Apple Developer • Binary Frameworks in Swift - WWDC 2019 - Videos - Apple Developer • [New!] ϑϨʔϜϫʔΫͷόΠφϦ഑෍༻ͷ৽ ϑΥʔϚοτ • .xcframework֦ுࢠ
  6. Why XCFrameworks?

  7. XCFrameworks Swift 5.1: Module Stability • SwiftͰॻ͍ͨϑϨʔϜϫʔΫΛόΠφϦ഑෍͠ ͯ΋໰୊ͳ͘ͳͬͨʢίϯύΠϥʔͷόʔδϣ ϯҧ͍Ͱ΋ΤϥʔʹͳΒͳ͘ͳͬͨʣ •

    ϑϨʔϜϫʔΫͷόΠφϦ഑෍ͷαϙʔτͷվ ળ
  8. XCFrameworks Multiplatform Support • 1ͭͷ.xcframeworkͷதʹෳ਺ͷϓϥοτϑΥʔ Ϝ༻ͷ.frameworkΛόϯυϧ͢Δ • macOS • iOS

    Simulator, iOS Device, Mac Catalyst (UIKit for Mac), • tvOS Simulator, tvOS Device • watchOS Simulator, watchOS Device
  9. 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Λڞଘͤ͞ΒΕͳ͍ • ඞવతʹ෼཭͢Δඞཁ͕͋Δ
  10. XCFrameworks Mac Catalyst (UIKit for Mac) • ϓϥοτϑΥʔϜຖʹframework͕෼཭͞Ε͍ͯΔ • iOS

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

  12. 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"
  13. 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
  14. Building Frameworks

  15. 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 ...
  16. Building Frameworks

  17. 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
  18. Creating XCFrameworks

  19. 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
  20. 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>
  21. <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>
  22. <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>
  23. <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>
  24. <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>
  25. </array> <key>CFBundlePackageType</key> <string>XFWK</string> <key>XCFrameworkFormatVersion</key> <string>1.0</string> </dict> </plist>

  26. 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.
  27. ! ࠓޙͷ֤छπʔϧ΍SDKͰͷαϙʔτʹظ଴

  28. ! ಛʹ޿ࠂSDK΍ܭଌܥͷSDK

  29. ! Happy XCFramework Life

  30. Thank you Sho Ikeda / @ikesyo