coiai Logo

This article is an English translation of the original Japanese post. Read the Japanese original →

Can't Build Flutter for iOS: No such module 'Flutter' / Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

February 6, 2025

Categories: Flutter · Tags: Flutter, Swift, Xcode, プログラミング

Can't Build Flutter for iOS: No such module 'Flutter' / Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

When I tried to build a Flutter app for iOS, I ran into the following error in AppDelegate.swift and couldn't run the app.

No such module ‘Flutter’

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

This post explains how to fix it.

Solution

Clear the Flutter project's cache. This is done to resolve dependency-related issues.

flutter clean

Download and update packages and set up dependencies according to pubspec.yaml.

flutter pud get

Move into the ios directory.

cd ios

Create the Pods/ folder based on ios/Podfile. This also updates ios/Podfile.lock and pins the dependency versions.

pod install

Open Xcode with the command below. Note that it's not Runner.xcodeproj ⚠️

open Runner.xcworkspace

If this doesn't fix it

Try upgrading Flutter. (That's what fixed it for me... sigh.) After upgrading, go through the clean, pub get, and pod install steps again.

flutter upgrade

Can't Build Flutter for iOS: No such module 'Flutter' / Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value | coiai Inc.