'No such module' when I use CocoaPods
IosXcodeSwiftCocoapodsIos Problem Overview
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
Ios Solutions
Solution 1 - Ios
Try adding the Pods
framework to your build scheme and building the framework. After you've built it, build/run your project.
Steps:
Solution 2 - Ios
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 :)
Solution 3 - Ios
You may also try re-installing pods using:
pod deintegrate
and then
pod install
This fixed this issue for me
Solution 4 - Ios
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.
Solution 5 - Ios
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'
Solution 6 - Ios
In my case it was because I opened xcodeproj
instead of the correct xcworkspace
.
Solution 7 - Ios
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.
Solution 8 - Ios
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
Solution 9 - Ios
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
Solution 10 - Ios
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.
Solution 11 - Ios
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.
Solution 12 - Ios
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.
Solution 13 - Ios
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
Solution 14 - Ios
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
Solution 15 - Ios
Adding link "c++" in the framework module.modulemap file worked for me
Solution 16 - Ios
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.
Solution 17 - Ios
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):
Solution 18 - Ios
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.
Solution 19 - Ios
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 :)
Solution 20 - Ios
Make sure to import correct framework name that is defined in .podspec
of the pod.
Solution 21 - Ios
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 myPre-configuration Build Products Path
to it .... AFTER doingpod 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 withpod install
. However, cocoapods hardcodes the build product path to${SRCROOT}/../build
andPre-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
andHeader Search Path
of my own project cover the above paths. - Tweak
Pods
project setting and all dependency Framework'sPre-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.
Solution 22 - Ios
I usually remove Pods
folder and .xcworkspace
file, then I run pod install
again and it helps in almost 100% cases.
Solution 23 - Ios
I get some warning when pod install: '... target overrides the FRAMEWORK_SEARCH_PATHS
build setting defined in ...'.
Fix it and enjoy.
Reference: https://stackoverflow.com/questions/26445784/target-overrides-the-framework-search-paths-build-settings.
Solution 24 - Ios
- clean project
- close xcode
- open xcode
- enjoy
Solution 25 - Ios
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"