Cocoapods + 无法为“ x”加载底层模块

我正在运行 XCode 7 Swift 2.0 iOS 9。

我想在我的项目中使用 Cocoapods 安装 Alamofire:

gem install cocoapods

pod setup

pod init

更新 Podfile 到:

# 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

然后我安装了吊舱:

pod install

然后我将以下内容添加到 ViewController.swift

import Alamofire

这就产生了以下错误:

Cannot load underlying module for 'Alamofire'

我用另一个 pod 进行了测试,结果也出现了同样的错误,所以我猜问题出在 Cocoapods 的安装上。如果你能帮忙,我将不胜感激。

52729 次浏览

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.

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.

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

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

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'

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

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

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.

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)

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

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

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

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

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.

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.

try Build For testing works for me

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.

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

Follow the steps:

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

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.

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.