cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

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

Closed Vages closed 4 days ago

Vages commented 2 weeks ago

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

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)
sandydoo commented 2 weeks ago

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

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

In your devenv config:

{ pkgs, ... }:
{
  stdenv = pkgs.stdenvNoCC;
}
sandydoo commented 6 days ago

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

Vages commented 4 days ago

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