Why does my Flutter app crash at startup on iOS? - ios

I'm trying to build a simple app using Flutter for iOS and Android, but the app crashes on startup when I try to run it on an iPhone (Android runs fine). I don't have a mac, so I'm using Codemagic to compile a release build and deploy to TestFlight, then installing on an iPhone from there. Apple only shows their crash logs in Xcode as far as I can tell (nothing in App Store Connect online?), and since I don't have a mac, I can't see those. Any thoughts as to what I might be running into, or what information I can gather to debug the problem?
Thanks!
Edit: I've been digging around some more and it looks like the crash is related to the Firebase dependencies. If I create the Flutter demo project (flutter create ), it runs fine on iOS. However if I then add Firebase packages to pubspec.yaml, and manually add GoogleServices-info.plist, the app crashes on startup. (I'm not adding any code that uses Firebase yet.) GoogleServices-info.plist is supposed to be added with Xcode, but since I don't have Xcode or a mac, that makes it tough. The second answer to this question gives a suggestion: Where to save GoogleService-Info.plist in Flutter without Xcode?
I tried making those changes but got the same result. Anybody have any recommendations for adding Firebase without a mac?

Ok, so here's what happened. Originally the app crashed on iOS because there were issues with the GoogleServices-info.plist file (probably). There were no error messages, so I didn't know where to look. I finally just went back to the simple demo app and started layering things back in to isolate the issue. The demo app would build and run on iOS with no problems, but when I added the Firebase dependencies (as a group), it failed. I had added the GoogleServices-info.plist file manually (outside of Xcode) and adjusted the references in ios/Runner.xcodeproj/project.pbxproj using a text editor, but that didn't do the trick.
At this point I finally broke down and got a MacBook. Debugging on the Mac, I could now see that the app crashed in debug mode on the emulator as well as when in release mode on a device, but still no helpful error messages. I added the GoogleServices-info.plist file using Xcode, so at least that piece was correct, but the app still crashed immediately. Going through the documentation, I realized that when I made the sample app, I had forgotten to add the app ID in the info.plist file for AdMob. At this point it was just AdMob causing the crash, not the other Firebase dependencies. I added that back in and things ran fine. I wish I had looked at that a month ago. Ugh.
Thanks #Mikhail Tokharev and #season for taking a stab at such a vague question. I wish I had more detail to share initially, but I didn't know enough yet to know what could be going wrong.
TL;DR
Just get a Mac. Trying to debug through Codemagic won't work.
For Firebase, be sure you actually add your GoogleServices-info.plist file through Xcode. Trying to add it manually and hack the project.pbxproj file probably won't work (this a practical recommendation, I didn't prove this conclusively).
https://firebase.google.com/docs/flutter/setup?platform=ios#add-config-file
For AdMob, be sure to add your application ID to the info.plist. https://pub.dev/packages/firebase_admob

I've been facing this error since the last few days and I happen to solve it today. So, I would like to share it with anyone facing startup error after connecting their iOS app to firebase.
I had followed all the steps while setting up a new iOS app with firebase and this was what exactly caused the error, in my case. If you have placed import 'Firebase' and Firebase.configure() in your AppDelegate.swift, then remove it and run your app again. I removed those two lines and it worked fine. Test it with Cloud Firestore (just make a button write something to your cloud firestore) and make sure you add await Firebase.initializeApp(); as well when the button is pressed.
I did all of those steps and it worked fine with me.
P.S. I did it with android studio in a Mac.

For any newbies out there like me, make sure registering firebase is before GeneratedPluginRegistrant in your ios/Runner/AppDelegate.swift file.
// This works without crashes, FirebaseApp.configure() after GeneratedPluginRegistrant crashes
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)

i had the same issue and i have fixed it as i was new to ios deployment i forgot to add capabilities which indeed crashed my app in testflight ...so please be sure you have added required capabilities in signing and capability tab in xcode

use terminal to run the app.
run this command
flutter run --release

For iOS: In our case this happened because of Facebook plugin update.
Previous version: flutter_facebook_auth: ^3.5.1
New Version: flutter_facebook_auth: ^4.3.3
We were missing FacebookClientToken in Info.plist file. So after adding that it worked.
<key>FacebookClientToken</key>
<string>$(FACEBOOK_CLIENT_TOKEN)</string>

most probably you've faced with next Flutter issue https://github.com/flutter/flutter/issues/54707

I had the same problem and solved it as below :
In the folder of flutter sdk,
I did git pull then run the app again and it was solved .

If you using Google Firebase library in flutter app
Make sure use FirebaseApp.configure() before GeneratedPluginRegistrant.register(with: self) in AppDelegate.swift file.
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)

Related

Can't get debug token for Firebase App Check for my Flutter iOS App

