I'm trying to run my app on iOS but getting the following error:
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>'
Upon searching I went through a lot of fixes here and there but nothing worked, and to make it clear I can even create a build successfully without any issues, only running the app causes this.
currently I've export LANG=en_US.UTF-8
added in booth ~/.profile & ~/.zshrc and even when running locale
in my terminal I get the following results:
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"
And when running pod install from iOS directory it works fine and runs successfully, don't know what may cause this issue when running the app.
To sum up, and why this is not a duplicate:
source 'https://cdn.cocoapods.org/'
added to my podfile
pod install
with no issues at alllocale
which ruby
command points to /usr/local/opt/ruby/bin/ruby
which sounds goodFinally I found a solution to my issue, only through this link, as it says:
Unfortunately this solution is not obvious for users (myself included) since the common advice for setting macOS Environment Variables in general (including these Cocoapods ones) is to define them in any of .zprofile, .zshrc or .profile files: None of these are respected by Xcode when launching its own 'Run Script' phases.
The variables must be set in the environment in which Xcode itself runs; as user-global environment variables. This is a 'volatile' procedure in macOS, having changed across recent versions. In Monterey it can be achieved with a launchctl task that can be run immediately and registered to run automatically on every reboot.
So mainly yo can use the script provided by the same answer:
Script to enable Cocoapod invocation from Xcode (fix KMM integration) Here is a Kotlin Script that fixes the problem by permanently setting up the required environment variables. The setting survives reboot. The script works by generating an environment variable setting task as a plist and registering it with launchctl.
Pre-requisites:
Kotlin is installed via Homebrew Script is set as executable with chmod +x ./init_cocoapodsEnvironment.main.kts ...then run the script from Terminal with ./init_cocoapodsEnvironment.main.kts
Future improvement While this issue could be closed in light of the workaround above; JetBrains might consider an alternative solution from within Cocoapods/KMM, as I think this will become a very common 'gotcha' as the technology gains more users.
The script:
#!/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."