class 'GTMHTTPUploadFetcher' 的重复接口定义

Duplicate interface definition for class 'GTMHTTPUploadFetcher'

我打算在我的 Swift 项目中使用 Google Drive API。我正在尝试通过 CocoaPods (v0.39.0) 添加 Drive SDK。下面是我的 Podfile。

platform :ios, '8.0'
use_frameworks!

pod 'Google-API-Client/Drive'

我添加了 use_frameworks! 标志,以便 CocoaPods 可以将 Objective-C pods 转换为 Swift 框架而不是静态库。

Pod安装成功。但是,当我构建项目时,出现以下错误。

class 'GTMHTTPUploadFetcher'

的重复接口定义

删除 DerivedData 文件夹和清理项目无效。

我也尝试过不添加 use_frameworks! 然后通过桥接头方式添加库。这没有问题。问题是我的所有其他依赖项都在打开它的情况下工作。不幸的是,CocoaPods doesn't support 仅针对某些 pods 打开该标志。

是否有解决此问题的解决方法?


正如 Google 的 docs 中所述,Google 工程师应该监控标有 google-drive-sdk 的问题,所以我希望至少他们会看到并尽快修复它。

我发现的唯一解决方法是您必须进入 Google 驱动导入的那三个项目并检查导入是如何完成的。现在它导入头文件,而不是框架(这三个框架相互依赖)。您只需手动执行即可。

我没有可向您展示的代码示例,但我知道我上次以这种方式让它工作。

我运行遇到了同样的问题。我的解决方案是 不安装 Google API 使用 CocoaPods 的 iOS 客户端,因为我使用的是 Swift-based pods因此,我无法删除 use_frameworks! 来尝试解决重复的 header 问题。

我按照 https://developers.google.com/drive/ios/quickstart?ver=swift 中关于步骤 2、3 和 4 的详细说明手动安装了库。我按照说明进行操作,但将它们应用到 我现有的工作区 而不是创建新的工作区。

重要的是要注意我必须调整 User Header Search Paths 中的路径以匹配我实际从 [=38 复制源代码的位置=].

我将说明复制到这里以供参考。

Step 2: Download the Google Client Library

Run the following commands to download the library using git:

  • git clone https://github.com/google/google-api-objectivec-client.git
  • git clone https://github.com/google/gtm-oauth2.git
  • git clone https://github.com/google/gtm-session-fetcher.git
  • git clone https://github.com/stig/json-framework.git -b v2.3
  • cp -R gtm-oauth2/Source google-api-objectivec-client/Source/OAuth2
  • cp -R json-framework/Classes google-api-objectivec-client/Source/JSON

Step 3: Prepare the workspace

Open Xcode and create a new workspace named "Quickstart". Using File > Add Files to "Quickstart"..., add the following projects to the workspace from the libraries you cloned in the previous step:

  • google-api-objectivec-client/Source/GTL.xcodeproj
  • gtm-session-fetcher/Source/GTMSessionFetcher.xcodeproj

Select the "GTMSessionFetcher" project and make the following changes:

  • Add a new target of the type iOS > Framework & Library> Cocoa Touch Static Library and name it "GTMSessionFetcherLib".
  • Add all of the .m files in the project's GTMSessionFetcher group to the target's Build Phases > Compile Sources section.

Select the "GTL" project's "GTLTouchStaticLib" target and make the following changes:

  • Add the library GTMSessionFetcher/libGTMSessionFetcherLib.a to Build Phases > Link Binary with Libraries.
  • Add the absolute path to gtm-session-fetcher/Source/ to Build Settings > User Header Search Paths.
  • Add the flag GTM_USE_SESSION_FETCHER=1 to Build Settings > Preprocessor Macros.
  • Delete the "GTL" project's "GTLFramework" target.
  • In the Project navigator, delete GTL project's GTL Source > Common > HTTPFetcher group.

Step 4: Prepare the project

  • Create a new iOS > Application > Single View Application project named "QuickstartApp". Set the Language to Swift , and when saving the project set the Add to and Group fields to "Quickstart".
  • Add the following frameworks and libraries to the project's Build Phases > Link Binary with Libraries section: libGTLTouchStaticLib.a
    • Security.framework
    • SystemConfiguration.framework
  • Change the following Build Settings:
  • Add -ObjC -all_load to Other Linker Flags.
  • Add the absolute path to the following directories to User Header Search Paths:
    • gtm-session-fetcher/Source/
    • google-api-objectivec-client/Source/**
  • Add the flag GTM_USE_SESSION_FETCHER=1 to Preprocessor Macros.
  • Add the file google-api-objectivec-client/Source/OAuth2/Touch/GTMOAuth2ViewTouch.xib to the project's Supporting Files group.
  • Add the following files to the QuickstartApp group:
    • google-api-objectivec-client/Source/Services/Drive/Generated/GTLDrive_Sources.m
    • google-api-objectivec-client/Source/Services/Drive/Generated/GTLDrive.h
  • If not created automatically, create a new header file Bridging-Header.h with the following content:
    • #import "GTMOAuth2ViewControllerTouch.h"
    • #import "GTLDrive.h"
  • Set Build Settings > Objective-C Bridging Header to the absolute path of the bridging header.

根据Google这个错误是由第三方使用cocoapod引起的,但是他们现在在项目中有一个官方的pod(https://github.com/google/google-api-objectivec-client/blob/master/GoogleAPIClient.podspec),这个问题应该已经解决了。

参见:https://github.com/google/google-api-objectivec-client/issues/103

使用:

pod 'GoogleAPIClient/Drive', '~> 1.0'

可能还有:

pod 'GTMOAuth2'pod 'Google/SignIn'

此处的简单解决方案:

转到编辑方案 -> Select 构建 -> 构建选项取消选中并行化构建

现在运行你的应用程序