Swift 如何使用cocoapods避免多项目工作区中的类重复

Swift 如何使用cocoapods避免多项目工作区中的类重复,swift,xcode,firebase,static-framework,Swift,Xcode,Firebase,Static Framework,我在业余时间制作了一个应用程序,我想问你一个问题,我的工作区有3个子项目:演示、域和数据,每一个子项目都是一个静态框架,都有自己的pod,而且都很酷,但现在我有一个问题,我不知道如何解决它。我有几个firebase依赖项,其中一些必须在表示中,另一些必须在数据中,执行时出现问题,因为它给了我一个错误: 类PodsDummy_FirebaseUI在这两种语言中都实现 /Users/../Debug iphonesimulator/PresentationCleanExample.framework

我在业余时间制作了一个应用程序,我想问你一个问题,我的工作区有3个子项目:演示、域和数据,每一个子项目都是一个静态框架,都有自己的pod,而且都很酷,但现在我有一个问题,我不知道如何解决它。我有几个firebase依赖项,其中一些必须在表示中,另一些必须在数据中,执行时出现问题,因为它给了我一个错误:

类PodsDummy_FirebaseUI在这两种语言中都实现 /Users/../Debug iphonesimulator/PresentationCleanExample.framework/PresentationCleanExample (0x104ffada0)和 /用户/../data/Containers/Bundle/Application/A15FF8B8-7B67-4512-8DFD-04F008175660/CleanExample.app/CleanExample (0x100c6e288)。将使用其中一个。哪一个是未定义的

因此,我在FirebaseUI/Storage的podspec中看到了以下内容:

这让我觉得cocoapods没有正确地解决Firebase/Storage之间的依赖关系

问题是,这只是我从Firebase获得的数千个重复类中的一个,用于遵循上面的图表。 我想有一种方法可以只注入Firebase依赖项一次,从而避免类重复,但我不知道如何实现

我的播客文件:

platform :ios, '13.6'

workspace 'CleanExample'
use_frameworks!

def firebase_pods
  pod 'Firebase/Core', '7.11.0'
  pod 'Firebase/Auth', '7.11.0'
  pod 'Firebase/Firestore', '7.11.0'
  pod 'Firebase/Storage', '7.11.0'
  pod 'FirebaseFirestoreSwift', '7.11.0-beta'
end


target 'CleanExample' do
  project 'CleanExample'
  firebase_pods
  pod 'FirebaseUI/Storage'
end

target 'PresentationCleanExample' do
  project 'PresentationCleanExample/PresentationCleanExample.xcodeproj'
#  firebase_pods
  pod 'FirebaseUI/Storage'
end

target 'DomainCleanExample' do
  project 'DomainCleanExample/DomainCleanExample.xcodeproj'
end

target 'DataCleanExample' do
  project 'DataCleanExample/DataCleanExample.xcodeproj'
  firebase_pods
end

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
            config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
            config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
        end
    end
end
github 我已经上传了代码

问题
  • FirebaseStorageUI.podspec文件或 是椰子荚的限制吗

  • 我的播客文件错了吗


受这篇文章的启发,我终于解决了我的问题,因为它让我明白了问题所在

如果我理解正确的话,其他的标志是通过复制添加框架

然后,为了避免原始消息问题,
Class***在这两个
中都实现了,我在目标“CleanExample”中安装了所有的pod,并从以下文件中删除了另一行

  • Pods-DataCleanExample.debug.xcconfig
  • Pods-DataCleanExample.release.xcconfig
  • Pods-PresentationCleanExample.debug.xcconfig
  • Pods-PresentationCleanExample.release.xcconfig
播客文件

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
# Inspired by https://medium.com/@GalvinLi/tinysolution-fix-cocoapods-duplicate-implement-warning-5a2e1a505ea8

platform :ios, '13.6'

workspace 'CleanExample'
use_frameworks!

def data_pods
  pod 'Firebase/Core', '7.11.0'
  pod 'Firebase/Auth', '7.11.0'
  pod 'Firebase/Firestore', '7.11.0'
  pod 'Firebase/Storage', '7.11.0'
  pod 'FirebaseFirestoreSwift', '7.11.0-beta'
end

def presentation_pods
  pod 'FirebaseUI/Storage', '10.0.2'
  pod 'Firebase/Storage', '7.11.0'
  pod 'lottie-ios'
end

target 'CleanExample' do
  project 'CleanExample'
  presentation_pods
  data_pods
  
end

target 'PresentationCleanExample' do
  project 'PresentationCleanExample/PresentationCleanExample.xcodeproj'
  presentation_pods
end

target 'DomainCleanExample' do
  project 'DomainCleanExample/DomainCleanExample.xcodeproj'
end

target 'DataCleanExample' do
  project 'DataCleanExample/DataCleanExample.xcodeproj'
  data_pods
end

post_install do |installer|
  removeOTHERLDFLAGS(['PresentationCleanExample', 'DataCleanExample'], installer)
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
      config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
      config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
    end
  end
end



def removeOTHERLDFLAGS(target_names, installer)
  pods_targets_names = target_names.map{ |str| 'Pods-' + str }
  handle_app_targets(pods_targets_names, installer)
end

def find_line_with_start(str, start)
  str.each_line do |line|
    if line.start_with?(start)
      return line
    end
  end
  return nil
end

def remove_words(str, words)
  new_str = str
  words.each do |word|
    new_str = new_str.sub(word, '')
  end
  return new_str
end

