Exclude pod when porting to mac with catalyst

后端 未结 6 1425
陌清茗
陌清茗 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 15:04

    Based on what has already been discussed here... here is my solution for projects with multiple targets. It basically is validating the usage of the libs on each target instead of following the target name.

    post_install do |installer|
        
        installer.pods_project.targets.each do |target|
            
            # handle non catalyst libs
            libs = ["FirebaseAnalytics", "Google-Mobile-Ads-SDK"]
            
            target.build_configurations.each do |config|
                xcconfig_path = config.base_configuration_reference.real_path
                xcconfig = File.read(xcconfig_path)
                values = ""
                
                libs.each { |lib|
                    if xcconfig["-framework \"#{lib}\""]
                        puts "Found '#{lib}' on target '#{target.name}'"
                        xcconfig.sub!(" -framework \"#{lib}\"", '')
                        values += " -framework \"#{lib}\""
                    end
                }
                
                if values.length > 0
                    puts "Preparing '#{target.name}' for Catalyst\n\n"
                    new_xcconfig = xcconfig + 'OTHER_LDFLAGS[sdk=iphone*] = $(inherited)' + values
                    File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
                end
            end
        end
    end
    
    
    

    It outputs something like this

    Generating Pods project
    
    Found 'Google-Mobile-Ads-SDK' on target 'Pods-TheApp'
    Found 'FirebaseAnalytics' on target 'Pods-TheApp'
    Preparing 'Pods-TheApp' for Catalyst
    
    Found 'Google-Mobile-Ads-SDK' on target 'Pods-TheApp-TheAppTests'
    Found 'FirebaseAnalytics' on target 'Pods-TheApp-TheAppTests'
    Preparing 'Pods-TheApp-TheAppTests' for Catalyst
    
    Found 'Google-Mobile-Ads-SDK' on target 'Pods-TheApp-TheApp_iOS_UI_Tests'
    Found 'FirebaseAnalytics' on target 'Pods-TheApp-TheApp_iOS_UI_Tests'
    Preparing 'Pods-TheApp-TheApp_iOS_UI_Tests' for Catalyst
    
    Found 'Google-Mobile-Ads-SDK' on target 'Pods-TheAppIntentsExtension'
    Found 'FirebaseAnalytics' on target 'Pods-TheAppIntentsExtension'
    Preparing 'Pods-TheAppIntentsExtension' for Catalyst
    
    Found 'Google-Mobile-Ads-SDK' on target 'Pods-TheAppTodayExtension'
    Found 'FirebaseAnalytics' on target 'Pods-TheAppTodayExtension'
    Preparing 'Pods-TheAppTodayExtension' for Catalyst
    

提交回复
热议问题