Cocoapods + Cannot load underlying module for 'x'

50,926

Solution 1

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

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

Solution 3

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

Solution 4

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 5

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

Share:
50,926
Admin
Author by

Admin

Updated on August 14, 2020

Comments

  • Admin
    Admin almost 4 years

    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.

  • Admin
    Admin over 8 years
    Yes it was the most recent build. I just figured out the problem though. I built the project, and all of a sudden, it worked.
  • Glenn
    Glenn over 8 years
    Ok then please answer your own question with the solution you figured out so that others can fix that problem when they encounter that,
  • SoliQuiD
    SoliQuiD almost 8 years
    I almost come here at the start of any project... Thanks buddy
  • AmirZ
    AmirZ over 6 years
    After everything else failed, this actually worked. Thanks a lot.
  • nikans
    nikans over 6 years
    Also, remove Pod/ folder before reinstalling
  • Hola Soy Edu Feliz Navidad
    Hola Soy Edu Feliz Navidad over 6 years
    True, that was the main problem,you have to clean with command-shift-K
  • Siddharth
    Siddharth about 6 years
    Damn workaround still works.. XCode should be open sourced.
  • Mundi
    Mundi about 6 years
    I had to set it from YES to NO. Weird.
  • Renexandro
    Renexandro almost 4 years
    You cannot consider to "start a new project" every time you see this error when 99% of the time it is happening in an existing project. What about just trying 'pod update'