ios - Is this the correct way to create dynamic/embedded framework with embedded cocoa pods? -
i trying create dynamic framework share code among various extensions of app.
problem :
here project structure.
myframeworks network layer of app inherently uses alamofire. structured pod file follow.
platform :ios, '9.0' use_frameworks! workspace 'cocoapodsprojectworkspace' def shared_pods pod 'alamofire' pod 'swiftyjson' end target 'cocoapodsproject' project 'cocoapodsproject.xcodeproj' # pods cocoapodsproject end target 'myframework' project 'myframework/myframework.xcodeproj' shared_pods end target 'cocoapodsprojecttests' end target 'cocoapodsprojectuitests' end
on building framework when drag embedded binary main project error.
dyld: library not loaded: .framework/alamofire referenced from: /users/sandeep/library/developer/xcode/deriveddata/cocoapodsprojectworkspace-enpobdyluhbxdwazuvbfogcspfof/build/products/debug-iphonesimulator/myframework.framework/myframework reason: image not found
solutions tried :
- declaring pods_frameworks.framework optional in linked binaries.
- tried changing runpath search path of framework dynamic library
- install name running pod deintegrate , running pod install again.
- deleting derived data , relinking framework lead same problem.
solution worked :
i realized myframework.framework trying find alamofire.framework in wrong directory , alway trying search relative project/target using framework . simplest solution find modify pod file follow.
platform :ios, '9.0' use_frameworks! workspace 'cocoapodsprojectworkspace' def shared_pods pod 'alamofire' pod 'swiftyjson' end target 'cocoapodsproject' project 'cocoapodsproject.xcodeproj' shared_pods # pods cocoapodsproject end target 'myframework' project 'myframework/myframework.xcodeproj' shared_pods end target 'cocoapodsprojecttests' end target 'cocoapodsprojectuitests' end
as can see added shared_pods both main app , framework project , respective targets. works smooth. neither had make pods_framework optional nor had modify build settings of myframework.
question:
adding shared repos projects , targets wants use framework looks little redundant. there better way can specify myframework.framework read dependencies rather reading project using it?
i have raised issue same on cocoapods git repo. because isn't inherently issue might not revert back. hence posting question here.link issue : https://github.com/cocoapods/cocoapods/issues/6901 if helps.
solved creating cocoa pod custom framework , using cocoa pods dependency .
step 1 : clean main/parent project
- removed myframework project (which added sub project) , remove myframework.framework added in embedded library of projects general settings.
- run
pod deintegrate
(to de-integrate pod added to
project) - now project clean , not have pod added initialized pod running
pod init
step 2: create pod framework
- using cd command navigate myframework project , once in myframework's root folder run
pod spec create myframework
this create file named myframework.podspec in myframework's root folder. open myframework.podspec using of editor tool , update shown in tutorial https://www.raywenderlich.com/126365/ios-frameworks-tutorial
most important step not there in tutorial how add cocoa pods dependency our framework needs build. turns out thats easiest part. in case needed
swiftyjson
,alamofire
in .podspec file added,
s.dependency 'alamofire'
s.dependency 'swiftyjson'
step 3:
- now open main/parent projects
podfile
, update shown below.
target 'cocoapodsproject' use_frameworks! pod 'testframework', :path => 'testframework/' end
what did is, tells main project add testframework dependency , installs testframework in framework folder of main project. because testframework in has dependency alamofire
& swiftyjson
when run pod install
not install alamofire
installs swiftyjson
, adds testframework's
framework folder.
thats all. testframework can access alamofire
, swiftyjson
, main/patent project can access testframework
if want update testframework code, till u finish develop add subproject main project (this necessary because if open testframework.xcproj u won't see alamofire/swifty json. have open parent project's workspace hence solution). once u done development if u decide remove testframework subproject u can :)
finally if decide add additional extensions app, lets u add today extension u have modify ur podfile follow.
target 'cocoapodsproject' use_frameworks! pod 'testframework', :path => 'testframework/' end target 'cocoapodstoday' use_frameworks! pod 'testframework', :path => 'testframework/' end
woo hooo :) add frameworks many extensions want :) hope helps.
Comments
Post a Comment