Exclude pod when porting to mac with catalyst

后端 未结 6 1450
陌清茗
陌清茗 2020-12-13 14:32

Porting apps to mac is finally possible thanks to Catalyst, problem is, numerous pods don\'t support AppKit. Most common one would be Crashlytics / Firebase

6条回答
  •  醉酒成梦
    2020-12-13 14:47

    Following @ajgryc answer, I was able to make a sleek solution:

    In your podfile add

    post_install do |installer|
        installer.pods_project.targets.each do |target|
            if target.name == "Pods-[Name of Project]"
                puts "Updating #{target.name} OTHER_LDFLAGS to OTHER_LDFLAGS[sdk=iphone*]"
                target.build_configurations.each do |config|
                    xcconfig_path = config.base_configuration_reference.real_path
                    xcconfig = File.read(xcconfig_path)
                    new_xcconfig = xcconfig.sub('OTHER_LDFLAGS =', 'OTHER_LDFLAGS[sdk=iphone*] =')
                    File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
                end
            end
        end
    end
    

    Since Cocoapods 1.8.4

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        if target.name == "Pods-[Name of Project]"
          puts "Updating #{target.name} to exclude Crashlytics/Fabric"
          target.build_configurations.each do |config|
            xcconfig_path = config.base_configuration_reference.real_path
            xcconfig = File.read(xcconfig_path)
            xcconfig.sub!('-framework "Crashlytics"', '')
            xcconfig.sub!('-framework "Fabric"', '')
            new_xcconfig = xcconfig + 'OTHER_LDFLAGS[sdk=iphone*] = -framework "Crashlytics" -framework "Fabric"'
            File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
          end
        end
      end
    end
    

    And then in run script build phase for Fabric:

    if [[$ARCHS != "x86_64"]]; then
      "${PODS_ROOT}/Fabric/run" [your usual key]
    fi
    

提交回复
热议问题