So I recently started setting up app check for my existing Flutter project (for both android and iOS platforms). I've had no problem with android's "Play Integrity", got the necessary debug token, and can successfully send and retrieve data to/from firestore (app check for firestore is currently enforced for my project).
The problem is, I can not get such a debug key for my iOS app. I will list the sources I've used and what I've tried so far.
I have firebase_app_check: ^0.1.1+8 installed via pubspec.yaml
I also added pod 'FirebaseAppCheck' to my Podfile
I have the necessary initialization code in my main.dart: await FirebaseAppCheck.instance.activate(...);
For "DeviceCheck", I am using THE SAME private key that I am using
for "Sign in With Apple" (which I have implemented successfully). I
have also enabled the checkbox for DeviceCheck in the settings of
that private key (in Apple Developer).
For my App ID (Apple Developer > Identifiers > App IDs), I have also
enabled the checkbox for "App Attest".
I have put "-FIRDebugEnabled" as an argument passed on launch in
XCode > Product > Scheme > Edit Scheme.
I always uninstall my app from my iOS simulator (iOS 16.2) or real device (iOS 16.1.2),
before trying again, because I have read across multiple forums that
the debug token only gets printed to the output the first time you
run your app.
I have also added these 4 lines of code in my AppDelegate.swift from here:
#if DEBUG
let providerFactory = AppCheckDebugProviderFactory()
AppCheck.setAppCheckProviderFactory(providerFactory)
#endif
Official firebase docs "iOS+ (App Attest)":
I have NOT copied ANY code from this page of the official docs, as I assume it's for native iOS apps only, and not for flutter, and I don't know where exactly I would have to put that code. I have only added the pod dependency and run pod install.
I don't have a .entitlements file.
So after all those steps, I'm apparently supposed to expect to find a debug token in my run output, as in:
Yet the only relevant output I can find is the following:
Runner[72719:33546579] 10.3.0 - [FirebaseFirestore][I-FST000001] AppCheck failed: 'The operation couldn’t be completed. (com.apple.devicecheck.error error 1.)'
If it matters:
I have NOT YET uploaded my iOS app to apple developer, app store connect or whatever (I'm not yet familiar with the process of publishing to the app store).
Neither have I uploaded my android app to Google Play console or created an app there (for this project).
Don't tell me anything about firestore rules. I already had that set up long ago, and everything worked just fine before I started integrating App Check.
Don't recommend any 3rd party plugins to me, I will only use official ones.
The firebase documentation says:
Tip: Confirm in your Xcode project's build settings that it passes the DEBUG flag to the Swift compiler
Try removing the '#if DEBUG' and '#endif' and run the app.
If it works, it mean you have missed that step
I was not able to find that build setting, so i just removed those lines from the AppDelegate, but i need to keep in mind to remove the other 2 lines while building the release mode
See this answer on the flutterfire Github issues page. Basically, call setAppCheckProviderFactory before GeneratedPluginRegistrant.register(with: self) in the app delegate file. I was investigating the same issue and it fixed it for me (the debug token was instantly printed out in Xcode's debug output). Hope it helps you as well!

Firebase Crashlytics won't activate

I have run my app on a device and in simulator with no success of updating the Firebase Crashlytics system.
I am not getting any errors, and I know that it's installed because it says the version number (4.5.0) in console.
Also Firebase Analytics is working.
I have followed the install guide to a T and also tried to force crash it by creating a SwiftUI button and using
fatalError()
Which seems to not fully crash the app, but more freeze the app.
I am wondering how I can trace this issue with SwiftUI and Firebase.
In addition of doing what the accepted answer recommends and I believe this is something new from Xcode 12.+. You need to uncheck the two checkboxes below the script window (at least once - you may tick them back up once registered with firebase). This (as stated) forces the script to run and therefore to communicate with firebase... the checkboxes unticked
As outlined here, if you're going to use the Xcode Simulator, you must detach the Xcode debugger at runtime by launching the app directly from the Simulator and not Xcode. Xcode automatically attaches its debugger if you launch from Xcode to a Simulator, blocking Crashlytics from being able to see exceptions/crashes.

Unity Firebase Analytics 6.15.2 crash

I have implemented Firebase Analytics 6.15.2 into my project, then I have builded the Xcode project and have run it on the device, everything went perfect, but when I try to open the app afterwards, without it running from Xcode - it crashes after 20 seconds of launch screen.
So I have no logs and anything, I somehow figured out it's an issue with Firebase and downgraded the pods in the Xcode project to Firebase 5.3.0, it worked.
I have other projects where the same issue is occurring.
So my question is, how do I fix it? Because there is no way it's happening to everyone, I might be doing something wrog here and I just don't see it.
I use Unity 2020.1.2f1
Firebase Core + Analytics 6.15.2 via Package Manager (also tried installing it manually, still the same)
Other plugins I am using are Facebook and ironSource
ps. The funny thing that it crashes on all devices, but it passes Apple review because they test it in some kind of debug mode, but when it's in release mode - it crashes.
Have you tried to reinstall Firebase Analytics 6.15.2? Also, you can try to restart your device and try to make it work again.
You need to add the debug symbols to your app debug archive file:
Select your Target -> Build Settings -> Build Options -> Debug
Information Format
Then Select DWARF with dSYM file for the debug mode.

Xcode 9 App installation failed, Could not write to the device

I've just updated to Xcode 9 and am getting App installation failed Could not write to the device error popup every other time. I see there are older questions on the subject, but this one is particular to iOS 11 and Xcode 9. I've never had the issue before.
How do I make sure Xcode 9 can install app to device every time?
In my case this issue was caused by using App Store distribution certificate while iPad was connected wirelessly.
Switching to development certificate fixed the issue.
Xcode 9 seems to have many different manifestations of this problem. Some of the other answers address specific problems, but this definitely occurs when there is nothing wrong with your project. These steps always resolve for me (in order from least painful to most painful):
Try running it again. Sometimes it works on the 3rd or 4th time.
Unplug the device and plug it in again.
Restart Xcode.
Clean build folder (not a regular clean - this is cmd+option+shift+K or hold option in the product menu) and then rebuild.
If all else fails, once a full restart fixed it for me. But probable something else was the root cause.
Hopefully Xcode fixes these problems soon...but I'm not hopeful.
In my case, I want to testing watchOS app and I set the debug provisioning profile to release one. I set to automatic and the issue is gone.
The solution that works for Could not write to the device is clicking the run button again after dismissing this error message.
In some cases I get the error App installation failed: unknown error. In this case I need to do a clean before building.
Deleting the app from device also helps.
I had similar issue and got is solved using below steps :
Delete app from device
Disconnect device from system
Restart iPhone device and Xcode
Delete derived data content
Clean your project (Shortcut key : cmd + shift + k)
Rebuild your project
I am facing same issues on my iPad. It was working fine before. But after some time my development version stop working on iPad. I have tried and search on internet but not able to find solutions. I have tried all above cases but no Luck.
At last, I have found solutions. Some developer has changed DATE/TIME settings for my Ipad. Please check date/time because my Provisional profile for apps has expired for the manual date set on iPad.
Hope the following steps will be useful for others,
Check your provisioning profile is valid.
choose the debug profile for signing in target.
Open you scheme under product in menu toolbar or using Cmd + < shortcut.
Choose debug mode for Run in your product scheme.
Tadaa! now you can run the app in your device flawlessly.
Happy coding! :)
I tried all the method , they didn`t work for me .
And I fixed the problem by removing the soft link file made by ln -s
In my case, this issue appears when I added a folder as reference in the project which contains a symlink. Removing the symlink fixed the issue.
Mine occurred when I had not signed in using my itunes developer portal credentials to sign into XCode. When I did it and cleared all derived data, it worked out.
Everyone is solving this problem in a different way. Mine was changing executable name, building the app (throwing the "You don't have permission etc." problem) and changing the executable name back to the original value.
I don't know why but it worked.
I actually had to reboot the system on the Mac, this gets me rid of the problem for a good while, but it eventually comes back. None of the other solutions mentioned here worked for me.
In my case the problem appears while I use manual signing and try to debug the app in Release mode. Although the fastlane builds and uploads fine in this mode fine, direct XCode debugging fails with the error "Could not write to the device". Temp switching to automatic signing mode fixed this issue.
What worked for me:
delete the app from iPhone
clean the code in Xcode
quit Xcode
re-open Xcode, connect my iPhone, and run it again
I got this issue App installation failed - Could not write to the device and I solved it by doing the below steps
Uninstall the app from device.
Clean the project.
Run the project.
It worked for me.
Xcode 9. iOS 11 SDK. Watch SDK 4.x.x - OPEN THE WATCH APP on the iPhone after failed. My Watch tab->(scroll down to the bottom)-> Install your app. Hope this helps. Just need permissions from the "Watch" app.
I had the same question that could be solved by deleting other debug App from my iPhone, then it worked.
When I choose the Automatically manage signing, my problem fixed.Hope my answer can help you.
Sometimes the problem arises when you removing some pod file reference. The only way to solve this in also your pod-file
eg:
use_frameworks!
pod 'KYDrawerController'
pod 'GoogleMaps'
pod 'GooglePlaces'
pod 'Alamofire'
pod 'Firebase'
pod 'Firebase/Messaging'
remove the unwanted file in this place. And also reinstall the pod-file again and open your project it surely works for you.

React native app stuck on splash screen on device but works in simulator

My React Native app works in the XCode simulator with no issues, but when I run in a physical device, my iPhone, there's a problem. The app launches and gets stuck on the React Native splash screen, the after 10-15 seconds the app crashes/closes. What's the cause of this and how can I prevent it?
It seems that I have found the problem. According to https://facebook.github.io/react-native/docs/running-on-device, when you build and run the app on your device, your app will load js files from the packager on your computer, so you can live reload your app. That means your device has to be connected to your computer or has to be in the same wifi network as your computer. If your device can't access the packager, it will stuck on the splash screen and quit.
To run on your device reliably, edit build schema and build release version.
For me when I build, it was working fine in simulator however, in actual device only splash screen was coming and nothing else.
This was because my build configuration was debug mode which is default I guess, I had to change release/build configuration from debug to release and everything work as expected.
Upvote it if this helps :)
Yep I had WiFi on my phone disabled. Enabled WiFi and boom back in business
It should be perfectly possible to run the app in debug, on the device, without the packager attached! You have to use react-native bundle to create an offline bundle, and add it to your Xcode project. Then your app should fall back to that bundle when the packager is not available.
This used to be in the Deploying to Device FB docs, not sure why it's not there anymore.
Sample call (our index.ios.js is placed in ./dist by TypeScript):
react-native bundle --dev true --assets-dest ./ios --entry-file ./dist/index.ios.js --platform ios --bundle-output ios/main.jsbundle
Also, it's apparently necessary to tell your app to run directly from the bundle rather than try to access the development server, which seems to cause the timeout (we had the same issue as OP).
Comment out this line:
jsCodeLocation = // whatever
And add this line:
jsCodeLocation = [[NSBundle mainBundle] URLForResource:#"main" withExtension:#"jsbundle"];
I tried disconnecting my iPhone from the Internet, the problem disappeared in later launches.
So something is trying to do network stuff and causing the delay.
It's a quick fix, but will do until we find the specific culprit.
I was having the same issue.
What I did was in Xcode go to Products -> Scheme -> Edit Scheme -> Select the Run tab -> Change the build configuration to Release ( default it was debug mode ) and run the app in the device.
It was much faster and run it as like a native app.
Just experienced this and after an hour of debugging realized I had recently enabled my systems firewall and set it to "Block all incoming connections".
Weird thing is that android was functioning fine on a physical device, however iOS on a physical device was not able to connect to the RN server. Relaxed the firewall rules and now iOS can connect to the RN server.
You probably need to sign the app.
Under the Project navigator, click on your app. Then select your target from the project and targets list. Within the "General" tab, find the 'Signing' section. You'll need to specify a team here.
See this link for more info: https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/LaunchingYourApponDevices/LaunchingYourApponDevices.html#//apple_ref/doc/uid/TP40012582-CH27-SW4
I faced this issue where I was react-native-splash-screen. After removing it, it is working
This issue could raise due to the following possibilities:
Your run schema set to release instead of debug, so always expect to load main.jsbundle, instead of running from the debug server. Change it by Product->Schema-> Edit Schema->Run-> Build Configuration: Debug
Check on Xcode log that any message like NSURLConnection finished with error - code -1004 or NSURLConnection finished with error - code -1022.
Go to Project->Target->Build Phases-> + -> New Run Script Phase
(-1004) You have configured your XCode project from sketch and forgot to enter the react-native xcode script on Build Phases:
For the below version of React Native 50:
export NODE_BINARY=node
../node_modules/react-native/packager/react-native-xcode.sh
For the higher version of React Native 50:
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh
(-1022) Your app ATS issue, check on Info.plist, and you can turn off ATS using below code:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
For me I am using firebase framework on my project. I forgot the add GoogleService-Info.plist file to my xcode project. After add it problem gone away.
Happened to me on my iOS device. I was connected to 4G, not WiFi. I connected to WiFi and it started working immediately.
I am facing same issue when I upload release on TestFlight, so what I did is
react-native link react-native-splash-screen
because some how my splash screen plugin is unlinked. This works for me.
Best check with all outgoing calls. This might happened if you do call an http request to fetch user for example or during fetching user from storage.
If this call returned error, you'll be stuck in Splash screen.
Additionally, imagine that you have navigation that uses these calls it will be worse.
All the solutions above do not work for me.
It's really weird in my situation. The router in my company sends both 2.4G and 5.0G wifi. Only connecting to the 2.4G wifi works when debug on real device.
For me,
I have followed below steps:
removed node_modules and reinstalled node_modules
restarted metro server
re-installed the app
In my case app stack on splash screen on both (debug & release) schemes of build.
Problem was in Capabilities for push Notification and Firebase. Just add this one. How you can do this
May be it'll help you:)
Delete node_modules folder
Then run
yarn or npm install

Resources