ios 总是得到构建错误:没有这样的模块“Alamofire”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36336476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:49:09  来源:igfitidea点击:

Always get build error : No such module 'Alamofire'

iosxcodeswiftcocoapodsalamofire

提问by Leem.fin

I followed the instruction of Alamofirein github,

我跟着的指令Alamofiregithub上

I created an xcode project named cocoapods-test& I closed it.

我创建了一个名为的 xcode 项目cocoapods-test并关闭了它。

I go to the project folder run pod initcommand which generates a Podfile. Then I added the following code to the Podfile:

我转到pod init生成 Podfile的项目文件夹运行命令。然后我在 Podfile 中添加了以下代码:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Alamofire', '~> 3.0'

Then, I run command pod installand this is the result in terminal:

然后,我运行命令pod install,这是终端中的结果

Updating local specs repositories

CocoaPods 1.0.0.beta.6 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Analyzing dependencies
Downloading dependencies
Installing Alamofire (3.3.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `cocoapods-test.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

Then, in my project folder there is a new file called cocoapods-test.xcworkspace. I double clicked it which opens my xcode again, and I can see the Alamofire module.

然后,在我的项目文件夹中有一个名为cocoapods-test.xcworkspace. 我双击它再次打开我的 xcode,我可以看到 Alamofire 模块。

Then, I opened my project's ViewControllerclass, and import Alamofire. But no matter how many times I clean & build, I always get errorNo such module 'Alamofire'. Here is the screenshot:

然后,我打开了我的项目ViewController类,然后import Alamofire. 但是无论我清理和构建多少次,我总是得到错误No such module 'Alamofire'。这是屏幕截图:

enter image description here

在此处输入图片说明

Why I get this problem though I followed the instruction step by step?

为什么我一步一步地按照说明进行操作时会出现此问题?

(I am using XCode 7.2.1, Swift 2.1.1& Alamofire 3.3.0)

(我正在使用XCode 7.2.1, Swift 2.1.1& Alamofire 3.3.0

======= UPDATE ========

======== 更新 ========

I tried @LK Yeung 's answer, uncomment import Alamofire, then clean & build again, I got a bunch of compiler errors from Alarmofire:

我尝试了@LK Yeung 的回答,取消注释import Alamofire,然后再次清理和构建,我从 Alarmofire 收到了一堆编译器错误:

enter image description here

在此处输入图片说明

采纳答案by Anthony To

I was having this exact same problem. Please make sure that you are on Xcode 7.3 and using Swift 2.2.

我遇到了完全相同的问题。请确保您使用的是 Xcode 7.3 并使用 Swift 2.2。

You can check your Swift version using xcrun swift -version. Updating Xcode to 7.3 should also automatically update Swift.

您可以使用xcrun swift -version. 将 Xcode 更新到 7.3 也应该会自动更新 Swift。

Updating Xcode resolved this issue for me.

更新 Xcode 为我解决了这个问题。

回答by LK Yeung

You need to build the project successfully once before using the library

在使用库之前,您需要成功构建项目一次

comment import Alamofire -> build -> uncomment import Alamofire

注释 import Alamofire -> build -> 取消注释 import Alamofire

回答by Saurabh Padwekar

Make sure you have opened the "project_name".xcworkspaceinstead of "project_name".xcodeproj.As you are working on pods all the installed pod will be available only in your .xcworkspaceproject file.

确保您已打开“project_name” .xcworkspace而不是“project_name” .xcodeproj。当您在处理 pod 时,所有已安装的 pod 将仅在您的.xcworkspace项目文件中可用。

回答by Patrick

You need to add the lib to 'the Link Binary With Libraries' section also

您还需要将 lib 添加到“链接二进制与库”部分

回答by vien vu

You can try put pod 'Alamofire', '~> 3.0'like below. And run pod installagain.

您可以尝试pod 'Alamofire', '~> 3.0'像下面这样放置。并pod install再次运行。

target 'yourtarget' do
     pod 'Alamofire', '~> 3.0'
end

回答by Justin Domnitz

If you're manually installing Alamofire (or any other framework) make sure your build configurations match between both your parent project and the sub project. For example, if your build configuration in your project is called 'Development', but Alamofire's is called 'Debug' you'll get the 'no such module' error.

如果您手动安装 Alamofire(或任何其他框架),请确保您的构建配置在您的父项目和子项目之间匹配。例如,如果您项目中的构建配置被称为“开发”,而 Alamofire 的被称为“调试”,您将收到“没有这样的模块”错误。

回答by Muhammad Ahmad

No such module 'Alamofire'

没有这样的模块“Alamofire”

I have also this same problem I solve this by :

我也有同样的问题,我通过以下方式解决了这个问题:

pod update

it automatically updates your pod file. If you have the same error, follow these steps :

它会自动更新您的 pod 文件。如果您遇到相同的错误,请按照下列步骤操作:

pod init 
pod install

then after this, if you have the same error, then do this:

然后在此之后,如果您遇到相同的错误,请执行以下操作:

pod update

回答by Zain Ullah Muhammad

I had the same issue, the reason was that I installed the wrong version of alamofire.

我遇到了同样的问题,原因是我安装了错误版本的 alamofire。

I am using Xcode 7.3, swift 2.2, so alamofire 3.0 worked for me

我使用的是 Xcode 7.3,swift 2.2,所以 alamofire 3.0 对我有用

remove the library using these steps mentioned by @Michal

使用@Michal 提到的这些步骤删除库

Remove or uninstall library previously added : cocoapods

删除或卸载之前添加的库:cocoapods

Then in your pod file

然后在你的 pod 文件中

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, ‘9.3'  <-- your target version

use_frameworks!

target '<your target name>' do
    pod 'Alamofire', '~> 3.0'

end

回答by ronak patel

try to latest updated install alamofire and also check u use alamofire latest is this in your xcode supported.

尝试安装最新更新的 alamofire 并检查您使用最新的 alamofire 是否在您的 xcode 支持中。

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Alamofire', '~> 4.4'
end

try this above alamofire on your podfile

在你的 podfile 上试试这个上面的 alamofire