类是在两者中实现的,其中一个将被使用。 哪一个未定义

我有一个Cocoapods中包含的依赖项问题。

我有一个Framework项目(MyFramework目标),它也有App目标(MyFrameworkExampleApp)。 当我尝试运行应用程序时,我得到一个充满错误的控制台,如下所示:

类PodsDummy_AFNetworking在/private/var/containers/Bundle/Application/AD85D7EC-2652-4019-94FB-C799D0FBA69B/MyFrameworkExampleApp.app/Frameworks/MyFramework.framework/MyFramework(0x1019a0438)和/ var / containers / Bundle / Application中实现/AD85D7EC-2652-4019-94FB-C799D0FBA69B/MyFrameworkExampleApp.app/MyFrameworkExampleApp(0x10107c558)。 将使用两者之一。 哪一个未定义。

问题是,错误来自仅包含在MyFramework目标中的库

以下是我的podfile的内容:

# Specify platform. platform :ios, '9.0' # Let's ignore all warnings from all pods inhibit_all_warnings! target 'MyFramework' do # ReactiveCocoa for easier binding between UI and data models. pod 'ReactiveCocoa', ' 0.4.1' # AFNetworking Security stuff pod 'AFNetworking/Security', '~> 2.5.4' # KZPropertyMapper to easily map JSON dicts to properties pod "KZPropertyMapper" # Simple wrapper for KeyChain pod 'UICKeyChainStore', '~> 2.0.6' # Animated gifs pod 'FLAnimatedImage', '~> 1.0' # Firebase push notifications pod 'Firebase/Core' pod 'Firebase/Messaging' # Easy image downloading with cache. pod 'SDWebImage', '~> 3.7.2' # Activity indicator for RBSlider pod 'DGActivityIndicatorView' end target 'MyFrameworkExampleApp' do # Progress indicator pod 'MBProgressHUD', '~> 1.0.0' # Color picker pod 'iOS-Color-Picker' # Hockey SDK pod 'HockeySDK', '~> 5.0.0' end 

如您所见,App目标不会inheritance任何pod,也不会有任何全局pod。 可能是什么原因?

我不知道原因,但如果您打开应用程序的Pods- [AppName] .debug.xcconfig文件,cocoapods创建您将找到OTHER_LDFLAGS,您将看到它链接到您在框架中链接的相同框架。 因此,如果删除-framework [Duplicated framework],警告将消失。

似乎是一个cocoapods错误

我还发现了另一个人写的脚本,可以自动修复bug。 它就像我上面回答的一样。 将其添加到您的Podfile:

 post_install do |installer| sharedLibrary = installer.aggregate_targets.find { |aggregate_target| aggregate_target.name == 'Pods-[MY_FRAMEWORK_TARGET]' } installer.aggregate_targets.each do |aggregate_target| if aggregate_target.name == 'Pods-[MY_APP_TARGET]' aggregate_target.xcconfigs.each do |config_name, config_file| sharedLibraryPodTargets = sharedLibrary.pod_targets aggregate_target.pod_targets.select { |pod_target| sharedLibraryPodTargets.include?(pod_target) }.each do |pod_target| pod_target.specs.each do |spec| frameworkPaths = unless spec.attributes_hash['ios'].nil? then spec.attributes_hash['ios']['vendored_frameworks'] else spec.attributes_hash['vendored_frameworks'] end || Set.new frameworkNames = Array(frameworkPaths).map(&:to_s).map do |filename| extension = File.extname filename File.basename filename, extension end frameworkNames.each do |name| if name != '[DUPLICATED_FRAMEWORK_1]' && name != '[DUPLICATED_FRAMEWORK_2]' raise("Script is trying to remove unwanted flags: #{name}. Check it out!") end puts "Removing #{name} from OTHER_LDFLAGS" config_file.frameworks.delete(name) end end end xcconfig_path = aggregate_target.xcconfig_path(config_name) config_file.save_as(xcconfig_path) end end end