在多个应用程序中使用可可触摸框架项目

Posted

技术标签:

【中文标题】在多个应用程序中使用可可触摸框架项目【英文标题】:Use cocoa touch Framework project in multiple apps 【发布时间】:2018-03-20 09:47:50 【问题描述】:

我有两个带有大量冗余代码的 ios 应用程序,因此我决定将此代码提取到共享的 cocoa touch 框架中,并在 RayWenderlichs tutorial 之后添加此框架项目文件。 我还阅读了 Apples Framework Programming Guide 但我无法解决我的问题。

现在陈述: 这两个应用程序都可以在添加的框架下正常工作。

我的问题: 我无法使用目标 Generic iOS Device 构建这两个应用程序,只能构建真正的设备目标或模拟器。但是两个应用程序都能够构建 通用 iOS 设备在添加框架项目之前。

这是我得到的输出,尝试使用目标 Generic iOS Device

希望的行为: 我希望应用程序和框架的行为就像 C# 或 Java 中的简单项目库一样。 我不明白为什么会发生这个错误。

Showing Recent Issues
Ld /Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Intermediates.noindex/VISUSDisplay.build/Debug-iphoneos/VISUSDisplay.build/Objects-normal/armv7/VISUSRemote normal armv7
    cd "/Users/dkronenberger/Documents/gitRepo/Mobile/VISUS/VISUS Display"
    export IPHONEOS_DEPLOYMENT_TARGET=10.0
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk -L/Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Products/Debug-iphoneos -L/Users/dkronenberger/Documents/gitRepo/Mobile/VISUS/VISUS\ Display -F/Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Products/Debug-iphoneos -F/Volumes/SoftwaresAndMedia/Adnan\ Projects/VISUS\ Project/Visus/Visus -F/Applications/Xcode.app/Contents/Developer/Library/Frameworks -F/Users/dkronenberger/Documents/gitRepo/Mobile/VISUS/VISUS\ Display -filelist /Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Intermediates.noindex/VISUSDisplay.build/Debug-iphoneos/VISUSDisplay.build/Objects-normal/armv7/VISUSRemote.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -miphoneos-version-min=10.0 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Intermediates.noindex/VISUSDisplay.build/Debug-iphoneos/VISUSDisplay.build/Objects-normal/armv7/VISUSRemote_lto.o -Xlinker -no_deduplicate -fobjc-arc -fobjc-link-runtime -lz -lstdc++ -framework GameKit -framework AudioToolbox -framework SystemConfiguration -framework Security -framework CFNetwork /Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Products/Debug-iphoneos/ConnectionManager.framework/ConnectionManager -framework AVFoundation -framework CoreText -framework QuartzCore -lsqlite3.0 -framework UIKit -framework Foundation -framework CoreGraphics -Xlinker -dependency_info -Xlinker /Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Intermediates.noindex/VISUSDisplay.build/Debug-iphoneos/VISUSDisplay.build/Objects-normal/armv7/VISUSRemote_dependency_info.dat -o /Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Intermediates.noindex/VISUSDisplay.build/Debug-iphoneos/VISUSDisplay.build/Objects-normal/armv7/VISUSRemote

ld: warning: directory not found for option '-F/Volumes/SoftwaresAndMedia/Afelde Projects/VISUS Project/Visus/Visus'
ld: warning: ignoring file /Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Products/Debug-iphoneos/ConnectionManager.framework/ConnectionManager, file was built for arm64 which is not the architecture being linked (armv7): /Users/dkronenberger/Library/Developer/Xcode/DerivedData/VISUSDisplay-cwapquipviigpndwwktvfnqurbsq/Build/Products/Debug-iphoneos/ConnectionManager.framework/ConnectionManager
Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_ConnectionManager", referenced from:
      objc-class-ref in AppDelegate.o
      objc-class-ref in HomeViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

编辑: 我已经检查了架构验证

【问题讨论】:

【参考方案1】:

显然,您的框架 ConnectionManager.framework 尚未配置为编译 armv7 架构的代码。

您可以尝试更改ConnectionManager目标的配置设置:

检查Valid Architectures 是否包含所有变体:arm64armv7armv7s 尝试将Build Active Architecture Only 设置为No 用于DebugRelase,如果它仍然不起作用。

【讨论】:

这两点我之前已经检查过了,这似乎不是问题,我添加了一个截图 您是否也为您的主要(非框架)项目检查了它?如果您使用“存档”而不是“构建”会发生什么? 我按照您的建议进行了更改,但现在我在其他架构中遇到了同样的错误:架构 i386 的未定义符号:“_OBJC_CLASS_$_ConnectionManager”,引用自:AppDelegate.o objc 中的 objc-class-ref HomeViewController.o ld 中的 -class-ref:未找到架构 i386 的符号 您是否尝试清理DerivedData 文件夹并重试?可以分享一下代码吗? 是的,我试过了,但仍然出现同样的错误,不幸的是我无法分享,这是一个 CustomerProject :-/ 任何其他想法?

以上是关于在多个应用程序中使用可可触摸框架项目的主要内容,如果未能解决你的问题,请参考以下文章

xcodebuild 命令无法与动态可可触摸框架一起正常工作

构建纯Swift可可触摸框架

在可可触摸框架的框架模块内包含非模块化头文件

如何展示我的可可触摸框架故事板屏幕?

如何将 pod(第三方框架)添加到我的自定义可可触摸框架中?

在可可触摸框架中隐藏实现