본문 바로가기

iOS/Swift

third party library into private cocoapods module

private cocoapods library로 모듈화할때 third party libarary를 참조하는 경우 외부 프로젝트에서 사용하는 방법 

 

cocoapodsd library not find 오류 해결

[!] Unable to find a specification for `Alamofire`

 

private cocoapods libarary에서 dependency로 추가한 third party library를 외부 프로젝트에 설치하려는 경우에 발생한 오류 해결 방법 


이전 글에서 cocoapods를 이용해 private pods library를 만들어 github로 배포하는 방법에 대해 작성하였다.

이후 만든 pod library를 통해 third party library인 Alamofire로 api 통신 함수를 모듈화하여 배포하려고 아래와같이 podspec 파일에

dependency를 추가하여주었다.

 

s.dependency 'Third-Party-Libaray-Name' 

# TestLib.podspec
# Be sure to run `pod lib lint TestLib.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = 'TestLib'
  s.version          = '0.1.10'
  s.summary          = 'A short description of TestLib.'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://github.com/username/TestLib' #POD REPO git 경로
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'username' => 'githubAccount@email.co.kr' }
  s.source           = { :git => 'https://github.com/username/TestLib.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '15.0'
  s.swift_version = '4.0'

  s.source_files = 'TestLib/Classes/**/*'
  
  # s.resource_bundles = {
  #   'TestLib' => ['TestLib/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  s.dependency 'Alamofire'
end

 

 

Utils.swift 클래스에 Api 통신을 위해 Alamofire libarary를 추가하고 코드를 작성하였다.

이렇게 외부 libarary를 사용하는 경우 podspec 파일에 dependency를 추가하지 않으면 배포시 오류가 발생한다.

 

github에 새로운 버전으로 배포하였고 새로운 프로젝트의 podfile에 사용하려는 외부 libraray를 추가하였다.

(배포 방법은 이전에 작성한 글에서와 참고 - 2023.07.10 - [iOS/Swift] - create module with private cocoapods )

 

podfile에 third party libaray 추가

그리고 pod install을 실행하자 third party libaray를 찾을 수 없다는 오류가 발생하였고 3일 검색 끝에 허무하게 해결하였다.

[!] Unable to find a specification for `Alamofire`

 

private cocoapods 모듈을 사용할 외부 프로젝트의 podfile을 아래처럼 작성해주면 된다.