Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
823 views
in Technique[技术] by (71.8m points)

ios - XCFramework with Pods Dependencies

Our goal is to create a framework that hides our internal code and provide SDK to our customers. We have thought of creating XCFramework which fulfills our requirement. Umbrella framework is also suggested over the internet but mostly suggested to avoid that approach. Our Framework is dependent on some third-party libraries which we are using via Pods.

Issue: XCFramework does not compile pods framework. We got an error like "Xyz(Pod) module not found". Even if we add pods from the client-side it does not work.

Code to create XCFramework is as bellow

1) Create an archive for iOS platform

xcodebuild archive -workspace ABC.xcworkspace 
  -scheme ABC 
  -sdk iphoneos 
  -archivePath "./archives/ios_devices.xcarchive" 
  BUILD_LIBRARY_FOR_DISTRIBUTION=YES 
  SKIP_INSTALL=NO

2) Create an archive for iOS-Simulator platform

  xcodebuild archive  -workspace ABC.xcworkspace 
  -scheme ABC 
  -sdk iphonesimulator 
  -archivePath "./archives/ios_simulators.xcarchive" 
  BUILD_LIBRARY_FOR_DISTRIBUTION=YES 
  SKIP_INSTALL=NO

3) Create an XCFramework from Archives

xcodebuild -create-xcframework 
-framework ./archives/ios_devices.xcarchive/Products/Library/Frameworks/ABC.framework 
-framework ./archives/ios_simulators.xcarchive/Products/Library/Frameworks/ABC.framework 
-output build/ABC.xcframework

We got ABC XCFramework successfully but dependencies are not included in XCFramework. Any solution for this? or Is there any way where we can set framework search path to client-side? or Any alternate approach?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can create a pod and publish it.

Check https://guides.cocoapods.org/making/making-a-cocoapod.html

Sample Podspec file with XCFramework + Third party dependency

Pod::Spec.new do |s|  
    s.name              = 'XCFrameworkTest' # Name for your pod
    s.version           = '0.0.1'
    s.summary           = 'Sample Spec'
    s.homepage          = 'https://www.google.com'

    s.author            = { 'Sample' => '[email protected]' }
    s.license = { :type => "MIT", :text => "MIT License" }

    s.platform          = :ios
    # change the source location
    s.source            = { :http => 'http://localhost:8080/XCFrameworkTest.zip' } 
    s.ios.deployment_target = '10.0'
    s.ios.vendored_frameworks = 'XCFrameworkTest.xcframework' # Your XCFramework
    s.dependency 'PromisesSwift', '1.2.8' # Third Party Dependency
end 

After you publish your pod, Customer can use cocopods to get our framework.

In Customer's Podfile

pod 'XCFrameworkTest' #Your pod name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...