Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Building Flutter projects on MacOS fails if FlutterMacOS.framwork is read-only (ie. in a Nix environment) #147142

Closed
@asyncmeow

Description

@asyncmeow

Steps to reproduce

  1. Make sure nix is installed on your MacOS machine
  2. Run nix-shell -p flutter to create a shell with Flutter in your environment
  3. Attempt to build a project for MacOS with flutter build macos and notice how it fails
  4. Leave the nix environment you created in step 2 (exit)
  5. Attempt to build again for MacOS with flutter build macos and notice how it succeeds

Expected results

The build should succeed under the nix environment.

Actual results

The build fails on the nix environment due to FlutterMacOS.framework being read-only in the Nix store. The Nix store is intentionally read-only, so changing FlutterMacOS.framework to rw within the Nix store would ruin the point of using Nix here.

Code sample

Code sample As this issue occurs on the brand-new project created by `dart create bug`, I attached that file unmodified:
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // TRY THIS: Try changing the color here to a specific color (to
        // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
        // change color while the other colors stay the same.
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          //
          // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
          // action in the IDE, or press "p" in the console), to see the
          // wireframe for each widget.
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Screenshots or Video

No response

Logs

Logs
underworld:bug pearl$ flutter build macos

2024-04-21 16:23:38.484 xcodebuild[49965:156303515] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00006000-001230823E7A401E }
{ platform:macOS, arch:x86_64, id:00006000-001230823E7A401E }
Building App.framework for x86_64...
Building App.framework for arm64...
Target release_unpack_macos failed: Exception: Failed to extract arm64 x86_64 for /Users/pearl/code/test/bug/build/macos/Build/Products/Release/FlutterMacOS.framework/Versions/A/FlutterMacOS.
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't create temporary output file: /Users/pearl/code/test/bug/build/macos/Build/Products/Release/FlutterMacOS.framework/Versions/A/FlutterMacOS.lipo (Permission denied)

Running lipo -info:
Architectures in the fat file: /Users/pearl/code/test/bug/build/macos/Build/Products/Release/FlutterMacOS.framework/Versions/A/FlutterMacOS are: x86_64 arm64 


Command PhaseScriptExecution failed with a nonzero exit code
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **

Building macOS application...                                           
Build process failed
underworld:bug pearl$ 

Flutter Doctor output

Doctor output
underworld:bug pearl$ flutter doctor -v
[✓] Flutter (Channel stable, 3.19.0, on macOS 13.4.1 22F770820d darwin-arm64, locale en-US)
    • Flutter version 3.19.0 on channel stable at /nix/store/yj4imxhd3lcv6gjvv584ggchqy9k4krx-flutter-wrapped-3.19.0-sdk-links
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision nixpkgs000 (), 1970-01-01 00:00:00
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /nix/store/z0mkx48izmj3iv10p3ig4ij2qd3iq1j7-androidsdk/libexec/android-sdk
    • Platform android-34, build-tools 30.0.3
    • ANDROID_HOME = /nix/store/z0mkx48izmj3iv10p3ig4ij2qd3iq1j7-androidsdk/libexec/android-sdk
    • Java binary at: /Users/pearl/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.15.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2023.2)
    • Android Studio at /Users/pearl/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.4)
    • IntelliJ at /Users/pearl/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 78.4.2
    • Dart plugin version 233.15123

[✓] IntelliJ IDEA Community Edition (version 2024.1)
    • IntelliJ at /Users/pearl/94w87dhc6smqxdlq61kvy2ksd99j1fhw-idea-community-2024.1/Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Ultimate Edition (version 2024.1)
    • IntelliJ at /Users/pearl/z9dfy1vs6g4gybvznyqlxn6453mgsy4z-idea-ultimate-2024.1/Applications/IntelliJ IDEA.app
    • Flutter plugin version 79.0.3
    • Dart plugin version 241.15845

[✓] VS Code (version 1.88.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
    • macOS (desktop) • macos • darwin-arm64 • macOS 13.4.1 22F770820d darwin-arm64

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: buildBuilding flutter applications with the toola: desktopRunning on desktopplatform-macBuilding on or for macOS specificallyr: fixedIssue is closed as already fixed in a newer versionteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions