我在下面的项目设置中为自定义构建配置编译主项目时遇到构建错误。但我没有得到调试配置的构建错误。
MainProject ( Mixed Objective-C and Swift)
|_ SubProject1 ( Only Objective-C)
MainProject build configs :
|_ Debug
|_ Inhouse
|_ Adhoc
|_ Store
SubProject1 build configs:
|_ Debug
|_ Release
Pod 文件:
workspace 'MainProject.xcworkspace'
platform :ios, '9.0'
target 'MainProject' do
use_frameworks!
def shared_pods
# all the pods go here
pod 'CocoaLumberjack/Swift'
end
target 'MainProject' do
project 'MainProject'
shared_pods
end
target 'SubProject1' do
project 'Subprojects/SubProject1/Subproject1'
shared_pods
end
end
主项目和子项目都使用 Cocoalumberjack。由于 subproject 是一个 obj-c 项目,所以它使用 cocoalumberjack obj-c 版本,并带有以下 import 语句。
#import "CocoaLumberjack/CocoaLumberjack.h"
在构建调试配置时,没有构建失败。但是在构建 Inhouse/Adhoc/Store 配置时,它无法在头搜索路径中找到 cocoalumberjack 头文件。从构建日志中,我可以推断出,
在构建主项目调试配置时,相同的配置用于构建 pod 和子项目。因此,Pod 被放置在 Debug-iphonesimulator 路径中。由于子项目有Debug配置,所以也会引用Debug-iphonesimulator路径下的pod头,所以构建成功。
当 Mainproject 中的其他自定义配置被构建时,比如说,Inhouse,Pods 被放置在 Inhouse-iphonesimulator 路径中。由于子项目没有内部配置,它默认发布配置。这导致在构建子项目时在发布中间路径中搜索 cocoalumberjack 头文件。但是 Cocoalumberjack header 不存在于发布配置路径中,但存在于内部中间路径中。这会导致构建错误。请在下面找到构建错误日志。
CompileC /Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Intermediates/Subproject1.build/Release-iphonesimulator/SubProject1.build/Objects-normal/x86_64/SubProject1.o
/Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Intermediates/Subproject1.build/Release-iphonesimulator/SubProject1.build/SubProject1-generated-files.hmap -F/Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Products/Release-iphonesimulator
> -F/Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Products/Release-iphonesimulator/CocoaLumberjack -iquote /Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Products/Release-iphonesimulator/CocoaLumberjack/CocoaLumberjack.framework/Headers -c /Users/someusername/Anand/iOS/Practices/StackOverflow/MainProject/Subprojects/SubProject1/SubProject1/SubProject1.m -o /Users/someusername/Library/Developer/Xcode/DerivedData/MainProject-gslvjyjvbpzplkerotbufvukmpac/Build/Intermediates/Subproject1.build/Release-iphonesimulator/SubProject1.build/Objects-normal/x86_64/SubProject1.o
In file included from /Users/someusername/Anand/iOS/Practices/StackOverflow/MainProject/Subprojects/SubProject1/SubProject1/SubProject1.m:10: /Users/someusername/Anand/iOS/Practices/StackOverflow/MainProject/Subprojects/SubProject1/SubProject1/Logger.h:9:9: fatal error: 'CocoaLumberjack/CocoaLumberjack.h' file not found
import "CocoaLumberjack/CocoaLumberjack.h"
^ 1 error generated.
有人可以帮我解决自定义配置的构建错误吗?如果需要更多详细信息,请告诉我。
这应该可以解决您的问题:
用这个更新你的 Podfile:
workspace 'MainProject.xcworkspace'
platform :ios, '9.0'
use_frameworks!
def shared_pods
# all the pods go here
pod 'CocoaLumberjack/Swift'
end
target 'MainProject' do
project 'MainProject'
shared_pods
end
target 'SubProject1' do
project 'Subprojects/SubProject1/Subproject1'
shared_pods
end
在终端上运行此命令以从项目中卸载 pod 以便稍后进行全新安装:
pod deintegrate
删除 Podfile.lock
rm -rf Podfile.lock
再次运行安装:
pod install
如果您使用 Lumberjack 作为框架,您可以像这样导入:
@import CocoaLumberjack
希望能解决,请告诉我结果...
您也可以尝试NSLogger也适用于混合的 Objective-c + swift 项目。
关于ios - Cocoapod - 混合 Objective-C 和 Swift 项目中自定义配置的构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45768104/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |