Fultter项目中IOS打包问题整理(附带解决方案)

Fultter项目中IOS打包问题整理(附带解决方案)

问题一:CocoaPods 在你的项目中找不到名为 AlicloudPush 版本为 ~> 1.9.1 的 Pod 规范。

报错信息

java 复制代码
[!] Unable to find a specification for `AlicloudPush (~> 1.9.1)`
 
You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

问题分析

AlicloudPush 这个 Pod 是在私有的 Podspec 仓库中,需要确保项目中已经正确配置了这个私有仓库。其他Pod同理。

解决方法

  1. 找到项目/iOS文件夹下的Profile文件,在文件中添加:source 'https://github.com/aliyun/aliyun-specs.git'。

  2. 并且为工程target添加依赖,例:引入AlicloudPush依赖:

    pod 'AlicloudPush', '~> 1.9.1'

问题二:ruby版本问题

报错信息

java 复制代码
Error
 
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/lib/cocoapods/installer.rb:170:in `install!'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/lib/cocoapods/command/install.rb:52:in `run'
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'
...
wrong argument type String (expected Regexp) 
Line: 1
Position: 38
Last 80 unconsumed characters:
<?xml version="1.0" encoding="UTF-8"?>
/Library/Ruby/Gems/2.6.0/gems/rexml-3.2.9/lib/rexml/parsers/treeparser.rb:96:in `rescue in parse'
......
/Library/Ruby/Gems/2.6.0/gems/cocoapods-1.15.2/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:23:in `load'
/usr/local/bin/pod:23:in `<main>'
 
――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
 
[!] Oh no, an error occurred.
 
Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=%23%3CTypeError%3A+wrong+argument+type+String+%28expected+Regexp%29%3......
 
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
 
Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
 
Don't forget to anonymize any private data!
 
Looking for related issues on cocoapods/cocoapods...
Searching for inspections failed: undefined method `map' for nil:NilClass
 
[!] 'WechatOpenSDK-XCFramework' uses the unencrypted 'http' protocol to transfer the Pod. Please be sure you're in a safe network with only trusted hosts. Otherwise, please reach out to the library author to notify them of this security issue.

问题分析

将此报错信息抛给chatgpt,发现'wrong argument type String (expected Regexp) '这行报错很可能是由于 Ruby 版本不兼容或过低所导致的。

当前ruby版本是2.6.0,cocoapods规范库的版本是1.15.2。

而 cocoapods-1.15.2 可能升级到 Ruby 2.7.x 或更高版本才能正确运行。

问题原因

ruby 和 cocoapods 版本不兼容。

解决方法

更新ruby的版本以满足cocoapods的要求。

仍然可能存在问题:

通过ruby -v查看版本号,发现ruby的新版本并未生效。

解决方法:

即使你更新了最新版本的ruby,但是通过ruby -v查看版本号,发现还是旧的版本号,说明并没有生效。

原因:

Mac os自带一个ruby版本,并且默认生效,我们即使下载了新版本的ruby,也有可能不生效。

解决方法:

我们可以通过设置环境变量,强行让新版本ruby生效。

打开~/.bash_profile文件或者 ~/.zshrc文件,添加这行代码:

export PATH="/opt/homebrew/Cellar/ruby/3.3.4/bin:$PATH"

将下划线部分地址换成自己本地新版本的ruby地址

最后,通过 source ~/.bash_profile 让配置文件生效。

注意:

mac的~/.bash_profile文件,使用source命令生效,但是新建窗口时就会失效。

原因有可能是:

  1. 重新打开窗口是非登陆shell,一般来说,macOS 终端在启动时会使用非登录 shell,因此 .bash_profile 可能不会自动生效,可以手动再执行source命令使其生效。
  2. 自 macOS Catalina 开始,默认的 shell 已从 Bash 切换到 Zsh。如果你在使用 Zsh 而不是 Bash,那么 .bash_profile 文件将不会被 Zsh 加载。相应的,Zsh 使用的是 .zshrc 文件。所以将环境变量的配置都移至~/.zshrc文件下,我使用的是这个方法。不需要后面经常手动使其生效。

问题三:cocoapods规范库的问题

解决方法

方法一:

  1. 找到项目/ios文件夹下的Profile文件,在文件中添加:source 'https://github.com/aliyun/aliyun-specs.git'。
  2. 需要科学上网并且修改git的代理地址,不然下载经常失败或者中断。
    设置代理
    git config --global http.proxy http://127.0.0.1:代理端口号
    取消代理
    git config --global --unset http.proxy

方法二:

  1. 找到项目/ios文件夹下的Profile文件,在文件中添加:source '/Users/linshang/.cocoapods/repos/cocoapods'。下划线部分换成自己的本地地址。
  2. 克隆cocoapods规范库到本地:
    cd ~/.cocoapods/repos
    git clone https://github.com/CocoaPods/Specs.git ~/.co coapods/repo/cocoapods
    pod install --repo-update

