Solved: WARNING: CocoaPods requires your terminal to be using UTF-8 encoding
Recently, I encounter an error like below, when I build the application with command line it can work, but build in the Xcode, it report…
Recently, I encounter an error like below, when I build the application with command line it can work, but build in the Xcode, it report the error like below:
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:
export LANG=en_US.UTF-8
Some tried methods
- Add
export LANG=en_US.UTF-8
to~/.profile
file - Add
export LANG=en_US.UTF-8
to~/.bashrc
- Add
export LANG=en_US.UTF-8
to~/.zshrc
- Add
export LANG=en_US.UTF-8
toshared.podspecs
With above methods, sometimes, it can work, but after clean the project and build again, it will report error again, so I want to find the root cause of the problem.
Solution
After search the internet, and I find the clue from CocoaPods installation failure when building for iOS, the solution mentioned in this post is like below:
If anyone else is struggling with this error, I found a solution.
Check the version of cocoapods installed on your machine. This can be done with a terminal command pod — version. If version is 1.11.*, which was released in september (https://github.com/CocoaPods/CocoaPods/releases) and probably not compatible with Unity 2019, you should downgrade it to the latest 1.10.* stable version. Just run commands sudo gem uninstall cocoapods and sudo gem install cocoapods -v 1.10.2.
Hope it helps :)
I find that in my computer, I upgrade the cocoapods and the version is 1.11.3, which is the latest version, so I want to downgrade the cocoapods to have a try, after I downgrade the cocoapods, it works like a charm.
Downgrade cocoapods
When I downgrade cocoapods, also encounter some problem, so I also record it here.
Uninstall cocoapods
# Installed by brew
brew uninstall cocoapods
# Installed with gem
sudo gem uninstall cocoapods
Install cocoapods version 1.10.2
sudo gem install cocoapods -v 1.10.2
# When I install with this command, it report the following error
# You don't have write permissions into the /usr/bin directory
# To solve this error, I use the following command
sudo gem install cocoapods -v 1.10.2 -n /usr/local/bin
Solution 2
Add export LANG=en_US.UTF-8
to the generated shared.podspec
file with gradle script, to implement this function, we can add the following scripts to the build.gradle.kts
file in the shared module.
val podspec = tasks["podspec"] as org.jetbrains.kotlin.gradle.tasks.PodspecTask
podspec.doLast {
val podspec = file("shared.podspec")
val newPodspecContent = mutableListOf<String>()
podspec.readLines().forEach {
newPodspecContent.add(it)
if (it.contains("set -ev")) {
newPodspecContent.add(" export LANG=en_US.UTF-8")
}
}
podspec.writeText(newPodspecContent.joinToString(separator = "\n"))
}