Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

XCFrameworks

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Why XCFrameworks?

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Build / Create

Slide 12

Slide 12 text

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"

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Building Frameworks

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Building Frameworks

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Creating XCFrameworks

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

AvailableLibraries ... LibraryIdentifier ios-x86_64-maccatalyst LibraryPath Himotoki.framework SupportedArchitectures x86_64 SupportedPlatform ios SupportedPlatformVariant maccatalyst

Slide 22

Slide 22 text

LibraryIdentifier macos-x86_64 LibraryPath Himotoki.framework SupportedArchitectures x86_64 SupportedPlatform macos

Slide 23

Slide 23 text

LibraryIdentifier ios-i386_x86_64-simulator LibraryPath Himotoki.framework SupportedArchitectures i386 x86_64 SupportedPlatform ios SupportedPlatformVariant simulator

Slide 24

Slide 24 text

LibraryIdentifier ios-armv7_arm64 LibraryPath Himotoki.framework SupportedArchitectures armv7 arm64 SupportedPlatform ios

Slide 25

Slide 25 text

CFBundlePackageType XFWK XCFrameworkFormatVersion 1.0

Slide 26

Slide 26 text

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.

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

! Happy XCFramework Life

Slide 30

Slide 30 text

Thank you Sho Ikeda / @ikesyo