Cocoapods + Cannot load underlying module for 'x'
IosSwiftAfnetworkingCocoapodsAlamofireIos Problem Overview
I am running XCode 7, Swift 2.0, iOS 9.
I want to install Alamofire in my project using Cocoapods. I have done the following:
gem install cocoapods
pod setup
pod init
Updated Podfile to:
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
use_frameworks!
target 'JSONeg' do
pod 'Alamofire', :branch => 'swift-2'
end
Then I installed the pod:
pod install
And I added the following to ViewController.swift
import Alamofire
This raises the following error:
Cannot load underlying module for 'Alamofire'
I tested with another pod and it raised the same error, so I guess the problem is with the installation of Cocoapods. Any help would be greatly appreciated.
Ios Solutions
Solution 1 - Ios
This seems to be a bug in XCode. I had the same problem, and as described in the comments of another answer to this question, building the project made the error go away.
Solution 2 - Ios
Solution 3 - Ios
This worked for me:
- Close your project
- In terminal go to your project directory
- Add this command: pod update
- After that all your pods will be updated. Just run your project
Solution 4 - Ios
Cannot load underlying module for 'x'for SWIFT :
How to fix the Issue:
step:1 Create a New project and build&run Successfully without installing pod.
step:2 After build&run the Project Successfully ,Now try to install pod and then try to importrealm,alamofire,charts etc it will work like a charm.
Failure Case --> New project -> Add (realm,alamofire,charts etc) via cocoapods w/o building first -> open Xcode workspace -> build&run
Success Case -->New project -> build&run -> add (realm,alamofire,charts etc)via cocoapods -> open Xcode workspace -> build&run again = success
Solution 5 - Ios
Once you have installed Alamofire pod.
Step.1 you should open your project by double click on your_project_name.xcworkspace file.
Step.2 Go to project settings --> Build Phases --> Link Binary with Libraries --> Add framework "Alamofire.framework"
Thats it!!
Now you can import the module
Solution 6 - Ios
I tried all of these solutions: Re-building, Cleaning, Re-installing the pods, etc., but In my case, it was a problem of changing my 'Build Active Architecture Only' setting to 'No', due to an AR library I was using. Changed it back to 'Yes' and it was fixed. Hope this helps somebody.
Solution 7 - Ios
What has helped in my case:
-
Close the project and XCode
-
In the terminal repeat command
> pod install
-
Open the project
(If it does not help, try to remove Pod/ folder before reinstalling)
Solution 8 - Ios
I had to do a Product > (Opt Click) Clean Build Folder ... then ran again and the issue was gone.
Solution 9 - Ios
I am on Xcode Version 8.3.1 (8E1000a). Somehow this problem occurs when I wanted to pod install SwiftCloudant module. Probably I did not close my Xcode when I run pod install.
I fixed this manually adding the SwiftCloudant.framework in the Targets > General tab.
Solution 10 - Ios
Im my case it was a different reason, it was the Other swift flags in my targets build setting, i had to add inherited flag to the top.
Solution 11 - Ios
Have you checked if you have a recent version of Cocoapods ? You can update by either updating all your gems :
sudo gem update
or just reinstall Cocoapods:
[sudo] gem install cocoapods
If that doesn't help take also a look at : https://stackoverflow.com/questions/30804866/cocoapods-build-for-ios-9-swift-2-with-xcode-beta
where is shows you how to easily change the Command-Line tools version in the Xcode Preferences "Locations" tab, and change "Command Line Tools" to Xcode 7.0.
Solution 12 - Ios
Follow the steps:
1.Install pods 2.Open workSpace 3.Run/build your application 4.Then you can import the framework
Solution 13 - Ios
Could not load underlying module
- Check framework path:
Build Settings -> Framework Search Paths
. - Make sure the path to a framework contains no space.
- If the path contains a variable, find the value of the variables by searching the variable name in your
Build Settings
. - Make sure the value of the variables contains no space.
- If the path contains spaces, rename those directories that contain spaces.
- Clean and build the project.
In summary, make sure your <Project Root>
path contains no space. Otherwise, rename the dir
that contains spaces, then clean and build your project.
e.g. If this is your project root: /Users/handsomeboy/ios app/Fancy App/
, rename the folder that has spaces. One way to get rid of the space: change 'ios app'
to 'ios_app'
Solution 14 - Ios
Setting GCC_SYMBOLS_PRIVATE_EXTERN
(displayed as "Symbols Hidden by Default" in target settings) to YES
in framework being linked helped me to get rid of this error. I've spent 2 days to find this out, hope it will help someone :)
Solution 15 - Ios
At this URL: https://github.com/Alamofire/Alamofire/issues/441
One of the users wrote this:
Clean did not work, re-installing from pods did not work, installing from carthage did not work, manual install did not work. I finally got it to work after Build for Testing.
So i tried this (xcode Version 9.2 (9C40b)):
It did work for me. Error gone now.
Note: My pod was not Alamofire so i guess it will work for every Pod.
Solution 16 - Ios
Another possible scenario: make sure the test target is defined within the scope of the parent target (not outside of it)
e.g.
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
end
If instead it looks like:
target 'MyApp' do
pod 'GoogleAnalytics', '~> 3.1'
end
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
then you'll also receive this error.
Solution 17 - Ios
Same issue for me. I solved that by removing Alamofire version in pod file.
Pod file as
# Uncomment this line to define a global platform for your project
platform :ios, "8.0"
# Uncomment this line if you're using Swift
use_frameworks!
target 'GettingSwift' do
pod 'Alamofire'
end
target 'GettingSwiftTests' do
end
Solution 18 - Ios
In my case:
1. Comment line of //import Pod_Module
2. Go to Project -> Clean or use shortcut key (Command+Shift+K)
2. Close your project
3. In terminal go to your project directory
4. run > pod install
5. open .xcworkspace
file and build it!
6. Uncomment line of import Pod_Module
Solution 19 - Ios
When installing CocoaPods, be sure to specify ios 9.0 by deleteing the #. Therefore, # platform :ios, '9.0'
should just be platform :ios, '9.0'
Then, if the error shows again, simply build and run. After you build and run, the error should not return.
Also, this can occur if you have more than one version of Xcode installed on your computer. Quit (not just close) all versions of Xcode first.
Solution 20 - Ios
try Build For testing works for me
Solution 21 - Ios
If you have verified that your Pods have been successfully installed, then the error may be associated with your derived data remaining from before you installed the Pods. You can clear your derived data by going to File -> Workspace Settings... -> Derived Data
. Deleting the derived data folder associated with your app and cleaning your build should solve the problem.