xcodebuild:cdtool无法编译:DataModelCompile /path/to/coredatamodel.xcdatamodeld dyld:找不到符号:_OBJC_CLASS _ $ _ OS_object

时间:2016-06-17 03:19:58

标签: ios cocoa core-data xcodebuild nstask

我正在构建一个Mac桌面/ Cocoa应用程序来存档我的iOS项目,核心实现使用NSTask和xcodebuild命令,然后是raywenderlich's this guide

根本原因是CoreData模型文件编译,我使用这个应用程序来构建我的另一个项目,该项目不包含任何CoreData文件,并且没有问题。更有趣的比较是,我在我的终端尝试了相同的xcodebuild命令,它只是成功了!

然后我开始对两个xcodebuild输出进行区分,发现一些差异,

在终端,

DataModelCompile /Users/hanwei/Library/Developer/Xcode/DerivedData/youYue3xMaster-cjatyqmgblwyoyccarejxlozikdi/Build/Intermediates/ArchiveIntermediates/youYue3xMaster/InstallationBuildProductsLocation/Applications/youYue3xMaster.app/ youYue3xMaster/LogicBook.xcdatamodeld
cd /Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin"
/Applications/Xcode.app/Contents/Developer/usr/bin/momc --sdkroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk --iphoneos-deployment-target 7.0 --module youYue3xMaster /Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster/youYue3xMaster/LogicBook.xcdatamodeld /Users/hanwei/Library/Developer/Xcode/DerivedData/youYue3xMaster-cjatyqmgblwyoyccarejxlozikdi/Build/Intermediates/ArchiveIntermediates/youYue3xMaster/InstallationBuildProductsLocation/Applications/youYue3xMaster.app/

在我的可可应用程序日志中

DataModelCompile /Users/hanwei/Library/Developer/Xcode/DerivedData/youYue3xMaster-cjatyqmgblwyoyccarejxlozikdi/Build/Intermediates/ArchiveIntermediates/youYue3xMaster/InstallationBuildProductsLocation/Applications/youYue3xMaster.app/ youYue3xMaster/MagazineModel.xcdatamodeld
cd /Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/usr/bin/momc --sdkroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk --iphoneos-deployment-target 7.0 --module youYue3xMaster /Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster/youYue3xMaster/MagazineModel.xcdatamodeld /Users/hanwei/Library/Developer/Xcode/DerivedData/youYue3xMaster-cjatyqmgblwyoyccarejxlozikdi/Build/Intermediates/ArchiveIntermediates/youYue3xMaster/InstallationBuildProductsLocation/Applications/youYue3xMaster.app/

dyld: Symbol not found: _OBJC_CLASS_$_OS_object
Referenced from: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/lib/system/libxpc.dylib
Expected in: /usr/lib/system/introspection/libdispatch.dylib in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.3.sdk/usr/lib/system/libxpc.dylib
2016-06-17 09:46:28.158 momc[76594:13533677] *** -[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?
cdtool invalid hashes:
/Users/hanwei/work/DragonSource/projects/ios_youyue3_xmaster/youYue3xMaster/youYue3xMaster/MagazineModel.xcdatamodeld/MagazineModel.xcdatamodel:: error: cdtool cannot compile

主要的错误日志详细信息可以在后面的部分找到,差异结果是“export PATH = ...”。在终端中,PATH包含当前用户的$ {PATH},我应该是最终原因,但在尝试将相同路径导出到我的cocoa应用程序的shell脚本后,没有运气。

这是我的shell脚本,

command -v xcodebuild >/dev/null 2>&1 || { echo >&2 "It requires xcodebuild but it's not installed.  Aborting."; exit 1; }

#export PATH=$PATH:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin

#PATH=$PATH:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/opt/subversion/bin:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin

echo ${PATH}

type xcodebuild
type xcpretty

if [ -x "$(command -v xcpretty)" ]; then
    xcodebuild -workspace "${1}" -scheme "${2}" -sdk iphoneos -destination generic/platform=iOS -archivePath "${3}" archive | xcpretty
else
echo "xcpretty is not installed, suggest to install it and try again.";
    xcodebuild -workspace "${1}" -scheme "${2}" -sdk iphoneos -destination generic/platform=iOS -archivePath "${3}" archive
fi

对于错误“dyld:未找到符号:_OBJC_CLASS _ $ _ OS_object ...”,我用Google搜索并发现从libdispach构建的_OBJC_CLASS _ $ _ OS_object符号,libdispatch应该在Foundation.framework中构建,然后我试图明确地链接我的项目中的Foundation.framework,存在相同的错误。

对于“引用自:...预期在:...”* 语句,它引用了iPhone模拟器,然后我猜可能有些错误 xcodebuild -destination < / em>,传递generic / platform = iOS或我的iOS设备(来自此cheetsheet的引用)也不起作用。

对于“错误:cdtool无法编译”,我在Xcode bug .xcdatamodel: cdtool cannot compile中发现了这个大问题,我尝试了重命名解决方案而没有运气,这个问题背景是针对Xcode的测试版。

目前我的环境是Xcode 7.3.1(7D1014),10.11.5(15F34)。

我专注于这个问题超过8小时,如果你有一些好的怀疑点或解决方案,请帮助我,非常感谢提前!

顺便说一句,我发现@MichalMoskala遇到了同样的问题而且没有解决方案Calling xcodebuild from Swift command line tool fails。他没有说明它在Xcode-beta版本中发生的背景。

如果确实没有最终解决方案,我必须决定将CoreData转移到FMDB / Realm。

更新

经过几天的调查,我没有找到真正的最终解决方案,在xcodebuild中手动编译xcdatamodeld文件时应该是Xcode中的错误。但为什么不出现在Xcode IDE中呢?也许Apple开发人员在Xcode中制作了一些补丁。

这是我的解决方案,将已编译的xcdatamodeld文件(* .momd)复制到项目中,从项目中的 Build Phrases - Compile Sources 中删除* .xcdatamodeld文件,这样在构建/存档时就不会编译它们。添加自定义脚本将.momd备份文件复制到产品目录,它在编译源之前执行,就像Xcode中的构建进度一样。

这是我的剧本,

cp -r ${SRCROOT}/CoreDataFiles/*.momd ${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}/

验证通过了!

0 个答案:

没有答案