building for iOS Simulator, but linking in object file built for iOS

3 篇文章 0 订阅
ld: building for iOS Simulator, but linking in object file built for iOS, file 'xxx/Pods/mob_sharesdk/ShareSDK/Support/PlatformConnector/QQConnector.framework/QQConnector' for architecture arm64

上篇文章讲了M1芯片安装CocoaPods问题,刚刚配置好pods环境。新的问题又出现了:运行项目时,编译不通过,模拟器报错,出现了上面的问题,而真机是可以运行的!Xcode版本12.4,模拟器是iOS14.4。而且在我电脑上(15款Macbook Pro)模拟器可以运行,真机也可以运行,新买的电脑M1芯片的运行却报错。
看了网上的内容,大致有几种方案都试了还是不行!

  1. 搜索VALID_ARCHS字段,将里面的值去掉或加上x86_64,或将整个字段删除。我搜索之后却没有个这值。
  2. 在Build Settings下Architecture中Excluded Architecture 属性加上 arm64,并且Build Active Architecture Only 设置为 NO。
  3. 删除.xcworkspace和Podfile.lock文件,重新pod install;删除Xcode缓存,点击访达Shift + command + G进入,输入~/Library/Developer/Xcode/DerivedData,删除里面的全部文件;多次重启Xcode。

在进行第二种方法的时候,出现以下错误

Cocoapods ld: library not found for -lPods-Projectname

解决方法(附件参考文章1)是在Build Phases下Link Binary With Libraries删除libPods-Projectname.a。然后出现缺少x86_64和i386,在arm64那加上这两个还是不可以,于是放弃了这种方法!
以上方法都试了,都不行!感觉是pods设置的问题,多次注掉Podfile文件里的库,然后执行pod install,还是报错!

然后找到了一篇文章(附件参考文章2)中的解决方法
  1. 在Excluded Architecture下增加 Any iOS Simulator SDK属性,值是arm64,并且Build Active Architecture Only 都设置为 YES(NO的话也运行不了)。

  2. Podfile或Podspec文件中设置

  • Podfile文件中增加代码:
post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
end

然后执行pod install,执行后会自动在Podspec中添加上面的pod设置代码。

  • 在Podspec文件中添加pod设置代码:
s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }

然后执行pod install

到这里模拟器就可以运行了,经测试真机也能正常运行。不像网上说的还要改回来真机才可以运行!
  • 但是在执行pod install的时候终端出现了以下警告:
[!] The `HaoYaoZaiXianB [Debug]` target overrides the `EXCLUDED_ARCHS[sdk=iphonesimulator*]` build setting defined in `Pods/Target Support Files/Pods-HaoYaoZaiXianB/Pods-HaoYaoZaiXianB.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `HaoYaoZaiXianB [Release]` target overrides the `EXCLUDED_ARCHS[sdk=iphonesimulator*]` build setting defined in `Pods/Target Support Files/Pods-HaoYaoZaiXianB/Pods-HaoYaoZaiXianB.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

于是按照提示在Excluded Architecture下Debug和Release后面值增加$(inherited)。然后执行pod install就没有警告了!
我又按照文章里的其他方法试了,也不可以。最后pod环境都搞坏了,出现错误
failed to read asset tags: Error Domain=NSPOSIXErrorDomain Code=9 "Bad file
只能删掉.xcworkspace和Podfile.lock文件,重新pod install。果然重新恢复正常!

到这里就基本结束了,总结一下方法:
  1. Excluded Architecture中Debug和Release添加Any iOS Simulator SDK属性,添加值arm64并且设置Active Architecture都为YES
  2. Podfile文件添加设置,在指定source源后面(target前添加)添加
post_install do |installer|
  installer.pods_project.build_configurations.each do |config|
    config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
  end
end
  1. Excluded Architecture中Debug和Release后面值增加$(inherited),去除pod install警告

原因在参考文章里有,因为是英文的(本人英文能力有限),具体原因我也是一知半解,只知道是M1芯片(与Intel芯片架构不同)才有这个问题!至于后续这样设置会出现其他问题吗,我也不清楚!但是项目却是可以正常运行的,而且真机调试的时候不用删除设置,省去了很多麻烦!

参考文章:

  1. stackoverflow参考文章1
  2. stackoverflow参考文章2
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值