Swift universal framework depending on pod
Finally I could accomplish it taking into account the advice given from @mag_zbc, thank you.
I had to modify the framework generation this way:
set -e
# Setup
WORKSPACE="${1}"
FRAMEWORK_NAME="${2}"
BUILD_DIR="${SRCROOT}/build"
OUTPUT_DIR="${HOME}/Desktop/"
OUTPUT="${OUTPUT_DIR}/${FRAMEWORK_NAME}.framework"
CONFIGURATION="${CONFIGURATION}"
rm -rf "${BUILD_DIR}"
rm -rf "${OUTPUT}"
mkdir -p "${OUTPUT_DIR}"
# Build the framework for device and for simulator (using all needed architectures).
xcodebuild -workspace "${WORKSPACE}" -scheme "${FRAMEWORK_NAME}" -configuration ${CONFIGURATION} -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator" clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator
xcodebuild -workspace "${WORKSPACE}" -scheme "${FRAMEWORK_NAME}" -configuration ${CONFIGURATION} -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos" clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
# Copy the device version of framework to output.
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework" "${OUTPUT}"
# Replace the framework executable within the framework with a new version created by merging the device and simulator frameworks' executables with lipo.
lipo -create -output "${OUTPUT}/${FRAMEWORK_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
# Copy the Swift module mappings for the simulator into the framework. The device mappings already exist from step 6.
cp -r "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${OUTPUT}/Modules/${FRAMEWORK_NAME}.swiftmodule"
# Delete build.
rm -rf "${BUILD_DIR}"
After generated, and added to the consumer app, the only thing left to do is to use Cocoapods in the consumer app to get Alamofire and SwiftyJSON.
iOS: How to build a static framework based on CocoaPods dependencies?
Solved the problem by simply feeding all the aggregated source files from the pod installation into a new static library, then using either the lipo command to make a fat binary out of it or creating an Xcode framework from it (as described here). The compiled framework could then be used to create another framework built on top of it.
adding a pod to a universal framework library using cocoapods
Here is my whole procedure
- crate a new swift app project.
- create a new cocoa touch framework target.
- in the project directory , run
pod init
Tyr This Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'SOQ' do
use_frameworks!
end
target 'SOQFW' do
use_frameworks!
end
pod 'EVReflection'
after pod install, in both my two targets SOQ (swift app) and SOQFW (cocoa touch framework) can import EVReflection
in *.swift and user class EVObject without a problem.
sample code is
import EVReflection
class User: EVObject {
var id: Int = 0
var name: String = ""
var friends: [User]? = []
}
you can give it a try.
My development environment is os x 10.12 , xode 8.2.1 , cocoapods 1.1.1
XCFramework with Pods Dependencies
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' => 'sample@sample.com' }
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
Related Topics
Exc_Bad_Access Using Ibinspectable
How to Execute a Function in a Uiviewcontroller Through a Swiftui Button
Using Haneke to Cache Then Play Mp4 Files with Avplayer
Use More Than One Firebase Database in Single App - Swift
Pausing Spritekit Game Using Appdelegate in iOS8
Getting Uiwebview API Deprecation Message After Adding Paypal Pod in My iOS App
Embedding a Uitableview as a Container View Within a Uiviewcontroller
Skspritenode Subclassing Swift
How to Create a Custom iOS Keyboard
How to Store Array in Nsuserdefault in Swift
Core Data Taking Time to Insert Records with Fetching Entity & Set as Relationship
How to Hide API Keys in Github for iOS (Swift) Projects
Show Bounding Box While Detecting Object Using Arkit 2
Creating Tableview Sections from JSON Data Swift 4
Saving Already Created Live Photos
iOS Media Playback Controls Notification
How to Trigger an API Call Before Displaying Local Notifications