前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ios小白的XCode升级之路

ios小白的XCode升级之路

作者头像
韦东锏
发布2024-03-21 17:58:59
3900
发布2024-03-21 17:58:59
举报
文章被收录于专栏:Android码农Android码农

一切缘由一个XCode的报错

苹果出新政策2024年4月29号前,必现升级XCode和ios SDK,既然躲不开,那就安排升级吧

首先,升级到最新的XCode,必须先升级macOS

于是先升级macOS,从12直接升级到最新的14版本

然后开始升级XCode 1、先卸载现有的XCode版本,避免跟新的XCode冲突 2、通过App Store安装最新版本的XCode

xCode安装完成后,第一次启动,还需要继续安装一个7G多的SDK

耗费大半天,终于升级好了,接下来开始验证公司的项目

公司有两个ios项目,一个是纯flutter的App项目,一个是原生的ios项目,升级完成后,先运行flutter的项目,不出意外的报错了

DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead

作为一个刚入门的ios小白,只好借助Google,搜查了一圈,发现有个答案可能性比较大,尝试之: https://stackoverflow.com/questions/77219650/dt-toolchain-dir-cannot-be-used-to-evaluate-library-search-paths-use-toolchain/77229768#77229768

先更新cocoapods

代码语言:javascript
复制
sudo gem update cocoapods
Password:
Ignoring ffi-1.15.5 because its extensions are not built. Try: gem pristine ffi --version 1.15.5
Updating installed gems
Updating cocoapods

Updating cocoapods会卡住一段时间,估计是包比较大(我有开全局代理,如果没走代理不知道有没有问题)

更新完的日志如下

代码语言:javascript
复制
sudo gem update cocoapods
Password:
Ignoring ffi-1.15.5 because its extensions are not built. Try: gem pristine ffi --version 1.15.5
Updating installed gems
Updating cocoapods
Fetching xcodeproj-1.24.0.gem
Fetching cocoapods-1.15.2.gem
Fetching cocoapods-core-1.15.2.gem
Fetching cocoapods-downloader-2.1.gem
Successfully installed xcodeproj-1.24.0
Successfully installed cocoapods-downloader-2.1
Successfully installed cocoapods-core-1.15.2
Successfully installed cocoapods-1.15.2
Parsing documentation for xcodeproj-1.24.0
Installing ri documentation for xcodeproj-1.24.0
Installing darkfish documentation for xcodeproj-1.24.0
Parsing documentation for cocoapods-downloader-2.1
Installing ri documentation for cocoapods-downloader-2.1
Installing darkfish documentation for cocoapods-downloader-2.1
Parsing documentation for cocoapods-core-1.15.2
Installing ri documentation for cocoapods-core-1.15.2
Installing darkfish documentation for cocoapods-core-1.15.2
Parsing documentation for cocoapods-1.15.2
Installing ri documentation for cocoapods-1.15.2
Installing darkfish documentation for cocoapods-1.15.2
Done installing documentation for xcodeproj, cocoapods-downloader, cocoapods-core, cocoapods after 9 seconds
Parsing documentation for cocoapods-1.15.2
Parsing documentation for cocoapods-core-1.15.2
Parsing documentation for cocoapods-downloader-2.1
Parsing documentation for xcodeproj-1.24.0
Done installing documentation for cocoapods, cocoapods-core, cocoapods-downloader, xcodeproj after 2 seconds
Gems updated: cocoapods cocoapods-core cocoapods-downloader xcodeproj

根据上面的答案,接下来,继续删除旧的缓存,更新pod库

