Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flutter run with target IOS fails with message Lexical or Preprocessor Issue (Xcode): 'UIKit/UIKit.h' file not found #1174

Closed
Vages opened this issue Apr 29, 2024 · 4 comments
Labels
macos Affects systems running macOS question Further information is requested

Comments

@Vages
Copy link

Vages commented Apr 29, 2024

Describe the bug

flutter run crashes when running through a devenv shell if it tries to target IOS. The devenv file can be practically empty.

Inspired by a Nixos forum post, I suspect that using mkShellNoCC instead of mkShell somewhere within the devenv source or in a Nix flake would solve the problem: https://discourse.nixos.org/t/flutter-for-ios-setup-not-working/43130 I would be glad to check whether this solution worked, but I would need some assistance.

To reproduce

  • Install flutter using some non-devenv method (in my case, Homebrew).
  • Install Xcode
  • Install Simulator (from Apple)

Running Flutter without devenv works …

$ flutter create flutter_demo                                                                                                                                                                                                                                                                                                                                        
Developer identity "Apple Development: My Name (AOEUIDHTNS)" selected for iOS code signing
Creating project flutter_demo...
Resolving dependencies in flutter_demo... 
Got dependencies in flutter_demo.
Wrote 129 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider: https://www.youtube.com/c/flutterdev

In order to run your application, type:

  $ cd flutter_demo
  $ flutter run

Your application code is in flutter_demo/lib/main.dart.
$ cd flutter_demo
$ flutter run                                                                                                                                                                                                                                                                                                                                ~/flutter_demo
Launching lib/main.dart on iPhone 15 Pro in debug mode...
Running Xcode build...                                                  
 └─Compiling, linking and signing...                         3,5s
Xcode build done.                                           14,9s
[ERROR:flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.mm(42)] Using the Impeller rendering backend.
Syncing files to device iPhone 15 Pro...                            20ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on iPhone 15 Pro is available at: http://127.0.0.1:49858/DoPGZofTYIo=/
The Flutter DevTools debugger and profiler on iPhone 15 Pro is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:49858/DoPGZofTYIo=/
Lost connection to device.

But throw in a devenv init before flutter run, and Xcode will fail to find one or more header files:

$ flutter create flutter_demo
Developer identity "Apple Development: My Name (AOEUIDHTNS)" selected for
iOS code signing
Creating project flutter_demo...
Resolving dependencies in flutter_demo... 
Got dependencies in flutter_demo.
Wrote 129 files.

All done!
You can find general documentation for Flutter at: https://docs.flutter.dev/
Detailed API documentation is available at: https://api.flutter.dev/
If you prefer video documentation, consider:
https://www.youtube.com/c/flutterdev

In order to run your application, type:

  $ cd flutter_demo
  $ flutter run

Your application code is in flutter_demo/lib/main.dart.
$ cd flutter_demo
$ devenv init

• Creating devenv.nix
• Creating devenv.yaml
• Creating .envrc
• Creating .gitignore
• Building shell ...
• Using Cachix: devenv
✖ You're not a trusted user of the Nix store. You have the following options:

a) Add yourself to the trusted-users list in /etc/nix/nix.conf for devenv to manage caches for you.

trusted-users = root my-name

Restart nix-daemon with:

  $ sudo launchctl kickstart -k system/org.nixos.nix-daemon

b) Add binary caches to /etc/nix/nix.conf yourself:

extra-substituters = https://devenv.cachix.org
extra-trusted-public-keys = devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=

And disable automatic cache configuration in `devenv.nix`:

{
    cachix.enable = false;
}

• Failed to get cachix caches due to evaluation error
$ devenv shell
✔ Building shell in 1.7s.
• Entering shell
Restored session: Mon Apr 29 13:54:22 CEST 2024
hello from devenv
git version 2.44.0
(nix:devenv-shell-env) (devenv) bash-5.2$ flutter run
Launching lib/main.dart on iPhone 15 Pro in debug mode...
Running Xcode build...                                                  
 └─Compiling, linking and signing...                        438ms
Xcode build done.                                           11,3s
Failed to build iOS app
Lexical or Preprocessor Issue (Xcode): 'UIKit/UIKit.h' file not found
/Users/my-name/flutter_demo/flutter_demo/build/ios/Debug-iphonesimulator/Flutter.framework/Headers/Flutter.h:7:8


Parse Issue (Xcode): Could not build module 'Flutter'
/Users/my-name/flutter_demo/flutter_demo/ios/Runner/GeneratedPluginRegistrant.h:9:8


Could not build the application for the simulator.
Error launching application on iPhone 15 Pro.
(nix:devenv-shell-env) (devenv) bash-5.2$ 

Version

$ devenv version                                                                                                                                                                                                                                                                                                                             
devenv 1.0.4 (aarch64-darwin)
@Vages Vages added the bug Something isn't working label Apr 29, 2024
@sandydoo
Copy link
Member

sandydoo commented May 1, 2024

@Vages, you can change the stdenv used by mkShell.

https://devenv.sh/reference/options/#stdenv

In your devenv config:

{ pkgs, ... }:
{
  stdenv = pkgs.stdenvNoCC;
}

@sandydoo
Copy link
Member

@Vages, did you have a chance to try this out?

@sandydoo sandydoo added question Further information is requested macos Affects systems running macOS and removed bug Something isn't working labels May 12, 2024
@Vages
Copy link
Author

Vages commented May 14, 2024

Just tested, and it worked! 👏 I’ll be closing the issue. Thank you for the help 😄

@Jonas-Sander
Copy link

Jonas-Sander commented Aug 10, 2024

Well this solved the problem from the title for me, but now when trying to run the iOS Simulator I get the following error:

Error (Xcode): Target debug_unpack_ios failed: Error: Flutter failed to create a directory at "/nix/store/i32cnrvy0iv69hq5ljcff68v9zc9956q-flutter-3.22.2-unwrapped/bin/cache/artifacts".

I'm not sure how i can change the directory where artifacts will be added to by Xcode.

Probably related: flutter/flutter#105257

Edit: flutter clean seems to have fixed it, idk if it really makes sense though 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macos Affects systems running macOS question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants