Firebase doesn't build on M1 simulator (Cannot find 'Analytics' in scope)

Viewed 3134

Since I have switched to M1, it has proven impossible running the app on the simulator. On the device itself it works fine.

I get the build error: Cannot find 'Analytics' in scope

import Firebase

class AlertService: AlertServiceBase, AlertServiceProtocol {

  func showWarningAlert(dict: NSDictionary) {
     ...
     Analytics.logEvent("blocked_no_more_warning", parameters: nil)
  }
}

I spoke to an Apple engineer and he said to change all Pods architecture to Standard Architectures (arm64, armv7) - $(ARCHS_STANDARD).

It helped a bit to progress further, but then it failed on the firebase analytics issue. He suggested to post the issue here on SO. Hopefully someone had this before. Thanks

3 Answers

I had this issue only when debugging on a physical device, simulator worked fine.

Additional to the import Firebase, I had to import FirebaseAnalytics

Run pod update to update to a more recent Firebase version. Firebase fully supports the M1 simulator since about the 7.7.0 release.

Go to Project (NOT TARGET)

  • Build Settings
  • Excluded Architectures
  • Debug -

Add a new setting called

Any iOS Simulator SDK - arm64

If you are using Pods, you should repeat above for your Pods PROJECT as well.

Some pod targets (like pod KeychainAccess in your case) might not be respecting what you had set at Pods PROJECT level, you might want to fix this exact same thing for offending Pod targets as well.

Or instead of checking all of the pod targets one by one, you could add this at the end of your podfile -

post_install do |installer|
  installer.project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end
  end
end

After doing this, do a pod install and a clean build, you should be good to go.

Related