I am trying to create a Dynamic Framework to share the code among various extensions of my app.
Problem :
Here is my project structure.
MyFrameworks is a network layer of my app which inherently uses Alamofire. So structured my pod file as follow.
platform :ios, '9.0'
use_frameworks!
workspace 'CocoaPodsProjectworkspace'
def shared_pods
pod 'Alamofire'
pod 'SwiftyJSON'
end
target 'CocoaPodsProject' do
project 'CocoaPodsProject.xcodeproj'
# Pods for CocoaPodsProject
end
target 'MyFramework' do
project 'MyFramework/MyFramework.xcodeproj'
shared_pods
end
target 'CocoaPodsProjectTests' do
end
target 'CocoaPodsProjectUITests' do
end
On building the framework when I drag it as embedded binary to my Main project I get the 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 I tried :
Declaring the pods_frameworks.framework as optional in linked
binaries.
Tried changing RunPath Search path of framework Dynamic Library
Install name Running pod deintegrate and running pod install again.
Deleting derived data and relinking framework all lead to same
problem.
Solution that worked :
I realized that MyFramework.framework was trying to find the Alamofire.framework in a wrong directory and it was alway trying to search relative to project/target using the framework . So the simplest solution that I could find was to modify pod file as follow.
platform :ios, '9.0'
use_frameworks!
workspace 'CocoaPodsProjectworkspace'
def shared_pods
pod 'Alamofire'
pod 'SwiftyJSON'
end
target 'CocoaPodsProject' do
project 'CocoaPodsProject.xcodeproj'
shared_pods
# Pods for CocoaPodsProject
end
target 'MyFramework' do
project 'MyFramework/MyFramework.xcodeproj'
shared_pods
end
target 'CocoaPodsProjectTests' do
end
target 'CocoaPodsProjectUITests' do
end
As you can see I added the shared_pods to both main app and my framework project and their respective targets. Now everything works smooth. I neither had to make pods_framework optional nor had to modify the build settings of MyFramework.
Question:
Adding the shared repos to all the projects and their targets which wants to use my framework looks little redundant. Is there a better way I can specify Myframework.framework to read all its dependencies rather than reading from project using it?
I have raised a issue for the same on CocoaPods Git repo. But because it isn't inherently a issue they might not revert back. Hence posting it as a question here.Link to issue : https://github.com/CocoaPods/CocoaPods/issues/6901 if it helps.
Solved it by creating a cocoa pod for my custom Framework and using cocoa pods dependency .
Step 1 : Clean the Main/Parent project
Removed MyFramework from the project (which was added as sub
project) and remove MyFramework.framework added in embedded library of projects General settings.
Run pod deintegrate (to de-integrate the pod already added to
project)
Now that the project is clean and does not have any pod added
initialized the pod by running pod init
Step 2: Create a Pod for my Framework
Using cd command navigate to MyFramework project and once you are in
MyFramework's root folder run pod spec create MyFramework
This will create a file named MyFramework.podspec in the
MyFramework's root folder. Open MyFramework.podspec using any of the
editor tool and update it as shown in tutorial https://www.raywenderlich.com/126365/ios-frameworks-tutorial
Most important step which is not there in this tutorial is how to add
cocoa pods dependency that our framework needs to build. Turns out
thats the most easiest part. In my case I needed SwiftyJSON and
Alamofire so in .podspec file I added,
s.dependency 'Alamofire'
s.dependency 'SwiftyJSON'
Step 3:
Now open the Main/Parent projects Podfile and update it as shown
below.
target 'CocoaPodsProject' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
What it did is, it tells main project to add TestFramework as dependency and installs TestFramework in Framework folder of main project. Because TestFramework in itself has dependency to Alamofire & SwiftyJSON when you run pod install it will not only install Alamofire but also installs SwiftyJSON and adds it to TestFramework's Framework folder.
Thats all. Now your TestFramework can access Alamofire and SwiftyJSON and Main/Patent project can access TestFramework
If you want to now update TestFramework code, till u finish develop add it as subproject to Main project (This is necessary because if you open TestFramework.xcproj u won't see Alamofire/Swifty JSON. You have to open the Parent project's workspace itself hence this solution). Once u are done with development if u decide to remove the TestFramework as subproject u can do that :)
Finally If you decide to add additional extensions to app, Lets say u add Today extension all u have to do is to modify ur Podfile as follow.
target 'CocoaPodsProject' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
target 'CocoapodsToday' do
use_frameworks!
pod 'TestFramework', :path => 'TestFramework/'
end
Woo hooo :) Now add your frameworks to as many extensions you want :) Hope it helps.
I'm using framework targets (for better code reuse and IB_Designables), and I've already had a framework target working perfectly. I've decided to move some other classes to a framework target too.
I've set up the pods (just a single one in this case), but whenever I try to include the pod I'm getting not found error.
No change if I try to use the modules approach too:
The problem is that I've already got another framework too, with the same settings (cross checked all the compiler settings/linker flags/build phases etc) and that framework has no issue importing its pods.
Here is my podfile (TUComponents is the working on, TUModels is the failing one):
[...]
target 'TUComponents' do
pod 'AHKNavigationController'
pod 'TTTAttributedLabel'
use_frameworks!
end
target 'TUModels' do
pod 'JSONModel'
use_frameworks!
end
Even weirder; Xcode has no problem code-completing importing the JSONModel/JSONModel.h header (or JSONModel in case of module #import). But when I try to compile, it fails.
What might be wrong with my configuration?
UPDATE: If I give up using frameworks in pods and use regular old static library, and set allow non-modular includes in frameworks to YES, I can build. But I have no idea why I can't build when using Pod frameworks.
Maybe try solution from: https://www.natashatherobot.com/cocoapods-installing-same-pod-multiple-targets/
platform :ios, '9.0'
use_frameworks!
# My other pods
def testing_pods
pod 'JSONModel'
end
target 'TUComponents' do
pod 'AHKNavigationController'
pod 'TTTAttributedLabel'
testing_pods
end
target 'TUModels' do
testing_pods
end
From iOS - Build fails with CocoaPods cannot find header files :
Make sure your Podfile includes link_with on targets missing a config file. Cocoapods only sets the first target by default otherwise. e.g.
platform :osx, '10.7'
pod 'JSONKit', '~> 1.4'
link_with 'Pomo', 'Pomo Dev', 'Pomo Tests'
Restarting Xcode fixed it for me
The following steps worked in my case:
Quit the Xcode n Simulator
Delete Drived data
Again open your project
Clear it
I am getting an error when building my app after i removed reference to a framework i added incorrectly. i am new to ios and cocoapods
/Users/MyMac/Library/Developer/Xcode/DerivedData/MyApp-ewxrexwuczochyctnqvlyusrtvvy/Build/Intermediates/MyApp.build/Debug-iphonesimulator/MyApp.build/Script-5874133373474758EEC76CFD.sh: line 2: /Users/MyMac/Documents/MyApp/Pods/Target Support Files/Pods-MyApp/Pods-MyApp-frameworks.sh: No such file or directory
I am aware that the file and directory don't exist and that is the way it should be but where is it finding the reference to this file so i can remove it and be rid of the error.
I have checked the following:
Linked Frameworks andLibraries under the general tab of my project
The frameworks group in the project
framework search paths under build settings tab
i have also run pod update after removing it from the pod file
How can i fix this?
Edit
back story
I was trying to add the framework https://github.com/Alliants/ALAccordion . in the instruction it said to use
# Podfile
target 'My Target' do
use_frameworks!
pod "ALAccordion"
end
so i added MyApp where my Target is and it created a framework named Pods-MyApp which i cant remove completely.
hope this helps
Cocoapods wrote a tool to completely deintegrate all of this stuff from your project so it goes back to running standalone. It sounds like you had an issue adding the correct target, so use this:
https://github.com/CocoaPods/cocoapods-deintegrate
Then try again so you can at least start from good ground. Hope this helps!
It happened with a prerelease version of Cocoapods 1.2.0.beta.1, by reverting to stable version and running pod install, then clean build, it worked.
why
use_frameworks!
after
target ... do
here is example
platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!
target 'XXX' do
pod 'RealmSwift'
end
target 'XXXTests' do
pod 'RealmSwift'
end
So here's my procedure. I create a new Podfile in the project directory, then I added the following
platform :ios, '9.0'
use_frameworks!
target 'CPod' do
pod 'AFNetworking', '~> 2.5'
pod 'ORStackView', '~> 2.0'
pod 'SwiftyJSON', '~> 2.1'
end
I fire off pod install, and everything goes well, open up the xcworkspace. I then go over to ViewController.swift and if I try to import a pod I get No such module 'SwiftyJSON', if I were to do import SwiftyJSON. Any ideas?
EDIT: SwiftyJSON is a Swift based module, not Obj-C
Try adding the Pods framework to your build scheme and building the framework. After you've built it, build/run your project.
Steps:
Scheme menu > Manage Schemes > check Pods > Close
Select Pods from the scheme menu.
Build Pods.
Select your project from the same menu, then build/run it.
You must reopen project .xcworkspace file(not .xcodeproj) after install your podfile.
Clone the repo with CocoaPods
Open YourWorkspace/YourApplication.xcworkspace
Select the app u want to run Add SwiftyJSON.framework in embedded
binaries for that project Hit Run
Happy Coding :)
You may also try re-installing pods using:
pod deintegrate
and then
pod install
This fixed this issue for me
Press Command+Option+Shift+K and then Run your app, you will see a magic.
Or from the menu -> Product, press Option on your keyboard and you'll see Clean Build Folder.
It's looking funny that how could Xcode do those things with us but same thing happened to me when I used a Swift library using Pod and after too much struggle I ended up with Clean Build Folder.
Not sure if this would still be helpful for others. But, in my case, it ended up being a silly mistake of not referencing dependencies from the .podspec file.
We have an application with multiple internal libraries, and those libraries also have dependencies on each other - which we accounted for the in the Podfiles... but NOT in the podspecs.
So, even though our Podfiles had:
Application / Podfile
# Development Pods
pod 'ConsumingLibrary ', :path => '../ios-consuming-lib'
pod 'DependentLibrary1', :path => '../ios-library-one'
pod 'CommonCoreLibrary', :path => '../ios-common-core-lib'
ConsumingLibrary / Podfile
# Development Pods
pod 'DependentLibrary1', :path => '../ios-library-one'
pod 'CommonCoreLibrary', :path => '../ios-common-core-lib'
Needed to also call it out in the .podspec's:
ConsumingLibrary / ConsumingLibrary.podspec
# TODO
# Add here any resources to be exported.
s.dependency 'DependentLibrary1', '~> 0.1.0-RC'
DependentLibrary1 / DependentLibrary1.podspec
# TODO
# Add here any resources to be exported.
s.dependency 'CommonCoreLibrary', '~> 0.1.0-RC'
I think I wasted about 2 hours trying to figure out why I could build ConsumingLibrary & run tests, but as soon as I built the app, that consumed all three libraries - I kept getting:
No such module 'DependentLibrary1'
In my case it was because I opened xcodeproj instead of the correct xcworkspace.
Had this issue, too. I noticed the folder in Pods/broken_framework_name for framework which produced an error was empty even after pod install or pod update. So, for me those steps helped:
close XCode completely
remove DerivedData
remove Podfile.lock. Before doing it, make sure your pods are set to specific versions and it will not cause unwanted code updates
run pod deintegrate
remove .xcworkspace file
probably optional step: I had general line use_frameworks! written before all targets, but included it also in target in which I had an error
run pod install
After all steps I noticed missing framework files finally appeared back and build was working again.
Try using pod update after pod install command which will solve problem of No such module.
I just tried and it working fine.
Thanks,
Ratneshwar
Those who working with multiple targets , please don't forget to add this line in pods
def shared_pods
pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'
end
target 'Target_Name' do
shared_pods
end
target 'Target_Name_Two' do
shared_pods
end
Sometimes happens when you have an obj-c pod within a swift project (even when you use the use_frameworks! in the .podfile).
If you're sure the pod is installed and you are still getting No such module, try this:
Go to Pods project in Xcode
Pods
Right click on the affected pod
Show in finder
There should be a package file with .framework suffix. Create a folder Modules in it. In this folder create a file called module.modulemap with code:
framework module MODULE_NAME_HERE {
umbrella header "MODULE_NAME_HERE.h"
export *
module * { export * }
link framework LINKED_FRAMEWORKS_AND_LIBRARIES_THE_POD_NEEDS_HERE
link framework "AdSupport"
link "c++"
link "z"
}
Rebuild and you should be ok.
As #jakub-truhlář wrote, the root issue is the missing module.modulemap file due to some concurrency issue mixing Swift and Objective-C libraries, but instead of creating those files manually, would be better to try multiple times cleaning the Derived Data and build your project. When the project is successfully built then commit module.modulemap files to your repository to avoid to lose those files for example changing the current branch.
I faced the same problem in a swift framework I developed. The framework had a dependency of git project and the framework itself added as a pod to my main project. So, ideally the dependency has been specified in podspec file and Podfile as well.
I didn't faced the problem when accessing through the my main project but when I open the framework standalone it was throwing "No such module" error.
The root cause is, the base configurations is set with the path which points towards my main project instead of the framework itself because I ran podinstall first in my main project and then in the framework project.
Eg: in the project file it was like
0091AB0C861D71C94ADD7240 /* Pods-myframework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-myframework.release.xcconfig"; path = "../../Apps/MyMainProject/Pods/Target Support Files/Pods-myframework/Pods-myframework.release.xcconfig"; sourceTree = ""; };
After doing the below mentioned fix,
4444F5B1B35F066E57F96782 /* Pods-myframework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-myframework.release.xcconfig"; path = "Pods/Target Support Files/Pods-myframework/Pods-myframework.release.xcconfig"; sourceTree = ""; };
To fix the error,
Project file -> Configurations -> Set all the configurations set to
none.
Remove Pods folder and Podfile.lock.
Run 'pod install' first in the framework project direcory and then do pod install in main project directory.
I get some warning when pod install: '... target overrides the FRAMEWORK_SEARCH_PATHS build setting defined in ...'.
Fix it and enjoy.
Reference: target overrides the FRAMEWORK_SEARCH_PATHS build settings.
Another way this issue can manifest: if you have multiple targets with different platforms (e.g. iOS and watchOS) you need to make sure your podfile specifies the correct platform for each target. Otherwise Cocoapods might be building the right pod but for wrong platform, leading to the "no such module" error.
You can fix it just by specifying the correct platforms e.g.
# global platform
platform :ios, '11.0'
target 'My Framework' do
use_frameworks!
pod 'RxSwift', '~> 5.1'
end
target 'My Framework (watchOS)' do
# override global platform for this target
platform :watchos, '4.0'
use_frameworks!
pod 'RxSwift', '~> 5.1'
end
i fixed it by check "Find Implicit Dependencies" to true.
Go to Edit Scheme -> Build Tab -> set Find Implicit Dependencies = true.
and rebuild.
Adding link "c++" in the framework module.modulemap file worked for me
I had this problem when I opened XCode and then selected the workspace of my project via file->open recent.
I found that I had two .xcworkspace files on my filesystem for the same workspace/project.
Opening XCode by double clicking on the correct .xcworkspace file did the trick.
The correct one is the one that works.
I later deleted the wrong one.
I just updated particular dependencies in terminal
Go to project folder then run below command
pod update your pod name
For me I need to do
pod update ReachabilitySwift
Had this issue while adding CocoaPods into an old project, which already had manually included libs from before. It happened because Xcode was not resolving to the Framework Search Path generated by CocoaPods because of values previously set in target's settings.
Solution that helped me:
copy the old path
hit delete to completely clear the Framework Search Path settings in the target's column - the path, generated by CocoaPods would appear there
add the old search path back under the generated one (only needed if you still have some manually added frameworks to work with)
Clean project, wipe Derived Data, build.
The result would look like this (1st line added by Xcode, 2nd added by CocoaPods, and 3rd is manual):
In case of multiple targets.
For eg. Target1, Target2
use_frameworks!
target 'Target1' do
pod 'Fabric'
pod 'Crashlytics'
target 'Target2' do
end
end
Then run pod install.
I tried all of these suggestions but nothing worked for me. Instead what'd worked for me was deintegrating pods. Afterwards deleting the pods folder from xcode hierarchy and doing pod install. Suddenly it worked. Don't ask me why because anyways most of these suggestions are hit or miss anyways but I'll be happy if it works for someone else too :)
Make sure to import correct framework name that is defined in .podspec of the pod.
I usually remove Pods folder and .xcworkspace file, then I run pod installagain and it helps in almost 100% cases.
My setup
macOS 10.14 Mojave
Xcode 10.3
cocoapods 1.7.5
None of the answers work for me, although some gave partial clues. In my case, the root cause was that I customized my build product paths after running pod install.
If you run cocoapods right after creating an Xcode project, then it usually works if you open the generated Xcode .xcworkspace instead of the .xcodeproj.
Funny things happen if you start tweaking your build product paths after generating the workspace. Because the generated Pods project and its target all refer to your old Xcode project settings.
In my case, my trouble came from:
I prefer all my build products sitting under the project folder $(SRCROOT)/build/$(CONFIGURATION)/$(EFFECTIVE_PLATORM_NAME). So I went ahead and changed my Pre-configuration Build Products Path to it .... AFTER doing pod install.
Now, the generated Pods project, including all its Framework target, still points to the old location, so both the header import and linking of your own project will fail (you'd see Command PhaseScriptExecution failed with a nonzero exit code when No such module is fixed).
The fix:
Delete all Pods stuff including the workspace.
Regenerate Pods project and workspace with pod install. However, cocoapods hardcodes the build product path to ${SRCROOT}/../build and Pre-configuration Build Products to $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) in my case, which usually points to a temporary ~/Library/Developer subfolder . Still not quite right. Then ....
Make sure the Framework Search Path and Header Search Path of my own project cover the above paths.
Tweak Pods project setting and all dependency Framework's Pre-configuration Build Products Path to use my preferred paths.
The moral lesson: Always regenerate Pods and verify the key result paths whenever you touch paths in Xcode project settings.
UPDATE
With Xcode 11, Apple finally removed the confusing "Pre-configuration Build Products Path". To customize the build product paths, use Locations in Xcode preferences with global relative paths pre-baked.
If you see this warning:
[!] The `Joint [Debug]` target overrides the `FRAMEWORK_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-Joint/Pods-Joint.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `Joint [Release]` target overrides the `FRAMEWORK_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-Joint/Pods-Joint.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
follow the instructions to avoid Module not found issue.
For me, removing the following from my podFile fixed it:
installer.pods_project.build_configurations.each do |config|
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
clean project
close xcode
open xcode
enjoy
For using Swift in Objective-C, you should import a header file that Xcode generates automatically in compile time (NameOfModule+Swift.h). In this case, you should try import SwifityJSON in you header file like this:
#import "SwiftyJSON-Swift.h"