iOS Fat Framework

유호준·2022년 4월 18일
0
post-thumbnail

SwiftUI와 Custom 프레임워크를 사용하고 있는데, 시뮬레이터가 되지 않아 너무 불편했다..그래서 fat framework를 생성해서 사용했고, 정리해보려고한다!

#Simulator
xcodebuild archive -workspace WORKSPACENAME.xcworkspace \
-scheme SCHEME_NAME \ 
-arch x86_64 \ #archtecture 제한시
-configuration Release -archivePath "./build/ios_sim.xcarchive" \
-sdk iphonesimulator SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \

#iphone
xcodebuild archive -workspace WORKSPACENAME.xcworkspace \
-scheme SCHEME_NAME \
-arch arm64
-configuration Release -archivePath "./build/ios_sim.xcarchive" \
-sdk iphoneos SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \

위 명령어를 터미널에 사용해서 아카이빙을 해준다.

xcodebuild -create-xcframework \
-framework build/ios.xcarchive/Products/Library/Frameworks/FRAMEWORK_NAME.framework \
-framework build/ios_sim.xcarchive/Products/Library/Frameworks/Frameworks/FRAMEWORK_NAME.framework \
-output build/Frameworks/FRAMEWORK_NAME.xcframework

#static 라이브러리 일시
xcodebuild -create-xcframework \
-library build/ios.xcarchive/Products/usr/local/lib/LIBRARY_NAME.a \      
-library build/ios_sim.xcarchive/Products/usr/local/lib/LIBRARY_NAME.a \
-output build/usr/LIBRARY_NAME.xcframework

그 후 위 명령어를 사용하면 아주 간단하게 Fat 프레임워크를 만들 수 있다!
하지만 Custom 프레임워크가 CocoaPods에서 추가적인 프레임워크를 사용하면 오류가 난다. 그럴 때는 Podfile 마지막에 아래와 같은 코드를 추가하면 오류가 사라진다.

post_install do |installer|
        installer.pods_project.targets.each do |target|
          target.build_configurations.each do |config|
            config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
          end
        end
      end

참고
https://dvlpr-chan.tistory.com/10

0개의 댓글