def handle_app_targets(names, installer)
  puts "handle_app_targets"
  puts "names: #{names}"
  installer.pods_project.targets.each do |target|
    if names.index(target.name) == nil
      next
    end
    puts "Updating #{target.name} OTHER_LDFLAGS"
    target.build_configurations.each do |config|
      xcconfig_path = config.base_configuration_reference.real_path
      xcconfig = File.read(xcconfig_path)
      old_line = find_line_with_start(xcconfig, "OTHER_LDFLAGS")
      
      if old_line == nil
        next
      end
      new_line = ""
      new_xcconfig = xcconfig.sub(old_line, new_line)
      File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
    end
  end
end
#取消注释下一行以定义项目的全局平台
#平台:ios,“9.0”
#灵感来自https://medium.com/@GalvinLi/tinysolution-fix-cocoapods-duplicate-implement-warning-5a2e1a505ea8
平台:ios,‘13.6’
工作区“CleanExample”
使用你的框架!
def数据舱
吊舱“火力基地/核心”,“7.11.0”
pod“Firebase/Auth”,“7.11.0”
吊舱“Firebase/Firestore”,“7.11.0”
吊舱“火力基地/仓库”,“7.11.0”
pod“FirebaseFirestoreSwift”,“7.11.0-beta”
结束
def演示文稿播客
吊舱“FirebaseUI/存储”,“10.0.2”
吊舱“火力基地/仓库”,“7.11.0”
lottie ios吊舱
结束
目标“CleanExample”do
项目“CleanExample”
演示文稿播客
数据舱
结束
目标“PresentationCleanExample”do
项目“PresentationCleanExample/PresentationCleanExample.xcodeproj”
演示文稿播客
结束
目标“DomainCleanExample”do
项目“DomainCleanExample/DomainCleanExample.xcodeproj”
结束
目标“DataCleanExample”do
项目“DataCleanExample/DataCleanExample.xcodeproj”
数据舱
结束
安装后的do安装程序|
移除其他LDFlags(['PresentationCleanExample','DataCleanExample',installer)
installer.pods_project.targets.each do| target|
target.build|u configurations.each do| config|
config.build\u设置['EXPANDED\u CODE\u SIGN\u IDENTITY']=“”
config.build\u设置['CODE\u SIGNING\u REQUIRED']=“否”
config.build\u设置['CODE\u SIGNING\u ALLOWED']=“否”
结束
结束
结束
def removeOTHERLDFLAGS(目标名称、安装程序)
pods_targets_names=target_names.map{str |'pods-'+str}
处理应用程序目标(吊舱目标名称、安装程序)
结束
def find_line_和_start(str,start)
str.每条线都有一条线|
如果行。开始使用?(开始)
回程线
结束
结束
归零
结束
def删除单词(str,单词)
new_str=str
单词。每个单词|
new_str=new_str.sub(单词“”)
结束
返回新的\u str
结束
def句柄应用程序目标(名称、安装程序)
放置“句柄\应用\目标”
放置“名称:#{names}”
installer.pods_project.targets.each do| target|
如果names.index(target.name)==nil
下一个
结束
将“正在更新#{target.name}其他#LDFLAGS”
target.build|u configurations.each do| config|
xcconfig\u path=config.base\u configuration\u reference.real\u path
xcconfig=File.read(xcconfig\u路径)
old_line=使用_start查找_line_(xcconfig,“其他\u LDFLAGS”)
如果old_line==nil
下一个
结束
new_line=“”
new\u xcconfig=xcconfig.sub(旧的\u行,新的\u行)
打开(xcconfig_路径,“w”){| File | File
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
# Inspired by https://medium.com/@GalvinLi/tinysolution-fix-cocoapods-duplicate-implement-warning-5a2e1a505ea8

platform :ios, '13.6'

workspace 'CleanExample'
use_frameworks!

def data_pods
  pod 'Firebase/Core', '7.11.0'
  pod 'Firebase/Auth', '7.11.0'
  pod 'Firebase/Firestore', '7.11.0'
  pod 'Firebase/Storage', '7.11.0'
  pod 'FirebaseFirestoreSwift', '7.11.0-beta'
end

def presentation_pods
  pod 'FirebaseUI/Storage', '10.0.2'
  pod 'Firebase/Storage', '7.11.0'
  pod 'lottie-ios'
end

target 'CleanExample' do
  project 'CleanExample'
  presentation_pods
  data_pods
  
end

target 'PresentationCleanExample' do
  project 'PresentationCleanExample/PresentationCleanExample.xcodeproj'
  presentation_pods
end

target 'DomainCleanExample' do
  project 'DomainCleanExample/DomainCleanExample.xcodeproj'
end

target 'DataCleanExample' do
  project 'DataCleanExample/DataCleanExample.xcodeproj'
  data_pods
end

post_install do |installer|
  removeOTHERLDFLAGS(['PresentationCleanExample', 'DataCleanExample'], installer)
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
      config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
      config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
    end
  end
end



def removeOTHERLDFLAGS(target_names, installer)
  pods_targets_names = target_names.map{ |str| 'Pods-' + str }
  handle_app_targets(pods_targets_names, installer)
end

def find_line_with_start(str, start)
  str.each_line do |line|
    if line.start_with?(start)
      return line
    end
  end
  return nil
end

def remove_words(str, words)
  new_str = str
  words.each do |word|
    new_str = new_str.sub(word, '')
  end
  return new_str
end

def handle_app_targets(names, installer)
  puts "handle_app_targets"
  puts "names: #{names}"
  installer.pods_project.targets.each do |target|
    if names.index(target.name) == nil
      next
    end
    puts "Updating #{target.name} OTHER_LDFLAGS"
    target.build_configurations.each do |config|
      xcconfig_path = config.base_configuration_reference.real_path
      xcconfig = File.read(xcconfig_path)
      old_line = find_line_with_start(xcconfig, "OTHER_LDFLAGS")
      
      if old_line == nil
        next
      end
      new_line = ""
      new_xcconfig = xcconfig.sub(old_line, new_line)
      File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
    end
  end
end