A. ๊ฒฐ๋ก
- ํธ์คํธ ์ฑ์์ static, dynamic ๊ด๊ณ ์์ด ์ฌ์ฉ ๊ฐ๋ฅ
- ํธ์คํธ ์ฑ์์ ์ด๋ฏธ a ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉํ๊ณ ์๋๋ฐ ํ๋ ์์ํฌ์์๋ a ์ฌ์ฉํด์ผ ๋๋ฉด ์ถฉ๋ ์์ด ๊ทธ๋ฅ ์ค์น๋์ด ์๋ ๊ฑธ๋ก ์ฌ์ฉ๋จ.
- ํ๋ ์์ํฌ ์์ฒด๋ xcframework์ด๊ณ ๊ทธ ๋ด๋ถ๋ static library์.
- ํ๋ ์์ํฌ ๋ด๋ถ ์์ค์ฝ๋ ๋น๊ณต๊ฐ, ๊ทธ๋ฌ๋ ๋ด PC์ ํด๋น ํ๋ ์์ํฌ ์ ์ฒด ์์ค ์ฝ๋๊ฐ ์๋ค๋ฉด indexing์ด ๋์ด์์. ๋ง์ฝ ์ 3์๊ฐ ํ๋ ์์ํฌ ๋ด๋ถ ์์ค ์ฝ๋ ์์ด pod์ผ๋ก ํ๋ ์์ํฌ๋ง ๋ฐ๋๋ค๋ฉด ์ฝ๋๊ฐ ๋ณด์ด์ง ์์.
- ์ฒดํฌํด๋ณธ ๊ฒฐ๊ณผ ๊ฐ๋ฅํ ๊ฒ
- ์ข ์์ฑ ์ฌ์ฉ ๊ฐ๋ฅ
- ํค์ฒด์ธ ๊ฐ๋ฅ
- UIKit ์ฌ์ฉํด์ vc, view … ๋ฑ๋ฑ ์ฌ์ฉ ๊ฐ๋ฅ
- Bundle๋ก ๋๊ฐ์ผ ํ๋ xib, image ํ์ผ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ๋ฐฐํฌ ๋ถ๊ฐ๋ฅ.
ํ ์คํธ
์ข ์์ฑ ์ฌ์ฉ ๊ฐ๋ฅ | UIKit ์ฌ์ฉ ๊ฐ๋ฅ |
![]() |
![]() |
|
|
B. ์ ์ฒด ๊ณผ์
- static library ๋ง๋ค๊ธฐ
- 1์์ ์์ฑํ ํ๋ก์ ํธ์ pod์ ํตํด ์ธ๋ถ ์ข ์์ฑ ์ค์น
- static library xcframework
- ๋ฐฐํฌ์ฉ podspec ๋ง๋ค๊ธฐ
- test ํ๋ก์ ํธ์์ pod์ผ๋ก ์ค์น ํ ๋น๋ ์ธํ ์์
C. ๊ฐ ๊ณผ์ ์์ธ - 1, 2
File > New > Project > Static Library ์ ํ
dynamic framework์ ๋ค๋ฅด๊ฒ ์๋ช ์ ๊ผญ ๋ ๋ ํ์ ์์. static library์์๋ ์๋ช ์์ฒด๊ฐ ์์ ์๋ํ๋ฉด ๊ทธ ์์ฒด๋ก ์คํ๋ ์ ์๋ ์ฝ๋๊ฐ ์๋๊ณ ํน์ ์ฑ์ด๋ ๋ชจ๋์ ์ฝ์ ๋์ด์ ์คํ๋๊ธฐ ๋๋ฌธ. (์ถ์ฒ : about static library code signing … | Apple Developer Forums ) ๊ทธ๋ฌ๋ ํ๊ฒ iOS ๋ฒ์ ์ ๊ฐ library → targets → Build Settings → iOS Deployment Target์ ์์ ํด์ฃผ๋ฉด ๋จ.
๋ง๋ ํ๋ก์ ํธ ์ฐฝ ๋ซ๊ณ ํด๋น ์์น์์ ํฐ๋ฏธ๋ open → pod init → vi PodSpec → ํ์ผ์ ์ํ๋ ์ข ์์ฑ ์ถ๊ฐ. Demo project์์๋ pod 'Alamofire'๋ฅผ ์ถ๊ฐํด์ฃผ์์. → pod install → ํ๋ก์ ํธ๋ช .xcworkspace ์ด๊ธฐ
๊ทธ๋ฆฌ๊ณ ์ฌ๊ธฐ์ ์ฝ๋ ์์ฑํ๋ฉด ๋๋๋ฐ pod์ผ๋ก ์ข ์์ฑ ์ค์นํ ๊ฒ์ importํ ๋ @_implementationOnly ํค์๋ ๋ถ์ฌ์ ์ฌ์ฉํด์ฃผ์ด์ผ ํจ. (e.g. @_implementationOnly import Alamofire)
์ฝ๋ ์์ฑ์ด ์๋ฃ ๋์๋ค๋ฉด xcframework๋ก ๋ง๋๋ 3๋ฒ ๊ณผ์ ์ํํ๊ธฐ ์ ์ ๋น๋ ํด๋ฆฐํด์ฃผ๊ณ ios, simulator๋ก ๊ฐ๊ฐ ๋น๋ํด์ฃผ์ด์ผ ํจ.
D. ๊ฐ ๊ณผ์ ์์ธ - 3
static library๋ฅผ ๋ง๋ ์์น์์ ํฐ๋ฏธ๋ open ํ ์๋์ ๋ช ๋ น์ด ์คํ (์ด์ ์ ๋ง๋ xcframework๊ฐ ์๋ค๋ฉด build, derived_data ํด๋ ์ญ์ ํ ๋ค์ ์คํ)
// simulator ์ฉ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋น๋ (์์ฑ ์์น : derived_data ํด๋ ํ์)
xcodebuild build \\
-scheme ํ๋ก์ ํธ๋ช
\\
-derivedDataPath derived_data \\
-arch x86_64 \\
-sdk iphonesimulator \\
-workspace ํ๋ก์ ํธ๋ช
.xcworkspace \\
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
// ๋ง๋ค์ด์ง ๊ฑธ build ํด๋ ๋ง๋ค๊ณ ๋ค์ ๋ณต์ฌ-๋ถ์ฌ๋ฃ๊ธฐ
mkdir -p build/simulators
cp -r derived_data/Build/Products/Debug-iphonesimulator/ build/simulators
// ios ์ฉ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋น๋ (์์ฑ ์์น : derived_data ํด๋ ํ์)
xcodebuild build \\
-scheme ํ๋ก์ ํธ๋ช
\\
-derivedDataPath derived_data \\
-arch arm64 \\
-sdk iphoneos \\
-workspace ํ๋ก์ ํธ๋ช
.xcworkspace \\
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
// ๋ง๋ค์ด์ง ๊ฑธ build ํด๋ ๋ง๋ค๊ณ ๋ค์ ๋ณต์ฌ-๋ถ์ฌ๋ฃ๊ธฐ
mkdir -p build/devices
cp -r derived_data/Build/Products/Debug-iphoneos/ build/devices
// ๋ณต์ฌ๋ library๋ก xcframework ๋น๋ (์์ฑ ์์น : build ํด๋ ํ์)
xcodebuild -create-xcframework \\
-library build/simulators/libํ๋ก์ ํธ๋ช
.a \\
-library build/devices/libํ๋ก์ ํธ๋ช
.a \\
-output build/ํ๋ก์ ํธ๋ช
.xcframework
E. ๊ฐ ๊ณผ์ ์์ธ - 4
3์์ ๋ง๋ค์ด์ง ํ๋ก์ ํธ๋ช .xcframework ํด๋๋ฅผ ๋ฐฐํฌ ๊ด๋ฆฌ๋ฅผ ์ํ ํด๋๋ก ์ด๋. ์ด๋ํ ํด๋์์ cmd open → git init → git remote add origin ์ฃผ์๋ช (๋ฐฐํฌ๋ฅผ ์ํ ๊ณต๊ฐ repo git ์ฃผ์) → touch ํ๋ก์ ํธ๋ช .podspec → ์์ฑํ ์คํ ํ์ผ ์คํ ํ ์๋ ๋ช ๋ น์ด ์์ฑ
Pod::Spec.new do |s|
s.name = "ํ๋ก์ ํธ๋ช
"
s.version = "๋ฒ์ "
# e.g. s.version = "0.1.0"
s.summary = "summary ์์ฑ"
s.description = <<-DESC
Desc ์์ฑ
DESC
s.homepage = "ํํ์ด์ง ์ฃผ์"
s.license = { :type => 'Copyright', :text => <<-LICENSE
Copyright 2018
Permission is granted to...
LICENSE
}
s.author = { 'name' => 'email' }
# e.g. s.author = { '์ ์ ๋ช
' => '์ด๋ฉ์ผ' }
s.source = { :git => "repo git ์ฃผ์", :tag => s.version.to_s }
s.vendored_frameworks = "ํ๋ก์ ํธ๋ช
.xcframework"
s.dependency '๊ฐ์ด ๊น๋ ค์ผ ๋๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ด๋ฆ'
# e.g. s.dependency 'Alamofire'
s.platform = :ios
s.swift_version = "์ค์ํํธ ๋ฒ์ "
s.ios.deployment_target = '13.0'
s.static_framework = true
end
์ดํ ์๋ ์์ ๋ฐ๋ผ์ ๊น ๋ฆฌํฌ์ ์ ๋ก๋ํด์ฃผ๋ฉด ๋จ. (ํ์ฌ ๋ฒ์ ์ด 0.x.x๋ผ๊ณ ๊ฐ์ )
- git add .
- git commit "commit msg"
- git tag 0.x.x
- git push origin ํ์ฌ_๋ธ๋์น tag 0.x.x
๋ง์ฝ ์๋ก์ด xcframework๋ฅผ ๋ง๋ค๊ณ ์ ๋ก๋ํ ๋๋ ํด๋น ํด๋์์ xcframework ์ด์ ๋ฒ์ ๊ฒ ์ง์ฐ๊ณ ์๋ก์ด ํด๋ ๋ฃ์ด์ค ํ podspec์์ ๋ฒ์ ์ ์์ผ์ฃผ๊ณ ์ 1~4 ๋ช ๋ น์ด ๋ค์ ์คํํด์ ์ ๋ก๋ํ๋ฉด ๋จ.
F. ๊ฐ ๊ณผ์ ์์ธ - 5
์ฌ์ฉํ๋ ค๋ ํ๋ก์ ํธ์์ Podfile์ ์๋ ๋ฌธ๊ตฌ ์ถ๊ฐ (๋ฒ์ ์ 0.x.x๋ผ๊ณ ๊ฐ์ )
pod 'ํ๋ก์ ํธ๋ช ', :git => "๋ฆฌํฌ ์ฃผ์", :tag => '0.x.x'
๊ทธ๋ฆฌ๊ณ ๋งจ ์๋ (end ๋ค) ์๋ ์ฝ๋ ์ถ๊ฐ
post_install do |pi|
pi.pods_project.targets.each do |t|
t.build_configurations.each do |config|
config.build_settings[‘BUILD_LIBRARY_FOR_DISTRIBUTION’] = ‘YES’
end
end
end
์ด ํ๋ก์ ํธ์ Library Search Paths, Import Paths์ ์๋ ํญ๋ชฉ ์ถ๊ฐ
$(SRCROOT)/Pods/ํ๋ก์ ํธ๋ช
/ํ๋ก์ ํธ๋ช
.xcframework/ios-x86_64-simulator
$(SRCROOT)/Pods/ํ๋ก์ ํธ๋ช
/ํ๋ก์ ํธ๋ช
.xcframework/ios-arm64
G. NAMSDK
→ NAMSDK์ GFPSDK๋ static library๋ฅผ ์ฌ์ฉ ์ค
Specs/NAMSDK.podspec.json at master · CocoaPods/Specs
→ NAMSDK๋ dependencies๋ก 3rd party library์ธ KissXML์ ์ฌ์ฉํ๊ณ ์์.
NAMSDK์ ๋น๊ตํด์ ์ง๊ธ ๋์ง ์๋ ์ : ์๋ฎฌ๋ ์ดํฐ๋ก ๋น๋ ์ ์ฐพ์ง ๋ชปํ๋ ์ . Derived Data์ simulator ํด๋ ๋ด XCFrameworkIntermediates ํด๋์ ์์นด์ด๋น์ด ๋์ง ์์… ํ์ง๋ง ๊ตณ์ด ์ง๊ธ ์ฐพ์ง ์๊ณ ๋ฐฐํฌ ๋ ์ฐพ์๋ ์ถฉ๋ถํ ํด๊ฒฐํ ์ ์์ ๊ฒ ๊ฐ์.
'CS > iOS, Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS] ํด์ฑ (0) | 2023.04.07 |
---|---|
[iOS] Framework, Library RnD (0) | 2023.04.07 |
[iOS] pod dependency trouble shooting (0) | 2023.04.07 |
[iOS] 1st party framework์์ 3rd party framework ์ฌ์ฉ (0) | 2023.04.07 |
[iOS] Framework์ ์ข ์์ฑ ์ถ๊ฐ ์ ์์ ํ๊ฒฝ ์ธํ (0) | 2023.04.06 |