问题四:证书问题

使用flutter命令对ios进行编译:flutter build ios

报错信息

java 复制代码
Changing current working directory to: /Users/linshang/Documents/aiyunhua_ai_app
Building com.linshang.app for device (ios-release)...
Automatically signing iOS for device deployment using specified development team
in Xcode project: QW5598QK8Y
Running pod install... 1,967ms
Running Xcode build... 
Xcode build done. 14.1s
Failed to build iOS app
Error (Xcode): No profile for team 'QW5598QK8Y' matching 'sunhui_profile' found:
Xcode couldn't find any provisioning profiles matching
'QW5598QK8Y/sunhui_profile'. Install the profile (by dragging and dropping it
onto Xcode's dock item) or select a different one in the Signing & Capabilities
tab of the target editor.
/Users/linshang/Documents/aiyunhua_ai_app/ios/Runner.xcodeproj

It appears that there was a problem signing your application prior to
installation on the device.

Verify that the Bundle Identifier in your project is your signing id in Xcode
open ios/Runner.xcworkspace

Also try selecting 'Product > Build' to fix the problem.
Encountered error while building for device.

原因

这个报错信息是因为 Xcode 在构建应用时,未能找到与你的 Apple 开发者账户(team 'QW5598QK8Y')相关联的匹配的配置描述文件(provisioning profile)。

可能的原因:

  1. 描述文件不存在:你可能没有为这个特定的应用创建或下载相应的描述文件。
  2. 描述文件未同步:描述文件已经创建,但没有同步到你的 Xcode 项目中。
  3. 团队 ID 或描述文件名称错误:在 Xcode 项目设置中,选择的团队 ID 或描述文件名称不正确。
  4. 描述文件已过期或无效:描述文件可能已经过期或因其他原因无效。

解决方法

  1. 检查团队 ID 和描述文件:
  • 在 Xcode 中打开你的项目,选择项目设置(Project Navigator 中的项目名称),然后选择 "Signing & Capabilities" 选项卡。
  • 确保选择了正确的团队 ID,并且 "Provisioning Profile" 是你在 Apple 开发者网站上创建的有效描述文件。
  • 如果描述文件未能自动选择或显示,点击 "Download Profile" 按钮以手动同步。
  1. 手动生成并下载描述文件:
  • 登录到 Apple 开发者账号。
  • 在 "Certificates, IDs & Profiles" 中,找到对应的 App ID,生成新的描述文件,并确保将其下载到本地。
  • 将下载的描述文件双击导入到 Xcode 中,或手动将其放入 ~/Library/MobileDevice/Provisioning Profiles/ 目录。
  1. 更新描述文件:
  • 如果描述文件过期或失效,需要重新生成新的描述文件。然后在 Xcode 中重新选择和同步该文件。
  1. 检查自动签名设置:
  • 如果使用的是自动签名,确保 Xcode 设置为自动管理签名,并选择正确的团队和签名证书。

最后

这几个问题都是我实际打包过程中遇到并解决的,希望以上的解决方法对你有用,如果你有其他的问题,可以第一时间问gpt,也可以下方留言评论,小伙伴们一起来解决!

相关推荐
一只大侠的侠1 小时前
Flutter开源鸿蒙跨平台训练营 Day 10特惠推荐数据的获取与渲染
flutter·开源·harmonyos
未来侦察班5 小时前
一晃13年过去了,苹果的Airdrop依然很坚挺。
macos·ios·苹果vision pro
renke33645 小时前
Flutter for OpenHarmony:色彩捕手——基于HSL色轮与感知色差的交互式色觉训练系统
flutter
子春一7 小时前
Flutter for OpenHarmony:构建一个 Flutter 四色猜谜游戏,深入解析密码逻辑、反馈算法与经典益智游戏重构
算法·flutter·游戏
铅笔侠_小龙虾8 小时前
Flutter 实战: 计算器
开发语言·javascript·flutter
微祎_9 小时前
Flutter for OpenHarmony:构建一个 Flutter 重力弹球游戏,2D 物理引擎、手势交互与关卡设计的工程实现
flutter·游戏·交互
一起养小猫10 小时前
Flutter for OpenHarmony 实战_魔方应用UI设计与交互优化
flutter·ui·交互·harmonyos
hudawei99610 小时前
flutter和Android动画的对比
android·flutter·动画
一只大侠的侠10 小时前
Flutter开源鸿蒙跨平台训练营 Day7Flutter+ArkTS双方案实现轮播图+搜索框+导航组件
flutter·开源·harmonyos
锐意无限11 小时前
Swift 扩展归纳--- UIView
开发语言·ios·swift