user5319603
user5319603

Reputation:

Cocoapods + Cannot load underlying module for 'x'

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.

Upvotes: 96

Views: 55960

Answers (21)

iwasrobbed
iwasrobbed

Reputation: 46713

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.

Upvotes: 4

EFE
EFE

Reputation: 3752

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)):

enter image description here

It did work for me. Error gone now.

Note: My pod was not Alamofire so i guess it will work for every Pod.

Upvotes: 2

Augustin A
Augustin A

Reputation: 127

Follow the steps:

1.Install pods 2.Open workSpace 3.Run/build your application 4.Then you can import the framework

Upvotes: 3

Reza Dehnavi
Reza Dehnavi

Reputation: 2273

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

Upvotes: 2

Brian Li
Brian Li

Reputation: 3080

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.

Upvotes: 0

Tawfik Bouabid
Tawfik Bouabid

Reputation: 1292

try Build For testing works for me

Upvotes: 0

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.

Upvotes: 5

user9470831
user9470831

Reputation:

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.

Upvotes: 0

Alex Kolovatov
Alex Kolovatov

Reputation: 879

This worked for me:

  1. Close your project
  2. In terminal go to your project directory
  3. Add this command: pod update
  4. After that all your pods will be updated. Just run your project

Upvotes: 13

shokaveli
shokaveli

Reputation: 522

I had to do a Product > (Opt Click) Clean Build Folder ... then ran again and the issue was gone.

Upvotes: 8

Ajay Reddy
Ajay Reddy

Reputation: 1493

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

Upvotes: 9

Alexander
Alexander

Reputation: 88

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 :)

Upvotes: 2

Andrew
Andrew

Reputation: 38029

What has helped in my case:

1) Close the project and XCode

2) In the terminal repeat command

> pod install

3) Open the project

(If it does not help, try to remove Pod/ folder before reinstalling)

Upvotes: 8

Purushottam Padhya
Purushottam Padhya

Reputation: 408

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

Upvotes: 2

Jacobo Koenig
Jacobo Koenig

Reputation: 12534

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.

Upvotes: 8

Zulqarnain Mustafa
Zulqarnain Mustafa

Reputation: 1653

Go to Product > Build and it will resolve the problem: enter image description here

Upvotes: 25

khongks
khongks

Reputation: 53

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.

Targets > General > Linked Frameworks and Libraries

Upvotes: 5

Markus Wu
Markus Wu

Reputation: 21

Could not load underlying module

  1. Check framework path: Build Settings -> Framework Search Paths.
  2. Make sure the path to a framework contains no space.
  3. If the path contains a variable, find the value of the variables by searching the variable name in your Build Settings.
  4. Make sure the value of the variables contains no space.
  5. If the path contains spaces, rename those directories that contain spaces.
  6. 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'

Upvotes: 2

jerfin
jerfin

Reputation: 893

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

Upvotes: 9

vichle
vichle

Reputation: 2508

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.

Upvotes: 216

Glenn
Glenn

Reputation: 2806

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 : 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.

Upvotes: 3

Related Questions