Fixing iOS compile issues in Flutter

I am not an iOS developer, so CocoaPods errors are foreign to me. I'll  document the common errors I get and how I fixed them for future reference.

Nov 2019: pod update

Once I tried to compile my app, and suddenly I got these errors:

    [!] CocoaPods could not find compatible versions for pod "GoogleSignIn":
      In snapshot (Podfile.lock):
        GoogleSignIn (= 4.4.0, ~> 4.0)

      In Podfile:
        google_sign_in (from `.symlinks/plugins/google_sign_in/ios`) was resolved to 0.0.1, which depends on
          GoogleSignIn (~> 5.0)


    You have either:
     * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
     * changed the constraints of dependency `GoogleSignIn` inside your development pod `google_sign_in`.
       You should run `pod update GoogleSignIn` to apply changes you've made.

Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.
To update the CocoaPods specs, run:
  pod repo update

So I ran pod repo update:

% cd ios
ios % pod repo update
Updating spec repo `master`
  $ /usr/local/bin/git -C /Users/myself/.cocoapods/repos/master fetch origin --progress
  remote: Enumerating objects: 154844, done.        
  remote: Counting objects: 100% (154844/154844), done.        
  remote: Compressing objects: 100% (222/222), done.        
  remote: Total 1011555 (delta 154697), reused 154608 (delta 154608), pack-reused 856711        
  Receiving objects: 100% (1011555/1011555), 112.51 MiB | 4.63 MiB/s, done.
  Resolving deltas: 100% (662823/662823), completed with 29957 local objects.
  From https://github.com/CocoaPods/Specs
     b1c83eec505..7a54ba26aa5  master       -> origin/master
   * [new branch]              cdn_scripts  -> origin/cdn_scripts
   * [new branch]              indexes      -> origin/indexes
   * [new branch]              netlify      -> origin/netlify
   * [new branch]              orta-patch-1 -> origin/orta-patch-1
  $ /usr/local/bin/git -C /Users/myself/.cocoapods/repos/master rev-parse --abbrev-ref HEAD
  master
  $ /usr/local/bin/git -C /Users/myself/.cocoapods/repos/master reset --hard origin/master
  HEAD is now at 7a54ba26aa5 [Add] EasyRest 1.2.0
Updating spec repo `trunk`

Building still didn't work, giving me the same error telling me to run pod repo update.

❌  error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

So this time I tried pod install and pod install --repo-update:

% cd ios
ios % pod install
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "GoogleSignIn":
  In snapshot (Podfile.lock):
    GoogleSignIn (= 4.4.0, ~> 4.0)

  In Podfile:
    google_sign_in (from `.symlinks/plugins/google_sign_in/ios`) was resolved to 0.0.1, which depends on
      GoogleSignIn (~> 5.0)


You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * changed the constraints of dependency `GoogleSignIn` inside your development pod `google_sign_in`.
   You should run `pod update GoogleSignIn` to apply changes you've made.

[!] Automatically assigning platform `iOS` with version `8.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

ios % pod install --repo-update
Updating local specs repositories
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "GoogleSignIn":
  In snapshot (Podfile.lock):
    GoogleSignIn (= 4.4.0, ~> 4.0)

  In Podfile:
    google_sign_in (from `.symlinks/plugins/google_sign_in/ios`) was resolved to 0.0.1, which depends on
      GoogleSignIn (~> 5.0)


You have either:
 * changed the constraints of dependency `GoogleSignIn` inside your development pod `google_sign_in`.
   You should run `pod update GoogleSignIn` to apply changes you've made.

It's only after running pod update GoogleSignIn that things started to look green:

% pod update GoogleSignIn
Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Installing AppAuth (1.3.0)
Installing BoringSSL-GRPC (0.0.3)
Installing FMDB (2.7.5)
Installing Firebase (6.12.0)
Installing FirebaseAnalytics (6.1.5)
Installing FirebaseAuth (6.3.1)
Installing FirebaseAuthInterop (1.0.0)
Installing FirebaseCore (6.3.3)
Installing FirebaseCoreDiagnostics (1.1.1)
Installing FirebaseCoreDiagnosticsInterop (1.1.0)
Installing FirebaseFirestore (1.7.0)
Installing FirebaseInstanceID (4.2.7)
Installing FirebaseStorage (3.4.1)
Installing Flutter (1.0.0)
Installing GTMAppAuth (1.0.0)
Installing GTMSessionFetcher (1.3.0)
Installing GoogleAppMeasurement (6.1.5)
Installing GoogleDataTransport (3.0.1)
Installing GoogleDataTransportCCTSupport (1.2.1)
Installing GoogleSignIn (5.0.2)
Installing GoogleUtilities (6.3.1)
Installing Protobuf (3.10.0)
Installing cloud_firestore (0.0.1)
Installing firebase_analytics (0.0.1)
Installing firebase_auth (0.0.1)
Installing firebase_core (0.0.1)
Installing firebase_storage (0.0.1)
Installing flutter_sound (0.0.1)
Installing flutter_tts (0.0.1)
Installing gRPC-C++ (0.0.9)
Installing gRPC-Core (1.21.0)
Installing google_sign_in (0.0.1)
Installing leveldb-library (1.22)
Installing nanopb (0.3.9011)
Installing path_provider (0.0.1)
Installing permission_handler (3.3.0)
Installing share (0.5.2)
Installing sqflite (0.0.1)
Installing url_launcher (0.0.1)
Generating Pods project
Integrating client project
Pod installation complete! There are 14 dependencies from the Podfile and 39 total pods installed.

[!] Automatically assigning platform `iOS` with version `8.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

Trying to compile again, I get a different error:

% flutter build ios --release --no-codesign
Warning: Building for device with codesigning disabled. You will have to manually codesign before deploying to device.
Building com.myorg.myapp for device (ios-release)...
 
Running pod install...                                              9.2s
Warning: Podfile is out of date
  This can cause a mismatched version of Flutter to be embedded in your app, which may result in App Store submission rejection or crashes.
  If you have local Podfile edits you would like to keep, see https://github.com/flutter/flutter/issues/24641 for instructions.
To regenerate the Podfile, run:
  rm ios/Podfile

It's only after removing ios/Podfile that it finally compiled:

% rm ios/Podfile
% flutter build ios --release --no-codesign
 
Warning: Building for device with codesigning disabled. You will have to manually codesign before deploying to device.
Building com.myorg.myapp for device (ios-release)...
 
Running pod install...                                             10.8s
Running Xcode build...                                                  
                                                   
 ├─Building Dart code...                                         
  138.6s (!)                                       
 ├─Generating dSYM file...                                   2.4s
 ├─Stripping debug symbols...                                1.4s
 ├─Assembling Flutter resources...                           2.2s
 └─Compiling, linking and signing...                        83.8s
Xcode build done.                                           693.6s
Built /Users/myself/.../build/ios/iphoneos/Runner.app.

If this was the only step required, I wish it had told me from the start.

May 2020: incompatible Firebase libs

After upgrading Firebase versions in my pubspec.yaml, things were still fine in Android, but started breaking in iOS. pod install would fail with this error:

[!] CocoaPods could not find compatible versions for pod "Firebase/Auth":
  In snapshot (Podfile.lock):
    Firebase/Auth (= 6.34.0, ~> 6.3)

  In Podfile:
    firebase_auth (from `.symlinks/plugins/firebase_auth/ios`) was resolved to 1.1.4, which depends on
      Firebase/Auth (= 7.11.0)

Specs satisfying the `Firebase/Auth (= 6.34.0, ~> 6.3), Firebase/Auth (= 7.11.0)` dependency were found, but they required a higher minimum deployment target.

Not sure what they mean by higher minimum deployment target. My Podfile already specified deployment target 10, which should be sufficient, and the iOS specific Firebase docs (https://firebase.google.com/support/release-notes/ios#version_7110_-_april_20_2021) didn't mention a deployment target to change.

So I tried the same trick as last year, using pod update package_name. When I ran pub update Firebase/Auth, I got this error:

LoadError - dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/lib/ffi_c.bundle, 0x0009): missing compatible arch in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/lib/ffi_c.bundle - /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/lib/ffi_c.bundle

A few GitHub tickets like this one mention you should install ffi with Rosetta enabled: sudo arch -x86_64 gem install ffi. After which you should run the install or update command, also using arch: arch -x86_64 pod update Firebase/Auth.

% arch -x86_64 pod update Firebase/Auth
Updating local specs repositories
Analyzing dependencies
cloud_firestore: Using Firebase SDK version '7.11.0' defined in 'firebase_core'
firebase_auth: Using Firebase SDK version '7.11.0' defined in 'firebase_core'
firebase_core: Using Firebase SDK version '7.11.0' defined in 'firebase_core'
firebase_storage: Using Firebase SDK version '7.11.0' defined in 'firebase_core'
[!] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly":
  In Podfile:
    firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`) was resolved to 0.0.1, which depends on
      Firebase/Analytics (~> 6.0) was resolved to 6.0.0, which depends on
        Firebase/Core (= 6.0.0) was resolved to 6.0.0, which depends on
          Firebase/CoreOnly (= 6.0.0)

    firebase_core (from `.symlinks/plugins/firebase_core/ios`) was resolved to 1.1.1, which depends on
      Firebase/CoreOnly (= 7.11.0)

So it looks like it's because Firebase Analytics was still using a version that was too old. My pubspec.yaml looked like this:

  cloud_firestore: ^1.0.0
  firebase_analytics: ^5.0.9
  firebase_auth: ^1.0.1
  firebase_core: ^1.0.0
  firebase_storage: ^8.0.0

I can see in firebase_analytics's release notes that in version 6.1.0, they updated Firebase iOS SDK from version 6.26.0 to 6.33.0, and in version 7.0.0, they started depending on version 7.3.0. Should I migrate all the way to 8.0.4?

After doing so, and running pod install, I got a different error:

[!] CocoaPods could not find compatible versions for pod "Firebase/CoreOnly":
  In snapshot (Podfile.lock):
    Firebase/CoreOnly (= 6.34.0)

  In Podfile:
    firebase_core (from `.symlinks/plugins/firebase_core/ios`) was resolved to 1.1.1, which depends on
      Firebase/CoreOnly (= 7.11.0)


You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * changed the constraints of dependency `Firebase/CoreOnly` inside your development pod `firebase_core`.
   You should run `pod update Firebase/CoreOnly` to apply changes you've made.

So I ran arch -x86_64 pod update Firebase/CoreOnly and things started looking green.

I also checked firebase_core's release notes. I was using version 1.0.0 I can see that in version 1.1.0, they went from the SDK 7.3 to 7.11. So version 1.0.0 is using 7.3.

I wonder what made pod use 7.11 instead of 7.3.