ios Flutter - Unicode标准化不适用于ASCII-8BIT

5f0d552i  于 2023-05-19  发布在  iOS
关注(0)|答案(1)|浏览(260)

我尝试在iOS上运行我的应用程序,但收到以下错误:

Error output from CocoaPods:
↳
        WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
        Consider adding the following to ~/.profile:

        export LANG=en_US.UTF-8
        
    /usr/local/Cellar/ruby/3.2.2/lib/ruby/3.2.0/unicode_normalize/normalize.rb:141:in `normalize': Unicode Normalization not appropriate for ASCII-8BIT (Encoding::CompatibilityError)
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:166:in `unicode_normalize'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:166:in `installation_root'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:226:in `podfile_path'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/user_interface/error_report.rb:105:in `markdown_podfile'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/user_interface/error_report.rb:30:in `report'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:66:in `report_error'
        from /usr/local/lib/ruby/gems/3.2.0/gems/claide-1.1.0/lib/claide/command.rb:396:in `handle_exception'
        from /usr/local/lib/ruby/gems/3.2.0/gems/claide-1.1.0/lib/claide/command.rb:337:in `rescue in run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/claide-1.1.0/lib/claide/command.rb:324:in `run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:52:in `run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/bin/pod:55:in `<top (required)>'
        from /usr/local/bin/pod:25:in `load'
        from /usr/local/bin/pod:25:in `<main>'
    /usr/local/Cellar/ruby/3.2.2/lib/ruby/3.2.0/unicode_normalize/normalize.rb:141:in `normalize': Unicode Normalization not appropriate for ASCII-8BIT (Encoding::CompatibilityError)
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:166:in `unicode_normalize'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:166:in `installation_root'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:226:in `podfile_path'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:205:in `podfile'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:160:in `verify_podfile_exists!'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/command/install.rb:46:in `run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:52:in `run'
        from /usr/local/lib/ruby/gems/3.2.0/gems/cocoapods-1.12.1/bin/pod:55:in `<top (required)>'
        from /usr/local/bin/pod:25:in `load'
        from /usr/local/bin/pod:25:in `<main>'

在搜索时,我在这里和那里进行了大量的修复,但没有任何工作,并明确表示,我甚至可以成功创建一个构建没有任何问题,只有运行应用程序导致这一点。目前我已经在booth ~/.profile & ~/.zshrc中添加了export LANG=en_US.UTF-8,即使在我的终端中运行locale,我也会得到以下结果:

LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

从iOS目录运行Pod安装时,它工作正常并成功运行,不知道运行应用程序时可能会导致此问题。
总结一下,为什么这不是一个重复:

  • 我已将source 'https://cdn.cocoapods.org/'添加到podfile
  • 我可以运行pod install没有任何问题
  • 运行locale时获得正确的unicode
  • 我已经将正确的unicode添加到我的~/.profile和~/.zshrc中
  • which ruby命令指向/usr/local/opt/ruby/bin/ruby,听起来不错
  • 我已经完全重新安装了椰子,但没有运气。
fzwojiic

fzwojiic1#

最后,我找到了解决我的问题的方法,只有通过这个链接,正如它所说:
不幸的是,这个解决方案对用户(包括我自己)来说并不明显,因为一般设置macOS环境变量(包括这些Cocoapods环境变量)的常见建议是在任何.zprofile,.zshrc或.profile文件中定义它们:Xcode在启动它自己的“运行脚本”阶段时,没有考虑到这些。
变量必须在Xcode本身运行的环境中设置;作为用户全局环境变量。这是macOS中的“volatile”过程,在最近的版本中有所变化。在Monterey中,可以通过launchctl任务来实现,该任务可以立即运行,并注册为在每次重新引导时自动运行。
所以主要是yo可以使用脚本提供的相同答案:
从Xcode启用Cocoapod调用的脚本(修复KMM集成)下面是一个Kotlin脚本,它通过永久设置所需的环境变量来修复这个问题。重新启动后,该设置仍然存在。该脚本的工作方式是生成一个环境变量设置任务作为plist并将其注册到launchctl。
先决条件:
Kotlin是通过Homebrew安装的。使用chmod +x将脚本设置为可执行文件。/init_cocoapodsEnvironment.main.kts...然后使用./init_cocoapodsEnvironment.main.kts从终端运行脚本
虽然根据上述变通办法,该问题可以解决; JetBrains可能会考虑在Cocoapods/KMM中使用另一种解决方案,因为我认为随着该技术获得更多用户,这将成为一个非常常见的“陷阱”。
剧本:

#!/bin/bash

# This is a Bash version of Kotlin script 
# https://youtrack.jetbrains.com/issue/KT-54408/CocoaPod-integration-broken-from-Cocoapods-version-1110#focus=Comments-27-6511829.0-0

# TL;DR; Run this script once, to permanently set environment variables required to run CocoaPods from within Xcode.
#
# Here's the long version:
#
# The latest Cocoapods versions now have a hard requirement on the LANG environment variable being set before they will
# execute any operations.
#
# When building a KMM project; due to how well encapsulated the Cocoapod process launch is between Xcode and Gradle,
# it's currently impossible to specify the LANG environment variable from Gradle configuration, or by making a change
# in any part of the Xcode project that won't be overwritten when Cocoapods regenerates it (e.g. by `pod update`).
#
# To overcome this problem; we desire to set a global environment variable on macOS which survives reboots.
# This script achieves it by defining and registering an environment variable setting task to execute on boot.
# The script also immediately launches the task, so you only need to restart Xcode for this to take effect, not the
# whole OS.

# These are the new variables we want to add
# These are required to make Cocoapods work, see: https://github.com/CocoaPods/CocoaPods/issues/10939
NEW_ENVIRONMENT_VARIABLES=(
    "LANG:en_US.UTF-8"
    "LANGUAGE:en_US.UTF-8"
    "LC_ALL:en_US.UTF-8"
)

LAUNCH_LABEL="cocoapods.environment"
ENVIRONMENT_FILE="$HOME/Library/LaunchAgents/$LAUNCH_LABEL.plist"

if test -f "$ENVIRONMENT_FILE"; then
    cat << EOM
The environment-setting launchctl task already exists at:
$ENVIRONMENT_FILE
        
This means you've probably already run this task before, and don't need to run it again.
If you need to clean up a previous run, use launchctl to stop & unload the existing file before deleting it.
Automated cleanup is outside the scope of this script.
EOM
    echo "$MESSAGE"
    exit
fi

SET_ENV_COMMAND=""
for item in "${NEW_ENVIRONMENT_VARIABLES[@]}"; do
    KEY="${item%%:*}"
    VALUE="${item##*:}"
    SET_ENV_COMMAND+="launchctl setenv $KEY $VALUE; "
done

# Create blank plist file for further editing using plutil
echo "Writing launchctl task plist to:"
echo "$ENVIRONMENT_FILE"

cat > "$ENVIRONMENT_FILE" <<- EOM
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
EOM

# Add values to plist
plutil -insert "Label" -string $LAUNCH_LABEL "$ENVIRONMENT_FILE"
plutil -insert "ProgramArguments" -xml '<array/>' "$ENVIRONMENT_FILE"
plutil -insert "ProgramArguments".0 -string 'sh' "$ENVIRONMENT_FILE"
plutil -insert "ProgramArguments".1 -string '-c' "$ENVIRONMENT_FILE"
plutil -insert "ProgramArguments".2 -string "$SET_ENV_COMMAND" "$ENVIRONMENT_FILE"
plutil -insert "RunAtLoad" -bool YES "$ENVIRONMENT_FILE"

echo "...done"

echo "Ensuring correct permissions plist"
chmod 755 "$ENVIRONMENT_FILE"

echo "Load the task immediately"
launchctl load "$ENVIRONMENT_FILE"

echo "Make the task survive reboot"
launchctl start "$ENVIRONMENT_FILE"

echo "All done: If Xcode is open, restart it for this change to take effect."

相关问题