xcode 无法导入与 Cocoapods 一起安装的依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44808305/
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
Can't import dependency installed with Cocoapods
提问by Bram Vanbilsen
I've installed FBSDK with Cocoapods but can't import it in my AppDelegate.swift file for some reason. The FBSDK kit appears in my Xcode project so I feel like it should be working.
我已经使用 Cocoapods 安装了 FBSDK,但由于某种原因无法将它导入我的 AppDelegate.swift 文件中。FBSDK 套件出现在我的 Xcode 项目中,所以我觉得它应该可以正常工作。
I'm not an iOS developer by any means, I'm just trying to write a simple native plugin for Flutter SDK. Anyone an idea?
我无论如何都不是 iOS 开发人员,我只是想为 Flutter SDK 编写一个简单的原生插件。任何人的想法?
--Here is what the pod file looks like--
--这是 pod 文件的样子--
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
if ENV['FLUTTER_FRAMEWORK_DIR'] == nil
abort('Please set FLUTTER_FRAMEWORK_DIR to the directory containing Flutter.framework')
end
target 'Runner' do
use_frameworks!
# Pods for Runner
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
# Flutter Pods
pod 'Flutter', :path => ENV['FLUTTER_FRAMEWORK_DIR']
if File.exists? '../.flutter-plugins'
flutter_root = File.expand_path('..')
File.foreach('../.flutter-plugins') { |line|
plugin = line.split(pattern='=')
if plugin.length == 2
name = plugin[0].strip()
path = plugin[1].strip()
resolved_path = File.expand_path("#{path}/ios", flutter_root)
pod name, :path => resolved_path
else
puts "Invalid plugin specification: #{line}"
end
}
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
---EDIT---
- -编辑 - -
I''m getting the following error atm: FBSDKCoreKit.framework: No such file or directory
.When I open the Frameworks folder in xCode, all file names are in red:
But that exact folder in Finder is empty. So I guess that's why the error is showing. The question is how to fix this...
我收到以下错误 atm: FBSDKCoreKit.framework: No such file or directory
.当我在 xCode 中打开 Frameworks 文件夹时,所有文件名都为红色:
但 Finder 中的确切文件夹为空。所以我想这就是显示错误的原因。问题是如何解决这个问题...
This is what my embedded binaries
and linked frameworks and libraries
look like in the project:
这就是我embedded binaries
和linked frameworks and libraries
看起来像项目:
回答by Bryan Norden
回答by QuantumHoneybees
Are you opening the .xcodeproj
or the .xcworkspace
? Make sure it is the workspace whenever you install a cocoapod
你是打开.xcodeproj
还是.xcworkspace
?每次安装 cocoapod 时,请确保它是工作区
回答by S2dent
I'll naively suppose you don't have use_frameworks!
in you Podfile
. If that's true, than you have two ways to go from here:
我会天真地假设你没有use_frameworks!
你Podfile
。如果这是真的,那么您有两种方法可以从这里开始:
In your
Runner-Bridging-Header.h
add#import <FBSDKCoreKit/FBSDKCoreKit.h>
, removeimport FBSDKCoreKit
fromAppDelegate.swift
and just continue writing the code.Add
use_frameworks!
to yourPodfile
and runpod install
again. That might bring some other issues, but if that works, than I'd suggest it.
在您
Runner-Bridging-Header.h
添加#import <FBSDKCoreKit/FBSDKCoreKit.h>
,删除import FBSDKCoreKit
从AppDelegate.swift
,只是继续写代码。添加
use_frameworks!
到您的Podfile
并pod install
再次运行。这可能会带来一些其他问题,但如果可行,我会建议这样做。
回答by Lawrence Tan
If you use cocoapods
, it should have generated a *.xcworkspace
file for you. Open this file instead so your project can see the FBSDK
installed and has reference to it.
如果您使用cocoapods
,它应该会*.xcworkspace
为您生成一个文件。改为打开此文件,以便您的项目可以看到已FBSDK
安装的并引用它。
回答by TonyB
When you install your pods, you must build your application first. Then your imports stop showing errors.
安装 Pod 时,必须先构建应用程序。然后您的导入停止显示错误。
回答by AnBisw
Why not simply use the Swift pods?-
为什么不简单地使用 Swift pods?-
pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'
and then import as normal, like-
然后像往常一样导入,比如-
import FBSDKLoginKit
import FacebookLogin
Once done, do a clean and build (command/?+ Shift+ K) and Build (command/?+ B). Make sure you are using the .xcworkspace
file to open the project.
完成后,进行清理和构建(command/?+ Shift+ K)和构建(command/?+ B)。确保您正在使用该.xcworkspace
文件打开项目。
More info on Swift FBSDK here.
在此处了解有关 Swift FBSDK 的更多信息。
Once you use the Swift pods, you should see these Frameworks in your project.
使用 Swift pod 后,您应该会在项目中看到这些框架。
If you still continue to see the error then "Clean the build folder" using command+ shift+ alt+ K.
如果仍然看到错误,则使用“清洁build文件夹” command+ shift+ alt+ K。
回答by iSaalis
The above solutions for Header Search Path should work. If you are too lazy to go there. Copy podfile content, remove all pods, pod install, then revert your podfile, pod install again.... Should work ;-)
标题搜索路径的上述解决方案应该有效。如果你懒得去那里。复制 podfile 内容,删除所有 pod,进行 pod 安装,然后恢复您的 podfile,再次进行 pod 安装.... 应该可以工作 ;-)
回答by Harry Singh
Start by cleaning your project using Command + Shift + K
then close the project and delete the pods
folder and the pod.lock
file and your .xcworkspace
file. Then run pod install
and see if that fixes the issue.
首先使用清理您的项目Command + Shift + K
然后关闭项目并删除pods
文件夹和pod.lock
文件以及您的.xcworkspace
文件。然后运行pod install
看看是否可以解决问题。
回答by Bhavesh Patel
First Clean your project directory. And add $(inherited) in framework search path in Build settings.
首先清理你的项目目录。并在构建设置的框架搜索路径中添加 $(inherited) 。
回答by b_ray
As importing the FBSDKCoreKit.framework
etc. will be performed in the [CP] Embed Pods Frameworks
build phase when using CocoaPods, you should remove the references to these frameworks in the Embed Frameworks
build phase.
由于使用 CocoaPods 时FBSDKCoreKit.framework
会在[CP] Embed Pods Frameworks
构建阶段执行导入等操作,因此您应该在Embed Frameworks
构建阶段移除对这些框架的引用。
CocoaPods will not create those references, I assume you have tried other ways of importing the Facebooks frameworks, and these link have been created in the process. You can also delete the references to the Facebook frameworks in the Frameworks Folder of you App-Project (the ones in your screenshot written in red, not the ones in the Pods-Project!), but keep the Pods_Runner.framework
there.
CocoaPods 不会创建这些引用,我假设您已经尝试过其他导入 Facebooks 框架的方法,并且这些链接已在此过程中创建。您还可以删除 App-Project 的 Frameworks 文件夹中对 Facebook 框架的引用(屏幕截图中用红色写的那些,而不是 Pods-Project 中的那些!),但保留在Pods_Runner.framework
那里。
From what I can tell, your Linked Frameworks and Libraries
section looks valid.
据我所知,您的Linked Frameworks and Libraries
部分看起来有效。
If it still doesn't work, I'd advise you to create a new Xcode Project with an empty Podfile, and only include the Facebook frameworks via CocoaPods. Importing the Facebook-SDK in the AppDelegate should work then, otherwise I can share a sample project with you. Then you should check your build setting and build phases, maybe something is wrong there. If you still can't figure out the problem, you will probably need to re-create you xcode-project and import all your files again.
如果它仍然不起作用,我建议您创建一个带有空 Podfile 的新 Xcode 项目,并且仅通过 CocoaPods 包含 Facebook 框架。然后在 AppDelegate 中导入 Facebook-SDK 应该可以工作,否则我可以与您共享示例项目。然后你应该检查你的构建设置和构建阶段,也许那里有问题。如果您仍然无法解决问题,您可能需要重新创建 xcode-project 并再次导入所有文件。
Without a sample Project that reproduces the error, that's the best advise I can give.
如果没有重现错误的示例项目,这是我能给出的最佳建议。
Good Luck! :)
祝你好运!:)