代码语言:javascript
复制
weigan@weigandeMacBook-Pro crm_flutter % cd ios
weigan@weigandeMacBook-Pro ios % flutter clean
Changing current working directory to: /Users/weigan/AndroidStudioProjects/crm_flutter
Cleaning Xcode workspace...                                         5.6s
Deleting build...                                                2,510ms
Deleting .dart_tool...                                             325ms
Deleting Generated.xcconfig...                                       0ms
Deleting flutter_export_environment.sh...                            0ms
Deleting Flutter.podspec...                                          1ms
Deleting .flutter-plugins-dependencies...                            1ms
Deleting .flutter-plugins...                                         0ms
weigan@weigandeMacBook-Pro ios % rm Podfile.lock
weigan@weigandeMacBook-Pro ios % rm -rf Pods/
weigan@weigandeMacBook-Pro ios % flutter pub get
Running "flutter pub get" in crm_flutter...                        11.8s
weigan@weigandeMacBook-Pro ios % pod install
Analyzing dependencies
Downloading dependencies
Installing AMap3DMap (9.1.0)
Installing AMapFoundation (1.6.9)
Installing AMapLocation (2.8.0)
Installing AMapSearch (8.1.0)
Installing Bugly (2.5.91)
Installing FMDB (2.7.5)
Installing Flutter (1.0.0)
Installing GTSDK (2.7.1.0)
Installing Toast (4.0.0)
Installing ZXSDK (3.2.4)
Installing amap_flutter_location (0.0.1)
Installing amap_flutter_map (0.0.1)
Installing device_info_plus (0.0.1)
Installing flutter_document_picker (0.0.1)
Installing flutter_keyboard_visibility (0.0.1)
Installing flutter_local_notifications (0.0.1)
Installing flutter_pdfview (1.0.2)
Installing fluttertoast (0.0.2)
Installing getuiflut (0.0.1)
Installing image_gallery_saver (2.0.1)
Installing image_picker (0.0.1)
Installing install_plugin_ygp (0.0.1)
Installing location_service_check (0.0.1)
Installing package_info_plus (0.4.5)
Installing path_provider_foundation (0.0.1)
Installing permission_handler_apple (9.1.1)
Installing shared_preferences_foundation (0.0.1)
Installing sqflite (0.0.2)
Installing url_launcher_ios (0.0.1)
Installing webview_flutter_wkwebview (0.0.1)
Generating Pods project
Integrating client project
Pod installation complete! There are 23 dependencies from the Podfile and 30 total pods installed.
 
[!] Automatically assigning platform `iOS` with version `11.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
 
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration (`Flutter/Release.xcconfig`).
 
[!] The `Runner [Debug]` target overrides the `EXCLUDED_ARCHS[sdk=iphonesimulator*]` build setting defined in `Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

这里,更新AMap3DMap (9.1.0)卡了比较久,需要有耐心,我差点以为是方法不对,关闭terminal了

继续执行命令:pod update

代码语言:javascript
复制
pod update
Update all pods
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Installing AMap3DMap 9.7.0 (was 9.1.0)
Installing AMapFoundation 1.8.2 (was 1.6.9)
Installing AMapLocation 2.10.0 (was 2.8.0)
Installing AMapSearch 9.7.0 (was 8.1.0)
Installing Bugly 2.5.93 (was 2.5.91)
Installing GTCommonSDK (3.1.0.0)
Installing GTSDK 3.0.5.0 (was 2.7.1.0)
Generating Pods project
Integrating client project
Pod installation complete! There are 23 dependencies from the Podfile and 31 total pods installed.
 
[!] Automatically assigning platform `iOS` with version `11.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
 
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration (`Flutter/Release.xcconfig`).
 
[!] The `Runner [Debug]` target overrides the `EXCLUDED_ARCHS[sdk=iphonesimulator*]` build setting defined in `Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

一步步操作完了,继续继续运行flutter的ios项目,还有新的报错

代码语言:javascript
复制
Framework 'GTCommonSDK' not found

找了一圈,按照官方的文档描述,升级下SDK版本,后来正常了 https://docs.getui.com/getui/mobile/ios/xcode/

继续运行,运行失败,继续新的报错

代码语言:javascript
复制
Command PhaseScriptExecution failed with a nonzero exit code

关于这个问题,网上的说法很多,最多的一个答案是更新文件,尝试后发现本身已经更新了 https://stackoverflow.com/a/75976213/3252800

