AFNetworking无法编译 [英] AFNetworking won't compile

查看:285
本文介绍了AFNetworking无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全想尝试使用AFNetworking在模拟器上运行项目。我以前在其他项目上使用过这种依赖关系,所以我不明白这里出了什么问题。首先,当我尝试运行项目时出现错误:

I'm totally stuck trying to run a project on the simulator using AFNetworking. I've used this dependency before on other projects, so I don't understand what is going wrong here. First, the error when I try to run the project:

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_AFHTTPSessionManager", referenced from:
      _OBJC_CLASS_$_SharedNetworkObject in SharedNetworkObject.o
  "_OBJC_CLASS_$_AFJSONResponseSerializer", referenced from:
      objc-class-ref in SharedNetworkObject.o
  "_OBJC_METACLASS_$_AFHTTPSessionManager", referenced from:
      _OBJC_METACLASS_$_SharedNetworkObject in SharedNetworkObject.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我确定这是问题的一部分,但我没有知道如何解决它:

I'm sure that this is part of the problem, but I don't know how to resolve it:

这是有问题的.h文件:

This is the offending .h file:

#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>
#import "SharedSessionKey.h"

@interface SharedNetworkObject : AFHTTPSessionManager

+ (SharedNetworkObject *) sharedNetworkObject;   // class method to return the singleton object

@end

请注意,当我开始输入AFNetworking的导入行时,该行会在几个字符后填充,因此我知道对AFNetworking依赖项的存在有所了解。

It may be of interest to note that when I start typing the import line for AFNetworking, the line fills in after a few characters, so I know that there is some awareness of the presence of the AFNetworking dependency.

我使用CocoaPods安装了依赖项。这是我的Podfile:

I installed the dependency using CocoaPods. Here is my Podfile:

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'

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

target 'WeRun' do
pod "AFNetworking", "2.5.2"
end

target 'WeRunTests' do

end

当然,我在 .xcworkspace 中工作(不是 .xcodeproj

And, of course I am working in .xcworkspace (not .xcodeproj).

另一件事,我的xcconfig文件如下所示,它与其他成功的AFNetworking版本相匹配:

One more thing, my xcconfig file looks like this, which matches with other successful AFNetworking builds:

GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/AFNetworking"
OTHER_CFLAGS = $(inherited) -isystem "${PODS_ROOT}/Headers/Public" -isystem "${PODS_ROOT}/Headers/Public/AFNetworking"
OTHER_LDFLAGS = -ObjC -l"Pods-MyApp-AFNetworking" -framework "CoreGraphics" -framework "MobileCoreServices" -framework "Security" -framework "SystemConfiguration"
OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS)
PODS_ROOT = ${SRCROOT}/Pods

我不知道还要寻找什么。我已经完全移除了广告连播,然后重新安装,却发现完全相同的错误。谁能帮我解决这个问题?谢谢!

I don't know what else to look for. I've completely removed the pod and reinstalled, only to find the exact same error. Can anyone help me figure this out? Thanks!

推荐答案

我花了几个小时来解决这个完全相同的问题,并浏览了我能找到的所有Google热门歌曲。该设备的构建正在工作,但模拟器的构建却没有。

I spent a couple of hours fighting with this exact same issue, going through all the Google hits I could find. Building for the device was working, but building for the simulator was not.

以下是最终为我解决问题的步骤:

Here are the steps that finally solved the issue for me:


  1. 清除XCode缓存:

  1. Clear the XCode caches:

rm -rf ~/Library/Developer/Xcode/DerivedData/


  • 清除CocoaPods缓存并重新安装依赖项:

  • Clear the CocoaPods caches and reinstall the dependencies:

    rm -rf "${HOME}/Library/Caches/CocoaPods"
    rm -rf "`pwd`/Pods/"
    pod update
    


  • 最后转到 Pods项目并设置 Build Active Architectures Only 也适用于调试配置。

  • Finally go to the "Pods" project and set the Build Active Architectures Only to No also for the "Debug" configuration.

    这篇关于AFNetworking无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