ios 无法安装 Cocoapods - 在项目目录中找不到 podfile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36902497/
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:58:00  来源:igfitidea点击:

Cannot Install Cocoapods - No podfile found in the project directory

iosxcodeswiftcocoapods

提问by tccpg288

I downloaded a sample project to learn how to make a UIPageViewController, and I am trying to essentially fork that project and need to add a third-party library. Right now, it does not look like I have a .xcworkspace file in my project. When I try and install the cocoapods, I first run

我下载了一个示例项目来学习如何制作 UIPageViewController,并且我试图从本质上分叉该项目并需要添加第三方库。现在,看起来我的项目中没有 .xcworkspace 文件。当我尝试安装 cocoapods 时,我首先运行

sudo gem install cocoapods- in the specific project directory in my terminal

sudo gem install cocoapods- 在我终端的特定项目目录中

pod install- in that same directory

pod install- 在同一个目录中

I am receiving an error in the terminal "No podfile found in the project directory."

我在终端中收到错误“在项目目录中找不到 podfile”。

Is this happening because I don't have a .xcworkspace file? Am I installing the podfile correctly?

这是因为我没有 .xcworkspace 文件吗?我是否正确安装了 podfile?

enter image description here

在此处输入图片说明

回答by Vijay Tholpadi

Steps to add CocoaPods to manage dependencies in your project:

添加 CocoaPods 以管理项目中的依赖项的步骤:

  1. sudo gem install cocoapods-> This installs CocoaPods as a piece of software on your machine.

  2. Go to the root of your project directory and execute pod init-> This will add a base Podfile to your project.

  3. Add the external dependencies that you have to this Podfile by editing it.

  4. Run pod installwhich will fetch all the external dependencies mentioned by you, and associate it with a .xcworkspacefile of your project. This .xcworkspacefile will be generated for you if you already do not have one.

  1. sudo gem install cocoapods-> 这会将 CocoaPods 作为软件安装在您的机器上。

  2. 转到项目目录的根目录并执行pod init-> 这会将基本 Podfile 添加到您的项目中。

  3. 通过编辑将您拥有的外部依赖项添加到此 Podfile。

  4. 运行pod install它将获取您提到的所有外部依赖项,并将其与.xcworkspace您的项目文件相关联。.xcworkspace如果您还没有此文件,则会为您生成此文件。

From here on, you should use .xcworkspacefile instead of .xcproject/ .xcodeproj.

从这里开始,您应该使用.xcworkspacefile 而不是.xcproject/ .xcodeproj

Example Podfile Syntax:

示例 Podfile 语法:

target 'MyApp' do   
pod 'AFNetworking', '~> 3.0'
end

Where AFNetworkingis the pod and 3.0is the specific version that I want to install.

AFNetworkingpod在哪里,3.0是我要安装的特定版本。

Documentation: Using CocoaPods

文档:使用 CocoaPods

回答by iamburak

If you want to add a library from GitHub to your own project, after installing gems, do firstly pod initlook at from GitHub cocoapod description and then add it after target line in podfile.

如果你想从 GitHub 添加一个库到你自己的项目中,安装 gems 后,pod init先从 GitHub cocoapod 的描述中查看,然后将它添加到 podfile 中的目标行之后。

Save and run "pod install".

保存并运行“pod install”。

It would be successfully added on your project.

它将成功添加到您的项目中。