ios 当我使用 CocoaPods 时“没有这样的模块”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31065447/
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
'No such module' when I use CocoaPods
提问by Idris
So here's my procedure. I create a new Podfile
in the project directory, then I added the following
所以这是我的程序。我Podfile
在项目目录中创建了一个新的,然后我添加了以下内容
platform :ios, '9.0'
use_frameworks!
target 'CPod' do
pod 'AFNetworking', '~> 2.5'
pod 'ORStackView', '~> 2.0'
pod 'SwiftyJSON', '~> 2.1'
end
I fire off pod install
, and everything goes well, open up the xcworkspace
. I then go over to ViewController.swift
and if I try to import a pod I get No such module 'SwiftyJSON'
, if I were to do import SwiftyJSON
. Any ideas?
我开火了pod install
,一切顺利,打开xcworkspace
. 然后我转到ViewController.swift
,如果我尝试导入一个 pod,我会得到No such module 'SwiftyJSON'
,如果我要这样做的话import SwiftyJSON
。有任何想法吗?
EDIT: SwiftyJSON is a Swift based module, not Obj-C
编辑:SwiftyJSON 是一个基于 Swift 的模块,而不是 Obj-C
回答by Micah Benn
Try adding the Pods
framework to your build scheme and building the framework. After you've built it, build/run your project.
尝试将Pods
框架添加到您的构建方案并构建框架。构建完成后,构建/运行您的项目。
Steps:
脚步:
回答by Asil ARSLAN
You must reopen project .xcworkspace file(not .xcodeproj) after install your podfile.
安装 podfile 后,您必须重新打开项目 .xcworkspace 文件(不是 .xcodeproj)。
- Clone the repo with CocoaPods
- Open YourWorkspace/YourApplication.xcworkspace
- Select the app u want to run Add SwiftyJSON.framework in embedded binaries for that project Hit Run
- 使用 CocoaPods 克隆 repo
- 打开 YourWorkspace/YourApplication.xcworkspace
- 选择您要运行的应用程序 在嵌入式二进制文件中为该项目添加 SwiftyJSON.framework 点击运行
Happy Coding :)
快乐编码:)
回答by Vishal
You may also try re-installing pods using:
您也可以尝试使用以下方法重新安装 pod:
pod deintegrate
and then
进而
pod install
This fixed this issue for me
这为我解决了这个问题
回答by Yash Vyas
Press Command+Option+Shift+Kand then Runyour app, you will see a magic.
按Command+Option+Shift+K然后运行你的应用程序,你会看到一个魔法。
Or from the menu ->?Product, press Option on your keyboard and you'll see?Clean Build Folder.
或者从菜单 ->?Product,按键盘上的 Option,你会看到?Clean Build Folder。
It's looking funny that how could Xcode do those things with us but same thing happened to me when I used a Swift library using Pod and after too much struggle I ended up with Clean Build Folder.
Xcode 怎么能和我们一起做这些事情看起来很有趣,但是当我使用 Pod 使用 Swift 库时,同样的事情发生在我身上,经过太多的努力,我最终得到了 Clean Build Folder。
回答by LowAmmo
Not sure if this would still be helpful for others. But, in my case, it ended up being a silly mistake of not referencing dependencies from the .podspec file.
不确定这对其他人是否仍然有帮助。但是,就我而言,它最终成为一个愚蠢的错误,即不从 .podspec 文件中引用依赖项。
We have an application with multiple internal libraries, and those libraries also have dependencies on each other - which we accounted for the in the Podfiles... but NOT in the podspecs.
我们有一个包含多个内部库的应用程序,这些库也相互依赖——我们在 Podfiles 中考虑了这一点……但不在 podspecs 中。
So, even though our Podfiles had:
所以,即使我们的 Podfiles 有:
Application / Podfile
应用程序/Podfile
# Development Pods
pod 'ConsumingLibrary ', :path => '../ios-consuming-lib'
pod 'DependentLibrary1', :path => '../ios-library-one'
pod 'CommonCoreLibrary', :path => '../ios-common-core-lib'
ConsumingLibrary / Podfile
消费图书馆/Podfile
# Development Pods
pod 'DependentLibrary1', :path => '../ios-library-one'
pod 'CommonCoreLibrary', :path => '../ios-common-core-lib'
Needed to also call it out in the .podspec's:
还需要在 .podspec 中调用它:
ConsumingLibrary / ConsumingLibrary.podspec
ConsumingLibrary / ConsumingLibrary.podspec
# TODO
# Add here any resources to be exported.
s.dependency 'DependentLibrary1', '~> 0.1.0-RC'
DependentLibrary1 / DependentLibrary1.podspec
DependentLibrary1 / DependentLibrary1.podspec
# TODO
# Add here any resources to be exported.
s.dependency 'CommonCoreLibrary', '~> 0.1.0-RC'
I think I wasted about 2 hours trying to figure out why I could build ConsumingLibrary & run tests, but as soon as I built the app, that consumed all three libraries - I kept getting:
我想我浪费了大约 2 个小时试图弄清楚为什么我可以构建 ConsumingLibrary 并运行测试,但是一旦我构建了应用程序,它就消耗了所有三个库 - 我不断得到:
No such module 'DependentLibrary1'
没有这样的模块“DependentLibrary1”
回答by Ratneshwar Singh
Try using pod updateafter pod install command which will solve problem of No such module. I just tried and it working fine.
尝试在 pod install 命令之后使用pod update这将解决No such module 的问题。我刚刚尝试过,它工作正常。
Thanks, Ratneshwar
谢谢,拉特内什瓦尔
回答by samuperry
As @jakub-truhlá? wrote, the root issue is the missing module.modulemap file due to some concurrency issue mixing Swift and Objective-C libraries, but instead of creating those files manually, would be better to try multiple times cleaning the Derived Data and build your project. When the project is successfully built then commit module.modulemap files to your repository to avoid to lose those files for example changing the current branch.
作为@jakub-truhlá?写道,根本问题是由于一些混合 Swift 和 Objective-C 库的并发问题导致缺少 module.modulemap 文件,但与其手动创建这些文件,不如尝试多次清理派生数据并构建您的项目。成功构建项目后,将 module.modulemap 文件提交到您的存储库,以避免丢失这些文件,例如更改当前分支。
回答by Kishore Kumar
Those who working with multiple targets , please don't forget to add this line in pods
那些使用多个目标的人,请不要忘记在 pods 中添加这一行
def shared_pods
pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'
end
target 'Target_Name' do
shared_pods
end
target 'Target_Name_Two' do
shared_pods
end
回答by Arvind Abi
I faced the same problem in a swift framework I developed. The framework had a dependency of git project and the framework itself added as a pod to my main project. So, ideally the dependency has been specified in podspec file and Podfile as well.
我在我开发的 swift 框架中遇到了同样的问题。该框架依赖于 git 项目,框架本身作为 pod 添加到我的主项目中。因此,理想情况下,在 podspec 文件和 Podfile 中也指定了依赖项。
I didn't faced the problem when accessing through the my main project but when I open the framework standalone it was throwing "No such module" error.
通过我的主项目访问时我没有遇到这个问题,但是当我独立打开框架时,它抛出“没有这样的模块”错误。
The root cause is, the base configurations is set with the path which points towards my main project instead of the framework itself because I ran podinstall first in my main project and then in the framework project.
根本原因是,基本配置设置为指向我的主项目而不是框架本身的路径,因为我首先在主项目中运行 podinstall,然后在框架项目中运行。
Eg: in the project file it was like 0091AB0C861D71C94ADD7240 /* Pods-myframework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-myframework.release.xcconfig"; path = "../../Apps/MyMainProject/Pods/Target Support Files/Pods-myframework/Pods-myframework.release.xcconfig"; sourceTree = ""; };
例如:在项目文件中它就像 0091AB0C861D71C94ADD7240 /* Pods-myframework.release.xcconfig */ = {isa = PBXFileReference; 包含索引 = 1; lastKnownFileType = text.xcconfig; name = "Pods-myframework.release.xcconfig"; path = "../../Apps/MyMainProject/Pods/Target Support Files/Pods-myframework/Pods-myframework.release.xcconfig"; 源树 = ""; };
After doing the below mentioned fix, 4444F5B1B35F066E57F96782 /* Pods-myframework.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-myframework.release.xcconfig"; path = "Pods/Target Support Files/Pods-myframework/Pods-myframework.release.xcconfig"; sourceTree = ""; };
完成下面提到的修复后, 4444F5B1B35F066E57F96782 /* Pods-myframework.release.xcconfig */ = {isa = PBXFileReference; 包含索引 = 1; lastKnownFileType = text.xcconfig; name = "Pods-myframework.release.xcconfig"; path = "Pods/目标支持文件/Pods-myframework/Pods-myframework.release.xcconfig"; 源树 = ""; };
To fix the error,
要修复错误,
- Project file -> Configurations -> Set all the configurations set to none.
- Remove Pods folder and Podfile.lock.
- Run 'pod install' first in the framework project direcory and then do pod install in main project directory.
- 项目文件 -> 配置 -> 将所有配置设置为无。
- 删除 Pods 文件夹和 Podfile.lock。
- 首先在框架项目目录中运行“pod install”,然后在主项目目录中进行 pod install。
回答by karthikeyan
I just updated particular dependencies in terminal
我刚刚更新了终端中的特定依赖项
Go to project folder then run below command
转到项目文件夹,然后运行以下命令
pod update your pod name
pod 更新你的 pod 名称
For me I need to do
对我来说,我需要做
pod update ReachabilitySwift
pod 更新 ReachabilitySwift