ios dev kangwook.

iOS) CocoaPods에 Private Framework 추가해서 배포하기 본문

iOS

iOS) CocoaPods에 Private Framework 추가해서 배포하기

kangwook 2022. 10. 29. 22:56

https://kvngwxxk.tistory.com/9

 

 

iOS) CocoaPods에 Private Framework 추가하기

iOS를 하면서 가장 많이 쓰는 툴이라고 하면 단연코 CocoaPods이라고 할 수 있겠다. 하지만 내가 직접 만든 프레임워크를 CocoaPods을 통해서 내 다른 프로젝트에서 쓴다던가, 모듈화 시켜서 CocoaPods에

kvngwxxk.tistory.com

오늘은 저번에 썼던 Private Framework를 배포하는 글에 더해 public으로 배포하는 방법, 그리고 가장 중요한 것들에 대해서 한 번 더 정리하려고한다. 스크린샷을 위 링크를 참고하길 바란다!


프로세스

  • Framework를 위한 Git Repository 생성
    • Readme, 라이센스 파일도 생성해 주어야 함
  • Podspec을 위한 Git Repository 생성
    • Readme 생성
  • Framework Repository clone
  • clone한 디렉토리에 Xcode Project(Framework) 생성 후 작성
    • 간단한 예시로 LogManager 작성
  • xcarchive 빌드 → xcframework 빌드
    • 별개로 빌드할 수 있으나 script를 사용하면 간편하게 iphone, simulator용 모두 빌드할 수 있음
xcodebuild archive \
-scheme MyFramework \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath './build/MyFramework.framework-iphoneos.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES

xcodebuild archive \
-scheme MyFramework \
-configuration Release \
-destination 'generic/platform=iOS Simulator' \
-archivePath './build/MyFramework.framework-iphonesimulator.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES


xcodebuild -create-xcframework \
-framework './build/MyFramework.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/MyFramework.framework' \
-framework './build/MyFramework.framework-iphoneos.xcarchive/Products/Library/Frameworks/MyFramework.framework' \
-output './build/MyFramework.xcframework'
  • Framework를 clone했던 디렉토리에 podspec 파일 생성
    • podspec 파일의 이름이 프레임 워크의 이름
pod spec create MyFramework
  • 디렉토리 구조
    • my-framework : 가장 처음 git clone한 디렉토리
    • ㄴ MyFramework : 소스파일이 존재하는 프로젝트 디렉토리
    •       ㄴ build : xcarchive, xcframework가 존재하는 빌드 output 디렉토리
  • podspec 파일 수정
    • 필수 작성 요소
      spec.source_files을 주석처리하고 spec.vendored_frameworks를 추가
      → spec.version과 git tag, 작성했던 framework 버전이 모두 같아야함(매우 중요)
Pod::Spec.new do |spec|
  spec.name         = "MyFramework"
  spec.version      = "0.0.1"
  spec.summary      = "This is test pod spec for private framework."
  spec.description  = <<-DESC
  This is test pod spec for private framework. 
  This is description of the spec.
  This is made by Kangwook Lee.
                   DESC

  spec.homepage     = "https://gitlab.linker.ac/kangwook"
  spec.license      = { :type => "MIT", :file => "LICENSE" }


  spec.author             = { "kangwooklee" => "kngwk.bsns@etoos.com" }

  spec.platform     = :ios
  spec.platform     = :ios, "13.0"

  spec.source       = { :git => "https://gitlab.linker.ac/kangwook/my-framework.git", :tag => "0.0.1" }
  spec.vendored_frameworks = "MyFramework/build/MyFramework.xcframework"

end
  • Git에 tag 생성 후 tag push & Git에 코드 push
git tag 0.0.1
git push --tags

git add .
git commit -m "initial commit"
git push origin main
  • pod spec lint를 통해 pod repo에 push할 수 있는지 validation 확인
    • Test 중 버전 업을 했기 때문에 아래 예시는 태그가 0.0.3 → 프로세스대로 진행했다면 보이는 버전은 0.0.1
    • The "vendored_frameworks" pattern did not match any file. 에러가 발생한다면 위에서 언급한 버전들이 모두 맞는지 확인해야 함
    • warning의 경우 --allow-warning으로 무시 가능 → 보통 iOS 타겟에 대한 경고가 뜸(무시 가능)
  • podspec을 저장할 pod repo 생성
    • 첫 번째에는 pod repo의 이름, 두 번째에는 2번에서 만들었던 podspec의 git주소를 넣어주면 됨
pod repo add MyPodSpec https://gitlab.linker.ac/kangwook/my-podspec.git
  • podspec 파일 pod repo에 push
    • validation이 정상적으로 통과되었다면 pod repo push도 정상적으로 진행
pod repo push MyPodSpec MyFramework.podspec
  • 프레임워크를 CocoaPods으로 적용시킬 새로운 프로젝트 생성
  • 해당 프로젝트 디렉토리에서 터미널을 열고 pod init
  • podfile 수정
    • platform의 경우 프레임워크와 프로젝트의 사양이 맞아야함
    • source 의 경우 podspec git으로 지정해주고, pod MyFramework는 프레임워크 git으로 지
platform :ios, '13.0'
source 'https://gitlab.linker.ac/kangwook/my-podspec.git'
workspace 'EtoosSdkDevelopmentWorkspace'
target 'EtoosSdkDevelopmentApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for EtoosSdkDevelopmentApp
	pod 'MyFramework', :git => 'https://gitlab.linker.ac/kangwook/my-framework.git'
	
  # target 'EtoosSdkDevelopmentAppTests' do
  #  inherit! :search_paths
  #  # Pods for testing
  # end

  # target 'EtoosSdkDevelopmentAppUITests' do
  #   # Pods for testing
  # end

end
  • pod install
  • 프로젝트에서 pod으로 install한 프레임워크 테스트

변경사항으로 인해 Fix할 경우

  • 코드 수정하고 Framework 버전 변경 후 push
  • git tag 생성 후 push
  • podspec version 수정 후 pod repo update
  • pod update
    • 만약 pod update가 되지 않는다면 지정해서 update 해주면 됨
pod update MyFramework
  • 에러 뜰 경우에는 pod 제거 후 캐시 지우고 재설치 시도
    • deintegrate 설치하면 유용하게 사용할 수 있음
sudo gem install cocoapods-deintegrate cocoapods-clean
pod deintegrate
pod cache clean --all
pod install

Trunk에 Push 후 배포하기

  • trunk에 등록하기
pod trunk register [이메일 주소] [계정 이름] --description='계정 설명'
  • 이메일이 오는데, 링크 클릭 → 인증 완료
  • trunk에 push
pod trunk push MyFramework.podspec
  • 기존 프로젝트 podfile로 설치
platform :ios, '13.0'
workspace 'EtoosSdkDevelopmentWorkspace'
target 'EtoosSdkDevelopmentApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for EtoosSdkDevelopmentApp
  # Trunk에 올라갈 때 이미 존재하는 프레임워크와 중복된 이름을 사용할 수 없음
	pod 'MyLogManagerSample'
	
  # target 'EtoosSdkDevelopmentAppTests' do
  #  inherit! :search_paths
  #  # Pods for testing
  # end

  # target 'EtoosSdkDevelopmentAppUITests' do
  #   # Pods for testing
  # end

end
  • 적용 완료

기타

Comments