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

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

Sho Ikeda
September 06, 2019

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

Sho Ikeda

September 06, 2019
Tweet

More Decks by Sho Ikeda

Other Decks in Programming

Transcript

  1. 5෼ͰΘ͔Δʂ
    Xcode 11͔Β࢖͑Δ
    XCFrameworks
    Sho Ikeda / @ikesyo
    iOSDC Japan 2019
    2019-09-06 Fri
    #iosdc

    View full-size slide

  2. Sho Ikeda /
    @ikesyo
    • ͍͚͠ΐʔʗ஑ా ᠳ
    • ͸ͯͳ@ژ౎
    • εϚʔτϑΥϯΞϓϦ։ൃ
    • iOS / Android / React
    Native
    • Swiftίϛολʔ
    • https://twitter.com/ikesyo
    • https://github.com/ikesyo

    View full-size slide

  3. XCFrameworks

    View full-size slide

  4. XCFrameworks
    • WWDC19ͷηογϣϯ
    • What's New in Swift - WWDC 2019 - Videos -
    Apple Developer
    • Binary Frameworks in Swift - WWDC 2019 -
    Videos - Apple Developer
    • [New!] ϑϨʔϜϫʔΫͷόΠφϦ഑෍༻ͷ৽
    ϑΥʔϚοτ
    • .xcframework֦ுࢠ

    View full-size slide

  5. Why
    XCFrameworks?

    View full-size slide

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

    View full-size slide

  7. XCFrameworks
    Multiplatform Support
    • 1ͭͷ.xcframeworkͷதʹෳ਺ͷϓϥοτϑΥʔ
    Ϝ༻ͷ.frameworkΛόϯυϧ͢Δ
    • macOS
    • iOS Simulator, iOS Device, Mac Catalyst
    (UIKit for Mac),
    • tvOS Simulator, tvOS Device
    • watchOS Simulator, watchOS Device

    View full-size slide

  8. 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Λڞଘͤ͞ΒΕͳ͍
    • ඞવతʹ෼཭͢Δඞཁ͕͋Δ

    View full-size slide

  9. XCFrameworks
    Mac Catalyst (UIKit for Mac)
    • ϓϥοτϑΥʔϜຖʹframework͕෼཭͞Ε͍ͯΔ
    • iOS SimulatorͱMac Catalyst͕ڞଘͰ͖Δ
    • carthage copy-frameworks͕ෆཁʹͳΔʢରԠ଴ͪʣ
    • ετΞਃ੥࣌ʹ͸xcframeworkͷத͔ΒɺiOS Device༻ͷ
    framework͕ຒΊࠐ·ΕΔʢiOS Simulatorͷ෼͸ຒΊࠐ·
    Εͳ͍ʣ
    • ετΞਃ੥༻ͷFat Binary͔ΒSimulatorͷCPUΞʔΩς
    ΫνϟΛऔΓআ͘ඞཁ͕ͳ͘ͳΔ

    View full-size slide

  10. Build / Create

    View full-size slide

  11. 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"

    View full-size slide

  12. 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

    View full-size slide

  13. Building Frameworks

    View full-size slide

  14. 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
    ...

    View full-size slide

  15. Building Frameworks

    View full-size slide

  16. 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

    View full-size slide

  17. Creating XCFrameworks

    View full-size slide

  18. 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

    View full-size slide

  19. XCFrameworks: Info.plist




    AvailableLibraries


    LibraryIdentifier
    watchos-armv7k_arm64_32
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    armv7k
    arm64_32

    SupportedPlatform
    watchos


    LibraryIdentifier
    watchos-i386-simulator
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    i386

    SupportedPlatform
    watchos
    SupportedPlatformVariant
    simulator


    LibraryIdentifier
    ios-x86_64-maccatalyst
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    x86_64

    SupportedPlatform
    ios
    SupportedPlatformVariant
    maccatalyst


    LibraryIdentifier
    macos-x86_64
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    x86_64

    SupportedPlatform
    macos


    LibraryIdentifier
    tvos-x86_64-simulator
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    x86_64

    SupportedPlatform
    tvos
    SupportedPlatformVariant
    simulator


    LibraryIdentifier
    tvos-arm64
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    arm64

    SupportedPlatform
    tvos


    LibraryIdentifier
    ios-i386_x86_64-simulator
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    i386
    x86_64

    SupportedPlatform
    ios
    SupportedPlatformVariant
    simulator


    LibraryIdentifier
    ios-armv7_arm64
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    armv7
    arm64

    SupportedPlatform
    ios


    CFBundlePackageType
    XFWK
    XCFrameworkFormatVersion
    1.0


    View full-size slide


  20. AvailableLibraries

    ...

    LibraryIdentifier
    ios-x86_64-maccatalyst
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    x86_64

    SupportedPlatform
    ios
    SupportedPlatformVariant
    maccatalyst

    View full-size slide


  21. LibraryIdentifier
    macos-x86_64
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    x86_64

    SupportedPlatform
    macos

    View full-size slide


  22. LibraryIdentifier
    ios-i386_x86_64-simulator
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    i386
    x86_64

    SupportedPlatform
    ios
    SupportedPlatformVariant
    simulator

    View full-size slide


  23. LibraryIdentifier
    ios-armv7_arm64
    LibraryPath
    Himotoki.framework
    SupportedArchitectures

    armv7
    arm64

    SupportedPlatform
    ios

    View full-size slide


  24. CFBundlePackageType
    XFWK
    XCFrameworkFormatVersion
    1.0


    View full-size slide

  25. 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 [-framework ...] -output
    xcodebuild -create-xcframework -library [-headers ] [-library [-headers ]...] -output
    OPTIONS:
    -framework Adds a framework from the given .
    -library Adds a static or dynamic library from the given .
    -headers Adds the headers from the given . Only applicable with -library.
    -output The 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.

    View full-size slide

  26. !
    ࠓޙͷ֤छπʔϧ΍SDKͰͷαϙʔτʹظ଴

    View full-size slide

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

    View full-size slide

  28. !
    Happy XCFramework Life

    View full-size slide

  29. Thank you
    Sho Ikeda / @ikesyo

    View full-size slide