Cocoapod"错误:无法构建模块' UIKit'"

时间:2015-06-04 07:07:57

标签: ios objective-c cocoapods mupdf podspec

我试图将MuPDF纳入podspec。虽然这不是我想要的那么好......

error: could not build module 'UIKit'

这是我每次尝试pod lib lint时得到的错误。我得到两种口味,取决于podspec的确切内容。但在那之前,有些背景!

tl; dr :我的大脑无法处理MuPDF及其静态库依赖关系,从中制作出漂亮的podspec。你能帮忙吗?

文件布局

所以图书馆是MuPDF(http://mupdf.com);我克隆了他们的git存储库。它附带了一堆.m文件,但主库是用C语言编写的,并且有几个依赖项。所以我们最终得到了一些静态库(.a文件)。文件布局如下所示:

mupdf/
  # objc files
  platform/ios/common.{h,m}
  platform/ios/Classes/*.{h,m}

  # headers and static libraries
  include/**/*.h
  platform/ios/thirdparty/*.a

include文件夹包含platform/ios/thirdparty中库所需的标头。这些标头包含在platform/ios/common.h

Podspec

我的podspec看起来像这样:

Pod::Spec.new do |s|
  # <enter usual podspec yada yada here>

  s.source_files  = "platform/ios/Classes/**/*.{h,m}", "platform/ios/common.{h,m}", "include/**/*.h"
  s.public_header_files = "platform/ios/Classes/**/*.h"
  s.header_mappings_dir = "include"

  s.libraries = "z"
  s.vendored_libraries = "platform/ios/thirdparty/*"
end

基于此(以及podspec的变体),我得到两个不同的错误。

符号重新定义错误

使用这个确切的podspec配置,我收到以下错误:

- ERROR |  /<path>/mupdf/include/mupdf/fitz/math.h:97:8:
           error: redefinition of 'fz_point_s'
- NOTE  |  /<path>/mupdf/include/mupdf/fitz/math.h:97:8:
           note: previous definition is here
- ERROR |  /<path>/mupdf/include/mupdf/fitz/math.h:121:8:
            error: redefinition of 'fz_rect_s'
- NOTE  |  /<path>/mupdf/include/mupdf/fitz/math.h:121:8:
           note: previous definition is here

# etc. etc.

- NOTE  |  Target Support Files/Pods-mupdf/Pods-mupdf-prefix.pch:2:9:
           fatal error: could not build module 'UIKit'

循环依赖性错误

如果我注释掉s.public_header_files行,我最终会出现循环依赖错误。太奇怪了!

- NOTE  |  /privateTarget Support Files/Pods-mupdf/Pods-mupdf-umbrella.h:1:9:
           fatal error: cyclic dependency in module 'UIKit':
           UIKit -> Foundation -> CoreFoundation -> MuPDF -> UIKit

结论

我的大脑疼,请帮忙!

2 个答案:

答案 0 :(得分:4)

我不太确定你的PodSpec会发生什么事,抱歉。这可能与你如何解决math.h头文件冲突有关 - 在pod规范中做到这一点是非常棘手的。

我刚刚创建了一个CocoaPod for MuPDF,并创建了一个example application based on that pod,一切似乎都正常。

此处参考我的pod规范(请注意,这已经过时了;请参阅published mupdf pod spec以获取与最新版本的mupdf和最新CocoaPods兼容的版本):

# podspec for MuPDF
#
# Copyright (C) 2015 Joseph Heenan <joseph@heenan.me.uk>

Pod::Spec.new do |s|
  s.name             = "MuPDF"
  s.version          = "1.7"
  s.summary          = "A lightweight PDF and XPS viewer."
  s.description      = <<-DESC
                       MuPDF is a small, fast, and yet complete PDF viewer. 
                       It supports PDF 1.7 with transparency, encryption, 
                       hyperlinks, annotations, searching and more. It also
                       reads XPS and OpenXPS documents.
                       DESC
  s.homepage         = "http://www.mupdf.com/"
  s.license          = { :type => "Affero GNU GPL v3", :file => 'COPYING' }
  s.author           = "Artifex Software Inc"
  s.source           = { :git => "https://github.com/ArtifexSoftware/mupdf.git", :tag => s.version.to_s }

  s.platform     = :ios, '6.1'
  s.requires_arc = false

  s.source_files = 'platform/ios/Classes/**/*.[mh]', 'platform/ios/common.[mh]'
  s.resources = 'platform/ios/*.png', 'platform/android/res/drawable-ldpi/*.png'

  s.public_header_files = "platform/ios/Classes/**/*.h", "platform/ios/common.h"

  # See https://github.com/CocoaPods/CocoaPods/issues/1437
  s.preserve_paths = "include/*", "include/**/*"

  s.prepare_command = <<-CMD
      # I tried --depth 1 here but it failed with git error "fatal: reference is not a tree:"
      git submodule update --init
      cd platform/ios

      # build the various .a files
      # release armv7 + arm64
      xcodebuild -scheme MuPDF -configuration Release CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
      # release i386 + x86_64
      xcodebuild -scheme MuPDF -configuration Release -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO

      # combine into fat libraries
      cd ../../build/
      for i in curl freetype jbig2dec jpeg mujs mupdf openjpeg z; do
          LIB=lib${i}.a
          lipo -create -output $LIB release-ios-i386-x86_64/$LIB release-ios-armv7-arm64/$LIB
      done
CMD

  s.vendored_libraries = "build/*.a"

  s.xcconfig = {
    # we have a math.h which conflicts with the system math.h unless
    # we disable header maps
    'USE_HEADERMAP' => 'NO',
    'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/Target Support Files/Pods"',

    'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/MuPDF/include"',

    'ALWAYS_SEARCH_USER_PATHS' => 'NO'
  }

end

答案 1 :(得分:0)

我通过在Build Phases中删除和添加UIKit.framework解决了这个问题 - &gt; Link Binary With Libraries和set project的最低iOS版本是6.0。