解决 Pod include of non-modular header inside framework module 错误
Bingo 2017-03-19 10:30:27
Cocoapods
iOS
# 前言
今天在封装网络层框架 DKNetworking,更新到 Cocoapods 的时候出现一个错误,核心语句是 error: include of non-modular header inside framework module
,去到 Apple Developer Forums 发现有很多人有这样的问题,大概是在使用 Swift 的库时会出现这个问题,他们把 Target 下 Build Settings 中 Allow Non-modular includes in Framework Modules
设为 Yes 就解决了。
但是我依然报错,因为我不是在 Pod install 的时候报错,而是在上传 Pod 的时候 xcodebuild 编译不通过,这个时候的Building with xcodebuild
应该是默认的 Xcode 编译环境,不受 Pod 项目本身 Build Settings 的影响,所以改什么都是无用功,最终的解决办法只能从那句 pod trunk push
入手。
# 错误
最后的一段错误输出日志如下:
While building module 'DKNetworking' imported from /var/folders/9j/c_9mf_4913z66d00dw_lqwsm0000gn/T/CocoaPods/Lint/App/main.m:3:
In file included from <module-includes>:1:
In file included from /Users/bingo/Library/Developer/Xcode/DerivedData/App-adpwvlhhgeknoqdfxpvlfodkbype/Build/Products/Release-iphonesimulator/DKNetworking/DKNetworking.framework/Headers/DKNetworking-umbrella.h:19:
/Users/bingo/Library/Developer/Xcode/DerivedData/App-adpwvlhhgeknoqdfxpvlfodkbype/Build/Products/Release-iphonesimulator/DKNetworking/DKNetworking.framework/Headers/DKNetworkSessionManager.h:9:9: error: include of non-modular header inside framework module 'DKNetworking.DKNetworkSessionManager' [-Werror,-Wnon-modular-include-in-framework-module]
#import "AFHTTPSessionManager.h"
^
1 error generated.
/var/folders/9j/c_9mf_4913z66d00dw_lqwsm0000gn/T/CocoaPods/Lint/App/main.m:3:9: fatal error: could not build module 'DKNetworking'
@import DKNetworking;
~~~~~~~^~~~~~~~~~~~
2 errors generated.
** BUILD FAILED **
The following build commands failed:
CompileC /Users/bingo/Library/Developer/Xcode/DerivedData/App-adpwvlhhgeknoqdfxpvlfodkbype/Build/Intermediates/App.build/Release-iphonesimulator/App.build/Objects-normal/i386/main.o App/main.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
CompileC /Users/bingo/Library/Developer/Xcode/DerivedData/App-adpwvlhhgeknoqdfxpvlfodkbype/Build/Intermediates/App.build/Release-iphonesimulator/App.build/Objects-normal/x86_64/main.o App/main.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
(2 failures)
-> DKNetworking (0.1.0)
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.
- WARN | [iOS] xcodebuild: DKNetworking/DKNetworking/DKNetworking.m:362:122: warning: values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead [-Wformat]
- WARN | xcodebuild: DKNetworking/DKNetworking/DKNetworking.m:408:25: warning: variable 'downloadTask' is uninitialized when captured by block [-Wuninitialized]
- NOTE | xcodebuild: DKNetworking/DKNetworking/DKNetworking.m:396:5: note: variable 'downloadTask' is declared here
- ERROR | xcodebuild: /Users/bingo/Library/Developer/Xcode/DerivedData/App-adpwvlhhgeknoqdfxpvlfodkbype/Build/Products/Release-iphonesimulator/DKNetworking/DKNetworking.framework/Headers/DKNetworkSessionManager.h:9:9: error: include of non-modular header inside framework module 'DKNetworking.DKNetworkSessionManager' [-Werror,-Wnon-modular-include-in-framework-module]
- NOTE | xcodebuild: /var/folders/9j/c_9mf_4913z66d00dw_lqwsm0000gn/T/CocoaPods/Lint/App/main.m:3:9: fatal error: could not build module 'DKNetworking'
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 2 errors and 2 warnings.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.0/lib/cocoapods/command/spec/lint.rb:81:in `run'
/Library/Ruby/Gems/2.0.0/gems/claide-1.0.1/lib/claide/command.rb:334:in `run'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.0/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.0/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 解决
解决 warning :
--allow-warnings // 允许警告,有一些警告是代码自身带的可以忽略
1
解决 error :
--use-libraries // 私有库、静态库引用的时候加上
1
所以最终的解决方法:
$ pod trunk push --verbose --allow-warnings --use-libraries
1