pod install in flutter iOS project gives base64: invalid input

858 Views Asked by At

After some downtime I'm trying to build my Flutter app for iOS without success. pod intall gives me the following output (even after cleaning the XCode workspace):

$ pod install
Analyzing dependencies
cloud_firestore: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
firebase_analytics: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
firebase_auth: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
firebase_core: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
Warning: firebase_app_id_file.json file does not exist. This may cause issues in upload-symbols. If this error is unexpected, try running flutterfire configure again.
firebase_crashlytics: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
firebase_dynamic_links: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
firebase_messaging: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
firebase_remote_config: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
firebase_storage: Using Firebase SDK version '8.15.0' defined in 'firebase_core'
Downloading dependencies
Installing AppAuth (1.5.0)
Installing BoringSSL-GRPC (0.0.24)
[!] /opt/homebrew/bin/bash -c
set -e
set -e
# Add a module map and an umbrella header
mkdir -p src/include/openssl
cat > src/include/openssl/umbrella.h <<EOF
  #include "ssl.h"
  #include "crypto.h"
  #include "aes.h"
  /* The following macros are defined by base.h. The latter is the first file included by the
     other headers. */
  #if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
  #  include "arm_arch.h"
  #endif
  #include "asn1.h"
  #include "asn1_mac.h"
  #include "asn1t.h"
  #include "blowfish.h"
  #include "cast.h"
  #include "chacha.h"
  #include "cmac.h"
  #include "conf.h"
  #include "cpu.h"
  #include "curve25519.h"
  #include "des.h"
  #include "dtls1.h"
  #include "hkdf.h"
  #include "md4.h"
  #include "md5.h"
  #include "obj_mac.h"
  #include "objects.h"
  #include "opensslv.h"
  #include "ossl_typ.h"
  #include "pkcs12.h"
  #include "pkcs7.h"
  #include "pkcs8.h"
  #include "poly1305.h"
  #include "rand.h"
  #include "rc4.h"
  #include "ripemd.h"
  #include "safestack.h"
  #include "srtp.h"
  #include "x509.h"
  #include "x509v3.h"
EOF
cat > src/include/openssl/BoringSSL.modulemap <<EOF
  framework module openssl {
    umbrella header "umbrella.h"
    textual header "arm_arch.h"
    export *
    module * { export * }
  }
EOF

# To avoid symbol conflict with OpenSSL, gRPC needs to rename all the BoringSSL symbols with a
# prefix. This is done with BoringSSL's BORINGSSL_PREFIX mechanism
# (https://github.com/google/boringssl/blob/75148d7abf12bdd1797fec3c5da9a21963703516/BUILDING.md#building-with-prefixed-symbols).
# The required prefix header file boringssl_prefix_symbols.h is not part of BoringSSL repo at
# this moment. It has to be generated by BoringSSL's users and be injected to BoringSSL build.
# gRPC generates this file in script /tools/distrib/upgrade_boringssl_objc.sh. This script
# outputs a gzip+base64 encoded version of boringssl_prefix_symbols.h because of Cocoapods'
# limit on the 'prepare_command' field length. The encoded header is generated from
# /src/boringssl/boringssl_prefix_symbols.h. Here we decode the content and inject the header to
# the correct location in BoringSSL.
case "$(uname)" in
  Darwin) opts="" ;;
       *) opts="--ignore-garbage" ;;
esac
base64 --decode $opts <<EOF | gunzip > src/include/openssl/boringssl_prefix_symbols.h
  *** SNIP: long base 64 string ***
EOF

# We are renaming openssl to openssl_grpc so that there is no conflict with openssl if it exists
find . -type f \( -path '*.h' -or -path '*.cc' -or -path '*.c' \) -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include <openssl/;#include <openssl_grpc/;g'

# Include of boringssl_prefix_symbols.h does not follow Xcode import style. We add the package
# name here so that Xcode knows where to find it.
find . -type f \( -path '*.h' -or -path '*.cc' -or -path '*.c' \) -print0 | xargs -0 -L1 sed -E -i'.grpc_back' 's;#include <boringssl_prefix_symbols.h>;#include <openssl_grpc/boringssl_prefix_symbols.h>;g'

base64: invalid input
gunzip: (stdin): unexpected end of file

If I copy the base64 string from the output above and run it through base64 --decode I do get the same error (invalid input":

cat base64.txt | base64 --decode
�boringssl_prefix_symbols.h��]s۸�h��W��ܩ:5;�n�base64: invalid input

I have no idea if this is an issue with my environment, cocoapods, BoringSSL-GRPC or something that depends on it (one of the firebase packages maybe?). Would really appreciate if anyone has any pointers.

Environment Hardware: Mac mini M1 Cocoapods: 1.11.3 from Homebrew Flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.4 21F79 darwin-arm, locale en-SE)
[✗] Android toolchain - develop for Android devices
    ✗ ANDROID_HOME = /Users/tjarvstrand/Android/Sdk
      but Android SDK not found at this location.
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2021.1)
[!] Android Studio
    ✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Community Edition (version 2021.3.3)
[✓] VS Code (version 1.67.2)
[✓] VS Code (version 1.66.2)
[✓] Connected device (1 available)
[✓] HTTP Host Availability

! Doctor found issues in 3 categories.
2

There are 2 best solutions below

4
On

After some thorough digging, it turns out that this was due to me having GNU coreutils installed on my system, so the installation was using an incompatible base64 command.

EDIT: To clarify, my PATH environment variable was set up so that base64 called the GNU version of the command which did not like the input arguments passed by Cocapods. I solved my problem by changing my PATH so that the system base64 command was invoked instead. Not sure exactly how/why they are incompatible in this case but this fixed my issue.

1
On

So, building upon the given solution, what this translates to is commenting the following lines inside your ~/.bash_profile or ~/.zshrc (depending to what you are using):



export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH"
PATH=$(brew --prefix)/opt/findutils/libexec/gnubin:$PATH
PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

After doing this editing, do not forget to execute source ~/.bash_profile or source ~/.zshrc before retrying to install the pods.

Basically, before this procedure, which base64 would print:
/opt/homebrew/opt/coreutils/libexec/gnubin/base64

But, after this procedure, which base64 would print this instead:
/usr/bin/base64