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

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

报错信息

[!] 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版本问题

报错信息

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

报错信息

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,也可以下方留言评论,小伙伴们一起来解决!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

技术杠精

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值