代码语言:javascript
复制
and edit this section:
if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink "${source}")"
  fi
 
to
if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink -f "${source}")"
  fi

后来找到新的答案,说是flutter版本太旧 https://stackoverflow.com/a/75947102/3252800

那就尝试升级flutter版本,目前的版本是3.3的,这个问题,是在3.7的版本修复的,为了避免升级跨度太大,计划升级到3.7.12,最小可兼容的版本,这里必须吐槽下flutter,官方居然没有升级到指定版本的方法,太low了

研究了一圈,找了个方法

1、直接删除本地的flutter lib包

2、去这个链接 https://docs.flutter.dev/release/archive?tab=macos,下载对应版本的flutter版本的包,解压,放在原来flutter目录下

运行flutter --version命令,果然升级上来了

代码语言:javascript
复制
% flutter --version

┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
Flutter 3.7.12 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4d9e56e694 (11 months ago) • 2023-04-17 21:47:46 -0400
Engine • revision 1a65d409c7
Tools • Dart 2.19.6 • DevTools 2.20.1

继续运行,发现还有新的报错

分析了一圈,感觉不像是代码层面的报错,于是尝试清除缓存后,重新运行,一样报错

后来看了下报错的信息,还是怀疑是缓存的原因,XCode不行,那就用vscode编译看下,第一次编译一直卡在installing,第二次编译居然成功了

在vsCode编译成功后,重新用xCode编译,也正常了

那接下来继续运行archive,看下是否可以满足App Store的要求

校验有报错,看信息,应该是版本号原因,升级版本号后继续,又有新的报错

点击Manage Accounts,会自动更新账号信息,等待几分钟(这里切记要断开翻墙代理,我开着代理总是不成功

再次运行,终于成功了

由于在适配过程中,更新了个推的SDK版本和flutter版本,Android也受到影响了,同时运行crm的Android项目,看下是否正常

确认正常了,也需要同步更新Android ci打包环境的flutter版本,也要同步更新到3.7.12,保持跟本地运行的版本一致

对于另外一个纯ios的App,由于不是基于flutter,只要改下target的版本到12,运行发现没什么报错,然后运行archive验证也是没问题的

以为一切已经结束了,第二天,上线前突然爆出了一个bug,信息如下

代码语言:javascript
复制
*** Assertion failure in void _UIGraphicsBeginImageContextWithOptions(CGSize, BOOL, CGFloat, BOOL)(), UIGraphics.m:410
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIGraphicsBeginImageContext() failed to allocate CGBitampContext: size={392, -0.66666666666666674}, scale=3.000000, bitmapInfo=0x2006. Use UIGraphicsImageRenderer to avoid this assert.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007ff80049b761 __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007ff800063904 objc_exception_throw + 48
    2   Foundation                          0x00007ff800dabb27 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
    3   UIKitCore                           0x00007ff8055b2628 _UIGraphicsBeginImageContextWithOptions + 702
    4   YGP                                 0x00000001075d5db3 -[UIImageView(Placeholder) layoutPlaceholderImage] + 899
    5   YGP                                 0x00000001075d58e8 -[UIImageView(Placeholder) placeholderImage] + 72
    6   YGP                                 0x0000000107538bf0 -[YGPCarouselContentFillImageCell setContent:] + 320
    7   YGP                                 0x0000000107979669 __44-[YGPHomeOperationBannerCell initializeView]_block_invoke + 569
    8   YGP                                 0x00000001079730e0 -[YGPCarousel setupCustomCell:forIndex:cycleScrollView:] + 176

经过排查,是因为给一个组件 UIGraphicsBeginImageContext,传了个负值导致了崩溃 https://blog.csdn.net/qq_43441647/article/details/134034413

在低于ios17的系统,也是传负值,但是不会崩溃,另外XCode升级前,也是没问题的,升级XCode后导致出现了这个问题,问题定位后,做下容错,避免传负值,问题修复了

·········· 这次的升级,共耗时一天半,一路曲折,过程紧张,特此记录下...

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2024-03-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Android码农 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档