#!/usr/bin/ruby # Author = Min Hu require 'xcodeproj' require 'cocoapods-bb-PodAssistant/babybus/helpers/babybus_info_plist_helper' require 'cocoapods-bb-PodAssistant/babybus/business/babybus_install_environment' require 'cocoapods-bb-PodAssistant/helpers/pod_utils' class PodPostInstaller def initialize(lib, deployment_target=nil, filter_targets=["test"], is_matrix=true) @lib = lib if deployment_target.nil? is_xcode16 = BB::PodUtils.compare_xcode_16_version if (is_xcode16 == true) then @deployment_target = "13.0" # iOS18最低支持13系统 else @deployment_target = isUnity3DApp ? "12.0" : "11.0" # Unity2022引擎最低支持iOS12.0、unity2d iOS11 、cocos iOS10、超A产品 iOS11 (968广告厂商升级最低支持iOS11) end else @deployment_target = deployment_target end if filter_targets.is_a? Array @filter_targets = filter_targets # 过滤target elsif filter_targets.is_a? String @filter_targets = [filter_targets] # 过滤target end @is_matrix = is_matrix end private def filterTargetName(target_name) for name in @filter_targets if target_name.include?(name) return true end end return false end def run env = BabybusInstallEnv.new() is_xcode15 = BB::PodUtils.compare_xcode_15_version # 是否Untify项目 isUnityProject = isUnityApp # Untify项目需要移除cocos项目res/src目录 if (isUnityProject) then env.createCocosResource end ios_deployment_target = @deployment_target puts "pod组件配置工程最低支持iOS系统 ===> #{ios_deployment_target.to_s.send(:red)}".green @lib.aggregate_targets.first.user_project.save # 解决Xcode13 pod update操作出现failed to save pods.xcodeproj问题 by hm 21/11/8 project = Xcodeproj::Project.open(BB::PodUtils.getXcodeprojPath) project.targets.each do |target| target.build_configurations.each do |config| # if !target.name.include? 'test' if !filterTargetName(target.name) # 过滤target test 工程 if (@is_matrix == true) && (config.name.include? 'Debug') # 只有debug环境才进行替换操作,其它环境交由打包机处理 puts "[#{target.name}/#{config.name}] 开发者debug环境环境替换[PlistMacro/cocos/unity]文件操作,其它环境交由打包机处理".red env.copyPlistMacro # 开发自行打开不能提交到版本控制,避免test包出现配置不正确情况 by hm 22/5/17 if (isUnityProject) then env.copyUnityFramework else env.copyCocosPackage end end # xcode_version = `xcrun xcodebuild -version | grep Xcode | cut -d' ' -f2`.to_f if xcode_version ≥ 15 # iOS17适配添加ld64 https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes if (is_xcode15 == true) then # c++ weak 标识 xcode15 -ld64 is deprecated, use -ld_classic instead config.build_settings['OTHER_LDFLAGS'] = "$(inherited) -lxml2 -lz -ObjC -lstdc++ -Wl -ld_classic -weak_framework SwiftUI" else config.build_settings['OTHER_LDFLAGS'] = "$(inherited) -lxml2 -lz -ObjC -lstdc++" end otherLink_setting_value = config.build_settings['OTHER_LDFLAGS'] puts "#{target.name}-#{config.name} Build Setting 'OTHER_LDFLAGS' Value: #{otherLink_setting_value}" # 配置工程最低部署 origin_value = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] if origin_value.to_i != ios_deployment_target.to_i then config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target.to_s new_value = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] puts "#{target.name}-#{config.name} Build Setting 'IPHONEOS_DEPLOYMENT_TARGET' deployment target: #{origin_value} => #{new_value}" end end end end # projects.config @lib.pod_target_subprojects.each do |project| project.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target if (isUnityProject) then config.build_settings['ARCHS'] = 'arm64' else config.build_settings['ARCHS'] = '$(ARCHS_STANDARD)' end end end # project.targets.config @lib.pod_target_subprojects.flat_map { |p| p.targets }.each do |target| target.build_configurations.each do |config| # pod 1.13.0兼容故去除,避免 # 适配xcode 15 动态库报错: Error 'DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead' # if (is_xcode15 == true) then # xcconfig_path = config.base_configuration_reference.real_path # xcconfig = File.read(xcconfig_path) # xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR") # File.open(xcconfig_path, "w") { |file| file << xcconfig_mod } # end config.build_settings['DEAD_CODE_STRIPPING'] = 'YES' config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target if (isUnityProject) then config.build_settings['ARCHS'] = 'arm64' else config.build_settings['ARCHS'] = '$(ARCHS_STANDARD)' end # fix xcode14手动签名问题 https://github.com/CocoaPods/CocoaPods/issues/11402 # config.build_settings["DEVELOPMENT_TEAM"] = "#{teamid}" # Fix Xcode14 bundle need sign # https://github.com/CocoaPods/CocoaPods/issues/11402#issuecomment-1201464693 if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' end # 编译器优化 config.build_settings['WARNING_CFLAGS'] = '-Wno-documentation -Wno-nullability-completeness -Wno-macro-redefined -Wno-property-attribute-mismatch -Wno-strict-prototypes -Wno-incompatible-pointer-types' config.build_settings['ASSETCATALOG_COMPILER_OPTIMIZATION'] = 'space' config.build_settings['ENABLE_BITCODE'] = 'NO' config.build_settings['DEAD_CODE_STRIPPING'] = 'YES' if config.name.include? 'Debug' config.build_settings['SWIFT_COMPILATION_MODE'] = 'Incremental' config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone' config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0' else config.build_settings['SWIFT_COMPILATION_MODE'] = 'wholemodule' config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Osize' config.build_settings['GCC_OPTIMIZATION_LEVEL'] = 'z' end # C++支持@import (工程中带mm类需要进行控制) if (target.name.include? 'matrix-wechat') || (target.name.include? 'Sentry') # 三方库不支持modulemap config.build_settings['OTHER_CPLUSPLUSFLAGS'] = "$(inherited) $(OTHER_CFLAGS)" else config.build_settings['OTHER_CPLUSPLUSFLAGS'] = "$(inherited) $(OTHER_CFLAGS) -fmodules -fcxx-modules" end end # 修复警告 Run script build phase '[CP] Copy Pods Resources' will be run during every build because it does not specify any outputs fix_phases = target.shell_script_build_phases.find { |x| x.name == '[CP] Copy XCFrameworks' || 'Create Symlinks to Header Folders' } if fix_phases fix_phases.always_out_of_date = "1" end project.save end end end