iOS 17 适配 Xcode 15 问题

在适配 iOS 17 + xcode 15时遇到的问题,记录一下。

1、 Could not build module ‘WebKit’

type argument 'nw_proxy_config_t' (aka 'struct nw_proxy_config *') is neither an Objective-C object nor a block type

解决方案:

  1. 选中不能编译的库的xcodeproj,在Build Phrases -> Compile Sources,选中所有文件,Complier Flags 里删除 -DOS_OBJECT_USE_OBJC=0

可能是三方库的目标版本比较低,cocoapods兼容低版本自动加上了 -DOS_OBJECT_USE_OBJC=0,也可以修改库的podspec 的 s.platforms = { :ios => “11.0”, :osx => “” } 重新 pod install。

  1. 临时方案

    把 NSArray *proxyConfigurations 编译版本改为180000

    编辑文件 /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk/System/Library/Frameworks/WebKit.framework/Headers/WKWebsiteDataStore.h

    将里面的 170000 修改成 180000。

2、 Assertion failed

Assertion failed: (false && “compact unwind compressed function offset doesn’t fit in 24 bits”), function operator(), file Layout.cpp, line 5758.

解决方法:Other Link Flags 添加-ld64 或者 -ld_classic

路径:Build Settings -> Linking – General -> Other Link Flags 添加-ld64 或者 -ld_classic

post_install do |installer|
  # 调试flutter时打开
#  flutter_post_install(installer) if defined?(flutter_post_install)
  
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
    
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      
      # 同步 pod 库的最低支持版本为 10.0
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
      
      config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
      config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
      
#      config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""

     # pod 也要添加“模拟器排除 arm64 支持”
     config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"

    # 修复 Xcode 15 上,ios 14及以下版本运行时崩溃的问题
	xcode_version = `xcrun xcodebuild -version | grep Xcode | cut -d' ' -f2`.to_f
      if xcode_version ≥ 15
        config.build_settings["OTHER_LDFLAGS"] = "$(inherited) -Wl, -ld_classic"
      end
      
      # 修复 Xcode 14 中,Pod 工程中的 Bundle target 签名报错的问题
      config.build settings["CODE SIGN IDENTITY"] = = ""
      
#      if target.name.eql?('SnapKit')
#        libraries = config.build_settings['OTHER_LDFLAGS']
#        config.build_settings['OTHER_LDFLAGS'] = "#{libraries} -lswiftCoreGraphics"
#        libraryPath = config.build_settings['LIBRARY_SEARCH_PATHS']
#        config.build_settings['LIBRARY_SEARCH_PATHS'] = "#{libraryPath} $(SDKROOT)/usr/lib/swift"
#      end

    end
  end
end

在这里插入图片描述

发现报错,因为项目中有些库没有用到swiftCoreGraphics,比如OC的三方库,或者非UI的库,所以还是要改,需要区分添加。针对项目中Swift类型的UI相关的库,添加这个编译选项,其他的不添加,最终示例如下:

need_otherlinkerflags_frameworks = ['FSPagerView', 'HandyJSON', 'IQKeyboardManagerSwift', 'JXSegmentedView', 'KDCircularProgress', 'Kingfisher', 'RxSwift', 'PKHUD', 'RxCocoa', 'SnapKit', 'ZLPhotoBrowser']
post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          if need_otherlinkerflags_frameworks.include?(target.name)
            config.build_settings['OTHER_LDFLAGS'] = '-Wl,-weak-lswiftCoreGraphics'
          end
        end
    end
end

3、 dyld: Library not loaded: /System/Library/Frameworks/SwiftUI.framework/SwiftUI

dyld: Library not loaded: /System/Library/Frameworks/SwiftUI.framework/SwiftUI
  Referenced from: /var/containers/Bundle/Application/73E9CC61-6EBE-46DB-A786-4E47290284AD/xxx.app/xxx
  Reason: image not found

项目中没有使用SwiftUI ,但是在适配iOS 17时还是报这个问题。

经排查,SwiftUI 使用 LC_LOAD_WEAK_DYLIB,而 Foundation 使用 LC_LOAD_DYLIB。这就是我们想要的。

https://developer.apple.com/forums/thread/126506

解决方法:

路径:Build Settings -> Linking – General -> Other Link Flags 添加-weak_framework SwiftUI

4、 The iOS deployment target ‘IPHONEOS_DEPLOYMENT_TARGET’ is set to xxx

产生原因:

在编译cocoapods管理的三方库时出现了这个警告,原因是该三方库部署目标的系统版本最低要求是8.0,而升级Xcode支持的部署最低版本范围是xxx,不匹配所以报警了。

解决方案:

将所有三方库的部署版本号强制修改到Xcode支持的范围内,代码如下:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 11.0
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
      end
    end
  end
end

4、 真机调试运行会出现iPhone.a文件丢失

升级到xcode 15.1后项目运行报错提示如下:

SDK does not contain 'libarclite' at the path '/Applications/Xcode15.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a'; try increasing the minimum deployment target

进入以下路径查看缺少文件:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/
lib/

目录中 缺少 arc文件夹。

解决方法:

1、从其他旧xcode中将arc文件夹拷贝至xcode 15.1 目录下面(下面步骤可以省略)

2、或新建arc文件夹

3、下载:https://github.com/kamyarelyasi/Libarclite-Files中的libarclite_iphoneos.a

4、将下载下来的文件粘贴到/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc下

重新启动xcode 即可运行

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/54f78a4a47.html